create schema Oktoberfest; set schema Oktoberfest; drop table faehrt; drop table bedient_an; drop table spielt; drop table bietet_an; drop table Schicht; drop table Bedienung; drop table Reservierung; drop table Produkt; drop table Besucher; drop table Fahrt; drop table Fahrgeschaeft; drop table Hit; drop table Auftritt; drop table Band; drop table Tisch; drop table Zelt; drop table Verkaufsstaende; drop table Zelte_Staende; drop table Produkttyp; create table Produkttyp ( Name varchar(40) not null primary key, Beschreibung varchar(255) ); create table Zelte_Staende ( Name varchar(40) not null primary key, Adresse varchar(40) ); create table Verkaufsstaende ( Name varchar(40) not null primary key, Art varchar(40) ); create table Zelt ( Name varchar(40) not null primary key, AnzahlTische int ); create table Tisch ( Zelt varchar(40) not null, TischNr int not null, AnzahlSitzplaetze int, primary key(Zelt,TischNr) ); create table Band ( Name varchar(40) not null primary key, Homepage varchar(255) ); create table Auftritt ( ID int not null primary key, Datum date, Zeit time, Zelt varchar(40), Band varchar(40) ); create table Hit ( Titel varchar(40) not null primary key, Dauer int ); create table Fahrgeschaeft ( Name varchar(40) not null primary key, Adresse varchar(40), AnzahlPlaetze int, Mindestgroesse int, Mindestalter int ); create table Fahrt ( FahrtID int not null primary key, Datum date, Zeit time ); create table Besucher ( BesucherID int not null primary key, Nationalitaet varchar(40) not null, BAlter int not null, Geschlecht char(1) not null, unique (Nationalitaet, BAlter, Geschlecht) ); ALTER TABLE Besucher ADD CONSTRAiNT Besucher_G CHECK(Geschlecht in ('m','w')); create table Produkt ( ID int not null primary key, Typ varchar(40), Zelt_Stand varchar(40), Besucher int, TransaktionsID int ); create table Reservierung ( ResID int not null primary key, Name varchar(40), Mindestverzehr decimal(10, 2), Datum date, Zeit time, Besucher int, Zelt varchar(40), TischNr int ); create table Bedienung ( PersID int not null primary key, Name varchar(40) ); create table Schicht ( Datum date not null, Zeit time not null, primary key (Datum, Zeit) ); create table bietet_an ( Produkttyp varchar(40) not null, Zelt_Stand varchar(40) not null, Bezeichnung varchar(40), Preis decimal(10,2), primary key(Produkttyp, Zelt_Stand) ); create table spielt ( Auftritt int not null, LiedNr smallint not null, Hit varchar(40) not null, Band varchar(40), primary key(Auftritt, LiedNr) ); create table bedient_an ( SchichtDatum date not null, SchichtZeit time not null, Zelt varchar(40) not null, Tisch int not null, Bedienung int, primary key (Schichtdatum, SchichtZeit, Zelt, Tisch) ); create table faehrt ( FahrtID int not null, Besucher int not null, Fahrgeschaeft varchar(40), Preis decimal(10,2), primary key(FahrtID, Besucher) ); ALTER TABLE spielt ADD foreign key(Auftritt) references Auftritt foreign key(Hit) references Hit foreign key (Band) references Band; ALTER TABLE bietet_an ADD foreign key(Produkttyp) references Produkttyp foreign key(Zelt_Stand) references Zelte_Staende; ALTER TABLE Reservierung ADD foreign key (Zelt,TischNr) references Tisch foreign key (Besucher) references Besucher; ALTER TABLE Produkt ADD foreign key (Besucher) references Besucher foreign key (Zelt_Stand) references Zelte_Staende; ALTER TABLE Auftritt ADD foreign key (Band) references Band; ALTER TABLE faehrt ADD foreign key (Fahrgeschaeft) references Fahrgeschaeft foreign key (Besucher) references Besucher; ALTER TABLE Tisch ADD foreign key (Zelt) references Zelt; ALTER TABLE Zelt ADD foreign key (Name) references Zelte_Staende; ALTER TABLE Verkaufsstaende ADD foreign key (Name) references Zelte_Staende;