The document defines the schema for a hospital database by creating tables for areas, tests, floors, beds, patients, doctors, nurses, visits, and test results. Tables are created with primary and foreign keys to link the tables together and store patient, doctor, and hospital data. The schema is populated with sample data by executing insert statements.
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0 ratings0% found this document useful (0 votes)
47 views4 pages
Hospital SQL
The document defines the schema for a hospital database by creating tables for areas, tests, floors, beds, patients, doctors, nurses, visits, and test results. Tables are created with primary and foreign keys to link the tables together and store patient, doctor, and hospital data. The schema is populated with sample data by executing insert statements.
( numPl TINYINT, numLlit TINYINT, PRIMARY KEY (numPl, numLlit), FOREIGN KEY (numPL) REFERENCES hospital.planta (numPl) ON DELETE NO ACTION ON UPDATE CASCADE ) engine=InnoDB;
CREATE TABLE IF NOT EXISTS hospital.pacient
( dni CHAR(9) PRIMARY KEY, nom VARCHAR(45) NOT NULL, cognoms VARCHAR(45) NOT NULL, dataAlta DATE, numP TINYINT, numL TINYINT, FOREIGN KEY (numP,numL) REFERENCES hospital.llit (numPl,numLlit) ON DELETE SET NULL ON UPDATE CASCADE ) engine=InnoDB;
CREATE TABLE IF NOT EXISTS hospital.metge
( codMetge TINYINT PRIMARY KEY, nom VARCHAR(45) NOT NULL, cognoms VARCHAR(45) NOT NULL, sou DECIMAL, numArea TINYINT, FOREIGN KEY (numArea) REFERENCES hospital.area (numArea) ON DELETE SET NULL ON UPDATE CASCADE ) engine=InnoDB;
CREATE TABLE IF NOT EXISTS hospital.infermer
( codInf TINYINT PRIMARY KEY, nom VARCHAR(45) NOT NULL, cognoms VARCHAR(45) NOT NULL, numArea TINYINT, FOREIGN KEY (numArea) REFERENCES hospital.area (numArea) ON DELETE SET NULL ON UPDATE CASCADE ) engine=InnoDB;
CREATE TABLE IF NOT EXISTS hospital.visita
( dniPac CHAR(9), codMetge TINYINT, data DATE, diagnostic VARCHAR(100), PRIMARY KEY (dniPac, codMetge, data), FOREIGN KEY (dniPac) REFERENCES hospital.pacient (dni) ON DELETE NO ACTION ON UPDATE CASCADE, FOREIGN KEY (codMetge) REFERENCES hospital.metge (codMetge) ON DELETE NO ACTION ON UPDATE CASCADE ) engine=InnoDB;
CREATE TABLE IF NOT EXISTS hospital.realitzacio
( codProv TINYINT, dniPac CHAR(9), data DATE, resultat VARCHAR(100), PRIMARY KEY (codProv,dniPac, data), FOREIGN KEY (codProv) REFERENCES hospital.prova (codProv) ON DELETE NO ACTION ON UPDATE CASCADE, FOREIGN KEY (dniPac) REFERENCES hospital.pacient (dni) ON DELETE NO ACTION ON UPDATE CASCADE ) engine=InnoDB;
INSERT INTO hospital.area VALUES (1, 'Traumatologia'),
INSERT INTO hospital.realitzacio VALUES (1,'11111111A','2014-03-05','Fractura
radio'), (1,'22222222B','2014-03-06','Fractura cubito'), (1,'33333333C','2014-03-08','Fractura radio'), (1,'44444444D','2014-03-10','Fractura cubito'), (1,'55555555E','2014-03-13','Fractura radio'), (3,'11111111A','2014-03-05','Parametres en els marges correctes'), (3,'22222222B','2014-03-06','Parametres en els marges correctes'), (3,'33333333C','2014-03-09','Hematies baixos'), (3,'44444444D','2014-03-10','Parametres en els marges correctes'), (3,'55555555E','2014-03-14','Hematies baixos');