1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90
|
CREATE TABLE US_User(
US_ID INT IDENTITY,
US_Email VARCHAR(50) NOT NULL,
US_Password VARCHAR(50),
US_LastName VARCHAR(50) NOT NULL,
US_FirstName VARCHAR(50) NOT NULL,
US_ddn DATE NOT NULL,
US_PhoneNumber INT,
PRIMARY KEY(US_ID),
UNIQUE(US_Email)
);
CREATE TABLE ME_Member(
US_ID INT,
ME_SerialNumber CHAR(6) NOT NULL,
PRIMARY KEY(US_ID),
UNIQUE(ME_SerialNumber),
FOREIGN KEY(US_ID) REFERENCES US_User(US_ID)
);
CREATE TABLE ST_Staff(
US_ID INT,
ST_SerialNumber CHAR(6) NOT NULL,
PRIMARY KEY(US_ID),
UNIQUE(ST_SerialNumber),
FOREIGN KEY(US_ID) REFERENCES US_User(US_ID)
);
CREATE TABLE CI_City(
CI_ID INT IDENTITY,
CI_Insee CHAR(5) NOT NULL,
CI_Name VARCHAR(50) NOT NULL,
PRIMARY KEY(CI_ID),
UNIQUE(CI_Insee)
);
CREATE TABLE PA_Parking(
PA_ID INT IDENTITY,
PA_Length DECIMAL(5,2) NOT NULL,
PA_Width DECIMAL(5,2) NOT NULL,
PA_Height DECIMAL(5,2) NOT NULL,
PA_GeoGPS GEOGRAPHY NOT NULL,
PA_Address1 VARCHAR(38) NOT NULL,
PA_Address2 VARCHAR(38),
PA_Access VARCHAR(50),
CI_ID INT NOT NULL,
US_ID INT NOT NULL,
PRIMARY KEY(PA_ID),
FOREIGN KEY(CI_ID) REFERENCES CI_City(CI_ID),
FOREIGN KEY(US_ID) REFERENCES ME_Member(US_ID)
);
CREATE TABLE AD_Advertisement(
PA_ID INT,
AD_ID SMALLINT,
AD_Date DATE NOT NULL,
AD_tarif DECIMAL(7,2) NOT NULL,
US_ID INT NOT NULL,
PRIMARY KEY(PA_ID, AD_ID),
FOREIGN KEY(PA_ID) REFERENCES PA_Parking(PA_ID),
FOREIGN KEY(US_ID) REFERENCES ME_Member(US_ID)
);
CREATE TABLE RE_Reserve(
PA_ID INT,
CA_Date DATE,
RE_Dtfin DATE NOT NULL,
US_ID INT NOT NULL,
PRIMARY KEY(PA_ID, CA_Date),
FOREIGN KEY(PA_ID) REFERENCES PA_Parking(PA_ID),
FOREIGN KEY(US_ID) REFERENCES ME_Member(US_ID)
);
CREATE TABLE MO_Moderate(
US_ID INT,
PA_ID INT,
AD_ID SMALLINT,
MO_HourlyDate DATETIME2 NOT NULL,
MO_Purpose VARCHAR(128),
PRIMARY KEY(US_ID, PA_ID, AD_ID),
FOREIGN KEY(US_ID) REFERENCES ST_Staff(US_ID),
FOREIGN KEY(PA_ID, AD_ID) REFERENCES AD_Advertisement(PA_ID, AD_ID)
);
ALTER TABLE AN_annonce
ADD CONSTRAINT FK_publier_posseder
FOREIGN KEY (PE_ident, PA_ident)
REFERENCES PA_parking(PE_ident, PA_ident)
; |