maine

CREAREA TABELELOR: CREATE TABLE medicamente ( cod_medicament number(4) NOT NULL, denumire_medicament varchar2(30) NOT NULL, afectiuni varchar2(40), administrare varchar2(40), compozitia varchar2(30), pret_unitar number(3), CONSTRAINT cod_medicament_pk PRIMARY KEY(cod_medicament), /* creare cheie primara */ CONSTRAINT check_administrare CHECK (administrare IN ('intern', 'extern')), /* creare constrangere a.i. administrare sa poata contine doar intern sau extern */ CONSTRAINT check_pret_unitar CHECK (pret_unitar BETWEEN 10 and 1000) /* creare constrangere a.i. pret unitar sa poata contine valori doar intre 10 si 1000 */ ); CREATE TABLE pacienti ( cod_pacient number(3) NOT NULL, nume_pacient varchar2(40) NOT NULL, serie_nr_ci varchar2(10), cnp number(13) NOT NULL, /* number(p,s) - p = number of digits befor decimal - p max =38 s max =127 si s min=-87; - s = number of digits after decimal */ localitate varchar2(40), adresa_strada_numar char(40) CONSTRAINT cod_pacient_pk PRIMARY KEY(cod_pacient) ); CREATE TABLE retete ( nr_reteta number(3) NOT NULL, cod_medicament number(4) NOT NULL, data_reteta date DEFAULT (SYSDATE), pret_reteta number(4), cantitate_reteta number(4) cod_pacient number(3), CONSTRAINT nr_reteta_pk PRIMARY KEY(nr_reteta), CONSTRAINT cod_medicament_fk FOREIGN KEY(cod_medicament) REFERENCES medicamente(cod_medicament), /* creare constrangere foreign key */ CONSTRAINT cod_pacient_fk FOREIGN KEY (cod_pacient) REFERENCES pacienti (cod_pacient), CONSTRAINT check_cantitate_reteta CHECK ( cantitate_reteta > 0 ) /* c. constrangere cantitate >0 */ ); CREAREA SECVENTELOR: CREATE SEQUENCE secventa_cod_medicament MINVALUE 1 START WITH 1 INCREMENT BY 1 NOCACHE; CREATE SEQUENCE secventa_cod_pacient MINVALUE 1 START WITH 1 INCREMENT BY 1 NOCACHE; CREATE SEQUENCE secventa_nr_reteta MINVALUE 1 START WITH 1 INCREMENT BY 1 NOCACHE; inserarea de valori unice INSERT INTO medicamente(cod_medicament, denumire_medicament, afectiuni, administrate, compozitia, pret unitar) values (secventa_cod_medicament.CURRVALUE, 'paracetamol', 'raceala', 'externa', 'aspirinia', 15) VIZUALIZAREA VALORII CURENTE A SECVENTELOR SELECT secventa_cod_medicament.CURRVAL FROM DUAL; SELECT secventa_cod_pacient.CURRVAL FROM DUAL; SELECT secventa_nr_reteta.CURRVAL FROM DUAL; MODIFICAREA VALORII MAXIME A UNEI SECVENTE CREATE ALTER SEQUENCE secventa_cod_medicament MAXVALUE 15000; VIZUALIZAREA VALORII URMATOARE A SECVENTEI SELECT secventa_cod_medicament.NEXTVAL FROM DUAL;
maine

Be the first to comment

You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.