· 6 years ago · Dec 20, 2019, 08:04 AM
1use HGRHz9Yjew;
2
3drop table if exists Dienstfahrt;
4drop table if exists Mitarbeiter;
5drop table if exists Fahrzeuge;
6
7
8create table if not exists Fahrzeug(ID int primary key,
9Kennzeichen VARCHAR(20) UNIQUE,
10Beschaffungsdatum date check(Beschaffungsdatum < Date.Now),
11AnzPlätze int check (AnzPlätze> 0),
12Fahrzeugtyp enum("LKW","PKW"));
13
14create table if not exists Mitarbeiter(Personalnummer int primary key,
15Vorname VARCHAR(20),
16Nachname VARCHAR(20),
17Einstellungsdatum date check(Einstellungsdatum < Date.Now),
18Kürzel VARCHAR(3) UNIQUE,
19GehaltInEuro int Check (Gehalt > 0)) ;
20
21create table if not exists Dienstfahrt(Personalnummer int,
22FahrzeugID int,
23KmVor int check (KmVor >= 0),
24KmNach int Check (KmNch > 0),
25 Check (KmVor < KmNach),
26 Primary key (FahrzeugID,Personalnummer));
27
28 Alter table Dienstfahrt
29 Add constraint FK_Mitarbeiter_Dienstfahrt
30 Foreign key (Personalnummer) references Mitarbeiter (Personalnummer);
31
32 Alter table Dienstfahrt
33 Add constraint FK_Fahrzeug_Dienstfahrt
34 Foreign key (FahrzeugID) references Fahrzeug (ID);