SQLize Online / PHPize Online  /  SQLtest Online

A A A
Share      Blog   Popular
Copy Format Clear
/*GrubHub ER Database SQL- Katherine Baker*/ /*Creating the GrubHub DB*/ /*Makeing the Tables*/ /*1. Customer Table*/ create table Customer( c_no int Primary Key, name varchar(20), address varchar(50), "phone no" bigint, c_paymentId int Unique ); /*2. Restaurant Table*/ create table Restaurant( r_no int Primary Key, name varchar(20), address varchar(50), "phone no" bigint, r_paymentId int Unique, cuisine varchar(20) ); /*3. Drivers Table*/ create table Drivers( id int Primary Key, name varchar(20), "phone no" bigint, license_no int, d_paymentId int Unique, status varchar(20) ); /*4. Orders Table*/ create table Orders( c_no int Foreign Key REFERENCES Customer(c_no), r_no int Foreign Key REFERENCES Restaurant(r_no), d_no int Foreign Key REFERENCES Drivers(id), o_no bigint Primary Key, "timestamp" timestamp, status varchar(20), ); /*5. GrubHub_Accounting Table*/ create table GrubHub_Accounting( c_payemntId int Foreign Key REFERENCES Customer(c_paymentId), r_paymentId int Foreign Key REFERENCES Restaurant(r_paymentId), d_paymentId int Foreign Key REFERENCES Drivers(d_paymentId), ); /* Adding Check constraint to allow only four values(Placed/Out/Cancelled/Fulfilled) for status cloumn in Orders Table*/ ALTER TABLE Orders ADD CONSTRAINT chK_status CHECK (status = 'Placed' or status = 'Out' or status = 'Cancelled' or status = 'Fulfilled'); /* Adding Check constraint to allow only two values(active/inactive) for status cloumn in Drivers Table*/ ALTER TABLE Drivers ADD CONSTRAINT chK_driver_status CHECK (status = 'Active' or status = 'Inactive');
Stuck with a problem? Got Error? Ask ChatGPT!
Copy Clear