Trabalho de banco de dados
CREATE TABLE Ficha
(
id_ficha smallint NOT NULL
, data datetime NOT NULL
, LojaID int NOT NULL
, IDV int NOT NULL
, CPF int NOT NULL
, Chassi varchar(20) NOT NULL
, CodPag int NOT NULL
, Seq int NOT NULL
, CONSTRAINT pk_fichaori PRIMARY KEY (id_ficha)
, CONSTRAINT FK_Ficha FOREIGN KEY(LojaID)
REFERENCES Loja(id_loja)
, CONSTRAINT FK_Ficha2 FOREIGN KEY(IDV)
REFERENCES Vendedor(id_vend)
, CONSTRAINT FK_Ficha3 FOREIGN KEY(CPF)
REFERENCES Cliente(CPF)
, CONSTRAINT FK_Ficha4 FOREIGN KEY(Chassi)
REFERENCES Veiculo(Chassi)
, CONSTRAINT FK_Ficha5 FOREIGN KEY(Seq)
REFERENCES CondPag(id_Seq)
)
INSERT INTO Ficha
VALUES (1,'20091009',1,1,' 07234512342','GHF42142F42445434564',1)
INSERT INTO Ficha
VALUES (2,'20101009',2,2,' 07234513454','GHF42142F40908976565',2)
INSERT INTO Ficha
VALUES (3,'20111009',1,1,' 07234555555','GHF42142F44737362738',3)
INSERT INTO Ficha
VALUES (4,'20081009',1,1,' 07234666663','GHF42142F44638292766',4)
INSERT INTO Ficha
VALUES (5,'20071009',1,1,' 07234434323','GHF42142F49483726450',5)
CREATE TABLE Loja
(
id_loja int NOT NULL
, NomeLoja varchar(50) NOT NULL
, CONSTRAINT pk_ficha PRIMARY KEY (id_loja)
)
INSERT INTO Loja
VALUES (1,'Store1')
INSERT INTO Loja
VALUES (2,'Store2')
INSERT INTO Loja
VALUES (3,'Store3')
INSERT INTO Loja
VALUES (4,'Store4')
INSERT INTO Loja
VALUES (5,'Store5')
CREATE TABLE Cliente
(
cpf int NOT NULL
, NomeCliente varchar(50) NOT NULL
, idCid int not null
, IdUF int NOT NULL
, Cep int NOT NULL
, endereco varchar(50) NOT NULL
, CONSTRAINT pk_cliente PRIMARY KEY (cpf)
, CONSTRAINT fk_cliente FOREIGN KEY(IdCid)
REFERENCES Cidade(id_cid)
, CONSTRAINT fk_cliente2 FOREIGN KEY(IdUF)
REFERENCES UF(id_UF)
)
INSERT INTO Cliente
VALUES (07234512342,'Rafael',1,1,30410410,'Rua Ametista 333')
INSERT INTO Cliente
VALUES (07234513454,'Amanda',1,1,30410420,'Rua Rubi 444')
INSERT INTO Cliente
VALUES