Você está na página 1de 6
Criagao da base-resposta ao exercicio 1 Utilizador - logut Password da base ~ passbas Nome da base de dados - testes © utilizador oria no linux , com um editor de texto, o ficheizo CRIABASE.txt abaixo descrito (o nome a BOLDs s6 para facilitar a legibilidade) use testes drop table if exists cliente; create table cliente ( codCli tinyint aute_increnent primary key, nomeCli char (10), moradaCli char (10), telcli char (91, imCred smallint, contacto char (10) ie Drop table if exists encomenda; create table encomenda codEnc tinyint auto_increment primary key, dataEne date, codcli. tinyint ; Drop table if exists objector create table objecto( codObj tinyint auto increment primary key, nomeObj char(10), pudb} smallint iW drop table if exists linSner create table linEnc( codine tinyint not null, cod0bj tinyint not null, qnt tinyint, primary key {codEnc, codobj) ” chama 0 mysql utilizando o ficheiro CRIARASE.txt (um script } como fonte de informacao LINUX > mysql ~u logut -p < criabase.txt © mysql pede a Password ( mantendo-a secreta) e 0 utilizador digita passbas Fase 2 Verificag&o do esquema da base © utilizador eria um script de verificagao a que chama schemaSistSnconendas.txt. Poderia utilizar um processo andlogo 4 criacao da bas Mas pelo contrario vai entrar na sua base , vai criar um ficheiro resultados chamado esqBase.txt (utilizando a directiva \P e vai chamar o script de verificagao utilizanco 2 directiva \. Nome_do fichairo . Para entrar directamente na base usa o modificador -D nome_da_base e ja ndo necessita de 0 escrever no script de verificacao. Respostas ao exercicio 1 Folhal de 6 26-03-2008 Contetide de script de verificagio show tables; dese encomenda; desc cliente; desc objecto; dese lingne; Para entrar na base LINUX > mysql -u logut -D testes -p ¢ responde com o pessword. mysql> \T esqBase.txt Logging to file ‘esqBase.txt! mysql> \. schemaSistEncomendas.txt Tables_in_testes | at cliente 1 i Lingne i objecto i ' 7 Hl | encomenda 1 i 4 rows in set (0.00 sec} | Field | type Null | Key | Default | Extra ' + + + + | codznc | tinyint(4) | 1 PRI | NUDL — | auto_increment | | dataEne | date Yes | i NoDL | I! | codeli | tinyint (4) | YES | (xo | 1 + + + 3 } rows in set (0.00 sec! I Field | Type | Wull | Key | Default | Extra i + at I codcli | tinyint (a) j [PRI | NULL | auto_increment | J nomecli | char(10) | YES || NULL} ' J moradecli | char(10) | YES | | NULL 1 {telcli |char(9) | YES | | NULL I | limcred [| smallint(6) | YES | | NULL | I | contacto | char(20) =| YES | | NOLL | I + + 6 rows in set (0.00 sec) 1 Field 1 Type F Null | Key | Default | extra I | codobj | tinyine(é) | | PRI | NULL — | auto_increment | I nonedbj | char(10) | YES | | NULL | I 1 puobj | smallint(6) | YES | | NOLL | \ + + + 3 rows in set {0.00 sec) Respostas ao exercicio! Folha2 de 6 26-03-2008 + I Field | Type | Null | Key | Default | Extra | I codgne | tinyint(4) | | PRE | 0 Hl I | codobj | tinyint(4) | | PRE | 0 1 t Iqnt "| tinyint(4) | YES | | NOLL | Il 3 rows in set (0.00 sec) Fase 3. Povoamento da base A partir da linha de comandos do mysql mysql> insert into cliente (nomeCli) values ('A.Silva'); Query OK, 1 row affected (0.00 sec} mysql> insert into cliente(nomeCli) values ('A.Cesar'); Query OK, 1 row affected (0.00 sec} mysql> insert into encomenda(dataEnc, codCli) values ('2001-4-12', 1); Query OK, 1 row affected (0.01 sec} mysql> insert into encomenda(dataEne, codCli) values ('2001-4-10', 2); Query OK, 1 row affected (0.00 sec} mysql> insert into encomenda(dataEne, codCli) values (12001-4-25', 1); Query OK, 1 row affected (0.00 sec} mysql> insert into encomenda(dataEne, codCii) values (*2001-5-2",1)7 Query OK, 1 row affected (0.00 sec} mysql> desc objector | Field | Type | Null | Key | Default | Sxtra 1 + + | codobj | tinyint(a) | [PRI | NULL — | auto_increment | | nomeObj | char(10) | YES | I Nou | I | puobj ~ | smallint (6) | YES | I NOLL | I + “+ 3 rows in set (0.00 sec) mysql> insert into objecto values (0, 'cadeira',200); Query OK, 1 row affected (0.00 sec) mysql> insert into objecto values (0, 'banco', 20); Query OK, 1 row affected (0.00 sec) mysql> insert into objecto values (0, 'cama’,521); Query OK, 1 row affected (0.00 sec) mysql> insert into objecto values (0, 'mesa', 300); Query OK, 1 row affected (0.00 sec) Respostas ao exercicio! Folha3 de 6 26-03-2008 mysql> select * from objecto; | puodj noneOb3 1 cadeira | 200 | 1 banco | 20 | I cama | 521 | i mesa [| 300 | 4 rous in set (0.00 sec} mysql> select * from encomenda; + + rows in set (0.00 sec) 1 | dataznc | codCli | + + + I | 2001-04-12 | ad i | 2001-04-10 | 21 i 1 2001-04-25 | 11 1 | 2001-05-02 | lt + + 4 mysql> dese inEne; oe i Field | Type | Null | Key } Default | Extra | | codgne | tinyint(4) | I Prt | 0 Hl Hl | codob} i tinyint (4) | IT PRI 0 1 I Iqnt | tinyint (4) i YES | I NOLL | I 7 3 rows in set (0.00 sec) mysql> insert into lingne values (2/1,7); Query OK, 1 row effected (0.00 sec) mysql> insert into linEnc values (1,2/14); Query OK, 1 row affected (0.00 sec) mysql> insert into linEnc values (2,3,1)7 Query OK, 1 row affected (0.00 sec) mysql> insert into lingne values (3,1,5); Query OK, 1 row affected (0.00 sec) mysql> insert into linEne values (3, 4,10); Query OK, 1 row affected (0.00 sec) mysql> insert into lingne values (4,1,7)7 Query OK, 1 row affected (0.00 sec) mysql> insert into linEne values (4,2,14); Query OK, 1 row affected (0.00 sec) mysql> insert into linEne values (4,3,2)7 Query OK, 1 row affected (0.00 sec) Respostas ao exercicio 1 Folha4 de 6 26-03-2008 mysql> select * from linEne; - + codEne | codObj | gnt i 1 + + i 11 2.174 i 11 21 34 i 21 31 14 i 31 1io84 I 31 41 101 i 41 tio i 4 21 144 I 41 3124 8 rows in set (0.00 sec) Fase 3 - Exploragao da base mysql> select nomeCli, dataEnc, codEnc from encomenda, cliente => where encomenda.codCliscliente.codcli; ae ee + + | momeCli | datazne | codgne | + + | A.Silva | 2001-04-12 | 1s | A.Silva | 2001-04-25 | 31 | A.Silva | 2001-05-02 | a | A.Cesar | 2001-04-10 | 21 + at at + 4 rows in set (0.02 sec} mysql> select sum(pudbj*gnt) from objecto,1inEnc where linEne.cod0bj= => objecto.cod0bj and codine + 7 | sum{pu0bj*ant) 7 Hl 1 row in set (0.00 sec) mysql> select nomeOb},pu0bj*qnt from objecto,1inBne where linfnc.codObj= => objecto.cod0b} and cedEne~4; nomeObj | pudbj*qnt i ' | cadeiza | 1400 | | banco | 280 | lcama | 1042 | + nt + 3 rows in set (0.00 sec) Respostas ao exercicio 1 FolhaS de 6 26-03-2008 mysql> select codine, sum(pudbj*qnt) from objecto, linEne where linfne.coddbj= ~> objecto. code} group by codenc; | codgne | sum{pudbj*aont} 1 1 2 3 4 4 rows in set (0.00 sec) mysql> select encomenda. codinc, datainc, sum(pu0bj*gnt) from objecto, linkne, encomenda where 1inEnc.codobj= => objecto.cod0bj and encomenda.codEnc=linlne.codEne group by codenc; + + + | datazne | sum(pu0bj*ant) | | 2001-04-12 | 1680 | | 2001-04-10 | S21 | § 2001-04-25 | 4000 | | 2001-05-02 | 2722 | rows in set (0.05 sec) aysql> select noneCLi, enconenda.codinc, datazine, sum(pudbj*gnt) from clionte, objecto, linEnc, encomenda where linEnc.cod0bj= => objecto.cod0bj and enconenda.codEnc=1inBne.codEnc and cliente.codClisencomenda.codCli group by codenc? = a + + “+ I nomeCli | codzne | datafne — | sum(pudbj*ant) | + oa cs + | A.Silva | 1 2001-04-12 | 1680 | | A.Cesar | | 2001-04-10 | 21 | I A.Silva | 1 2001-04-25 | 4000 | I a.silva | {2001-05-02 | 2722 | + + + + 4 rows in set (0.01 sec) Respostas ao exercicio 1 Folha6 de 6 26-03-2008

Você também pode gostar