Spre exemplu pacientul cu numele 'DINU MARIA',; si nu prea am idee cum sa fac asta.
Cod: Selectaţi tot
CREATE TABLE medicament(
cod_medicament int primary key,denumire_medicament varchar(50),cantitate_medicament int,pret_unitar float
);
CREATE TABLE pacient(
cnp varchar(14)primary key,nume_pacient varchar(60),adresa varchar(30)
);
CREATE TABLE boala(
cod_boala int primary key,denumire_boala varchar(50)
);
CREATE TABLE diagnostic(
cnp varchar(14),cod_boala int,cod_medicament int,cantitate_medicament int,
primary key(cnp,cod_boala,cod_medicament)
);
ALTER TABLE diagnostic ADD CONSTRAINT FK_MEDICAMENT foreign key(cod_medicament) REFERENCES medicament(cod_medicament);
ALTER TABLE diagnostic ADD CONSTRAINT FK_PACIENT foreign key(cnp) REFERENCES pacient(cnp);
ALTER TABLE diagnostic ADD CONSTRAINT FK_BOALA foreign key(cod_boala) REFERENCES boala(cod_boala);
ALTER TABLE diagnostic ADD CONSTRAINT FK_MEDICAMENT_STERGERE foreign key(cod_medicament) REFERENCES medicament(cod_medicament)ON DELETE CASCADE;
ALTER TABLE diagnostic ADD CONSTRAINT FK_PACIENT_STERGERE foreign key(cnp) REFERENCES pacient(cnp)ON DELETE CASCADE;
ALTER TABLE diagnostic ADD CONSTRAINT FK_BOALA_STERGERE foreign key(cod_boala) REFERENCES boala(cod_boala) ON DELETE CASCADE;
ALTER TABLE diagnostic ADD CONSTRAINT FK_MEDICAMENT_MODIFICARE foreign key(cod_medicament) REFERENCES medicament(cod_medicament)ON UPDATE CASCADE;
ALTER TABLE diagnostic ADD CONSTRAINT FK_PACIENT_MODIFICARE foreign key(cnp) REFERENCES pacient(cnp)ON UPDATE CASCADE;
ALTER TABLE diagnostic ADD CONSTRAINT FK_BOALA_MODIFICARE foreign key(cod_boala) REFERENCES boala(cod_boala) ON UPDATE CASCADE;
INSERT INTO MEDICAMENT(cod_medicament,denumire_medicament,cantitate_medicament,pret_unitar) values (1,'ZYNAT',900,3);
INSERT INTO MEDICAMENT(cod_medicament,denumire_medicament,cantitate_medicament,pret_unitar) values (2,'AUGUMENTIN',700,3);
INSERT INTO MEDICAMENT(cod_medicament,denumire_medicament,cantitate_medicament,pret_unitar) values (3,'PARASINUS',850,1);
INSERT INTO MEDICAMENT(cod_medicament,denumire_medicament,cantitate_medicament,pret_unitar) values (4,'PANADOL',890,1.2);
INSERT INTO MEDICAMENT(cod_medicament,denumire_medicament,cantitate_medicament,pret_unitar) values (5,'ALGOCALMIN',500,1.5);
INSERT INTO PACIENT(cnp,nume_pacient,adresa) values ('1234567891223','POP ION','CRAIOVA');
INSERT INTO PACIENT(cnp,nume_pacient,adresa) values ('1234567891333','DINU MARIA','CRAIOVA');
INSERT INTO PACIENT(cnp,nume_pacient,adresa) values ('1234567812233','CARSTEA ANCA','MIOVENI');
INSERT INTO PACIENT(cnp,nume_pacient,adresa) values ('1234567813121','CALIN IOANA','BALS');
INSERT INTO PACIENT(cnp,nume_pacient,adresa) values ('1234568899123','MATEI DIANA','SLATINA');
INSERT INTO BOALA(cod_boala,denumire_boala) values (1,'REUMATISM');
INSERT INTO BOALA(cod_boala,denumire_boala) values (2,'SINUZITA');
INSERT INTO BOALA(cod_boala,denumire_boala) values (3,'MENINGITA');
INSERT INTO BOALA(cod_boala,denumire_boala) values (4,'GRIPA');
INSERT INTO BOALA(cod_boala,denumire_boala) values (5,'BRONSITA');
INSERT INTO DIAGNOSTIC(cnp,cod_boala,cod_medicament,cantitate_medicament)
values
('1234567891223',1,1,10);
INSERT INTO DIAGNOSTIC(cnp,cod_boala,cod_medicament,cantitate_medicament)
values
('1234567891223',2,5,18);
INSERT INTO DIAGNOSTIC(cnp,cod_boala,cod_medicament,cantitate_medicament)
values
('1234567891333',1,5,15);
INSERT INTO DIAGNOSTIC(cnp,cod_boala,cod_medicament,cantitate_medicament)
values
('1234567891333',1,2,13);
INSERT INTO DIAGNOSTIC(cnp,cod_boala,cod_medicament,cantitate_medicament)
values
('1234567891333',2,3,20);
INSERT INTO DIAGNOSTIC(cnp,cod_boala,cod_medicament,cantitate_medicament)
values
('1234567813121',3,4,30);
INSERT INTO DIAGNOSTIC(cnp,cod_boala,cod_medicament,cantitate_medicament)
values
('1234567812233',3,2,10);
INSERT INTO DIAGNOSTIC(cnp,cod_boala,cod_medicament,cantitate_medicament)
values
('1234568899123',4,1,15);
INSERT INTO DIAGNOSTIC(cnp,cod_boala,cod_medicament,cantitate_medicament)
values
('1234568899123',5,5,3);