Skip to content

Instantly share code, notes, and snippets.

@Azzeccagarbugli
Last active December 4, 2016 20:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Azzeccagarbugli/69e88d910eb5e11f3dd0f542caa9927b to your computer and use it in GitHub Desktop.
Save Azzeccagarbugli/69e88d910eb5e11f3dd0f542caa9927b to your computer and use it in GitHub Desktop.
Esercizio in MySQL - Ospedale
CREATE DATABASE ospedale; //Creo DB
use ospdale; //Connessione al DB creato
CREATE TABLE Paziente ( codicepaziente char(5) PRIMARY KEY,
cognome varchar(20) NOT NULL,
nome varchar(20) NOT NULL ); //Creo la tabella Paziente con i vari attributi
CREATE TABLE Indirizzo ( cap char(5) PRIMARY KEY,
via varchar(25) NOT NULL,
città varchar(20) NOT NULL,
codicepaziente char (5)
REFERENCES Paziente (codicepaziente)
ON UPDATE cascade
ON DELETE cascade ); //Creo la tabella Inidirizzo con i vari attributi
CREATE TABLE Cartellaclinica ( numcartella char(8) PRIMARY KEY,
reparto varchar(15) NOT NULL,
diagnosi varchar(100) NOT NULL,
codicepaziente char (5)
REFERENCES Paziente (codicepaziente)
ON UPDATE cascade
ON DELETE cascade ); //Creo la tabella Cartella Clinica con i vari attributi
CREATE TABLE Data ( giorno integer NOT NULL,
mese integer NOT NULL,
anno integer NOT NULL,
CHECK (giorno > 0 and giorno <= 31),
CHECK (mese > 0 and giorno <= 12),
CHECK (anno >= 1969),
numcartella char(8)
REFERENCES Cartellaclininca (numcartella)
ON UPDATE cascade
ON DELETE cascade,
PRIMARY KEY (numcartella, mese, anno) ); //Creo la tabella Data con i vari attributi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment