Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
12 views

SQL Comprobem

The document contains SQL commands to create tables, insert data, and perform queries on a database. It first creates 8 tables to store information about cost centers, sections, storekeepers, requisitions, materials, and requisition details. It then inserts sample data into the tables. Finally, it shows examples of INSERT, UPDATE, DELETE, and ALTER queries on the tables.

Uploaded by

augustosoaresw
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views

SQL Comprobem

The document contains SQL commands to create tables, insert data, and perform queries on a database. It first creates 8 tables to store information about cost centers, sections, storekeepers, requisitions, materials, and requisition details. It then inserts sample data into the tables. Finally, it shows examples of INSERT, UPDATE, DELETE, and ALTER queries on the tables.

Uploaded by

augustosoaresw
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

1 - CRIAR TABELA

REATE TABLE CENTRO_CUSTO (

CCusto CHAR(3) NOT NULL,

NomeCC CHAR(10) NOT NULL,

CONSTRAINT PK_CENTRO_CUSTO PRIMARY KEY (CCusto)

);

CREATE TABLE SECAO (

Secao NUMERIC(3,0) NOT NULL,

NomeSec CHAR(20) NOT NULL,

CCusto CHAR(3) NOT NULL,

CONSTRAINT PK_SECAO PRIMARY KEY (Secao),

CONSTRAINT FK_SECAO_CCUSTO FOREIGN KEY (CCusto) REFERENCES CENTRO_CUSTO


(CCusto)

);

CREATE TABLE ALMOXARIFADO (

NAlmox NUMERIC(4,0) NOT NULL,


Almoxarife CHAR(30) NOT NULL,

CONSTRAINT PK_ALMOXARIFE PRIMARY KEY (NAlmox)

);

CREATE TABLE REQUISICAO (

NumReq NUMERIC(4,0) NOT NULL,

DtReq DATETIME NOT NULL,

Secao NUMERIC(3,0) NOT NULL,

NAlmox NUMERIC(4,0) NOT NULL,

CONSTRAINT PK_REQUISICAO PRIMARY KEY (NumReq),

CONSTRAINT FK_REQUISICAO_SECAO FOREIGN KEY (Secao) REFERENCES SECAO (Secao),

CONSTRAINT FK_REQUISICAO_ALMOXARIFE FOREIGN KEY (NAlmox) REFERENCES


ALMOXARIFE (NAlmox)

);

CREATE TABLE MATERIAL (

CdMat NUMERIC(4,0) NOT NULL,

DescrMatPrima CHAR(15) NOT NULL,

CONSTRAINT PK_MATERIAL PRIMARY KEY (CdMat)

);

CREATE TABLE REQ_MAT (

NumReq NUMERIC(7,0) NOT NULL,

CdMat NUMERIC(4,0) NOT NULL,

QtdReq NUMERIC(7,0) NOT NULL,

VlrUnit NUMERIC(10,2) NOT NULL,

CONSTRAINT PK_REQ_MAT PRIMARY KEY (NumReq, CdMat),

CONSTRAINT FK_REQ_MAT_REQUISICAO FOREIGN KEY (NumReq) REFERENCES REQUISICAO


(NumReq),

CONSTRAINT FK_REQ_MAT_MATERIAL FOREIGN KEY (Cdmat) REFERENCES MATERIAL


(CdMat)

);
2- INSERIR DADOS DA TABELA

INSERT INTO CENTRO_CUSTO VALUES ('10A', 'Sub-1'),

('10B', 'Mult-2'), ('11A', 'Sub-2'), ('12A', 'Sub-3')

INSERT INTO SECAO (Secao, NomeSec, CCusto)

VALUES (010, 'ADM', '12A'), (020, 'Manutencao', '10A'), (021, 'Producao-1', '10A'), (022,
'Reparos', '10B'), (023, 'Producao-2', '11A'), (024, 'Producao-3', '11A'), (025, 'Escritorio', '10B')

INSERT INTO ALMOXARIFADO (NAlmox, Almoxarife)

VALUES (1001, 'Joao da Silva'), (1002, 'Antonio Prado'), (1003, 'Lourenco Dias'), (1004, 'Jose
Antonio'), (1005, 'Silvino Torres'), (1006, 'Antonio Santos'), (1007, 'Valter Souza'), (1008, 'Sergio
Melo')

INSERT INTO MATERIAL (CdMat, DescrMatPrima)

VALUES (100, 'Enxofre'), (101, 'Areia Monaztica'), (102, 'Argila Moida')

INSERT INTO REQUISICAO (NumReq, DtReq, Secao, NAlmox)

VALUES (101, 20020601, 020, 1001), (102, 20020601, 021, 1002), (103, 20020601, 022,
1003), (104, 20020602, 023, 1004), (105, 20020602, 024, 1005), (106, 20020602, 020, 1002), (107,
20020603, 025, 1008), (108, 20020603, 025, 1001), (109, 20020604, 021, 1006), (110, 20020604,
010, 1006), (111, 20020604, 010, 1007)

INSERT INTO REQ_MAT (NumReq, CdMat, QtdReq, VlrUnit)

VALUES (101, 100, 8, 12.5), (101, 101, 5, 10), (102, 101, 6, 11.5), (102, 102, 25, 3.4), (103,
100, 5, 12.8), (103, 101, 7, 12), (104, 100, 12, 12), (104, 101, 9, 11.3), (105, 102, 20, 3.46), (106, 100,
15, 15), (106, 101, 4, 11), (107, 101, 7, 13), (108, 100, 12, 11.8), (109, 101, 5, 12), (110, 102, 25, 3.2),
(111, 100, 15, 1.3)
3- REALIZAR CONSULTAS

INSERT INTO CENTRO_CUSTO VALUES ('13A', 'Sub-4')

INSERT INTO SECAO VALUES (026, 'Logistica', '13-N')

INSERT INTO ALMOXARIFADO VALUES (1009, 'Eduardo Britto)

INSERT INTO MATERIAL VALUES (103, 'Cimento')

SELECT NumReq, Almoxarife FROM REQUISICAO, ALMOXARIFADO WHERE REQUISICAO.NAlmox =


ALMOXARIFADO. NAlmox ;

UPDATE SECAO SET NomeSec='Secao Teste 001' WHERE NomeSec='Producao-4'

UPDATE SECAO SET NomeSec='11A' WHERE NomeSec='11A'

DELETE FROM CENTRO_CUSTO WHERE CCusto='10C'

ALTER TABLE MATERIAL ADD VlrUnit NUMERIC(10,2) NOT NULL;

ALTER TABLE MATERIAL DROP VlrUnit;

DROP TABLE REQ_MAT;

You might also like