Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

SQL question. My assignment is to create the following mini database. I don't know how to reference the composite primary key in the Lot _Permit_Type

SQL question. My assignment is to create the following mini database. I don't know how to reference the composite primary key in the Lot _Permit_Type table. Also, would you look it over and check my foreign keys, etc. are correct. The scenario is for university parking lot permits.

Create Table Owner (

oid int NOT NULL,

oname varchar (30) NOT NULL,

otype char (1) NOT NULL,

email varchar (40) NOT NULL,

PRIMARY KEY (oid));

Create Table Permit_Type

(ptype varchar (20) NOT NULL, -- type, e.g. evening only, compact car, electric

description varchar (30),

price decimal (4,2) NOT NULL,

otype char (1) NOT NULL, -- 1=student, 2=faculty

PRIMARY KEY (ptype));

Create Table Permit

(pid int NOT NULL,

oid int NOT NULL,

ptype varchar (20) NOT NULL,

expiredate date NOT NULL,

PRIMARY KEY (pid),

FOREIGN KEY (oid) REFERENCES Owner (oid),

FOREIGN KEY (ptype) REFERENCES Permit_Type (ptype));

Create Table Car

(cid int NOT NULL,

oid int NOT NULL,

Make varchar (30) NOT NULL,

Model varchar (30) NOT NULL,

Color varchar (20) NOT NULL,

Plate varchar (10) NOT NULL,

State varchar (2) NOT NULL,

Primary KEY (cid),

FOREIGN KEY (oid) REFERENCES Owner(oid));

Create Table Lot

(lid int NOT NULL,

lname varchar (30) NOT NULL,

capacity int NOT NULL,

Primary Key (lid));

Create table Lot_Permit_Type

(lid int NOT NULL,

ptype varchar(20) NOT NULL,

Primary Key (lid, ptype)) ; /* REFERENCES lot(lid) permit_type (ptype)); I don't know the syntax for referencing a composit primary key. */

create table ticket_type

(ttype int NOT NULL,

tdescription varchar (30) NOT NULL,

amount decimal (4,2) NOT NULL,

Primary Key (ttype));

create table ticket

(tid int NOT NULL,

cid int NOT NULL,

lid int NOT NULL,

ttype int NOT NULL,

status int NOT NuLL, --1 issued, 2 paid,

tdate date NOT NULL,

paydate date NOT NULL,

note varchar (400) NOT NULL,

Primary Key (tid),

FOREIGN KEY (cid) REFERENCES car (cid),

FOREIGN KEY (lid) REFERENCES lot (lid),

FOREIGN KEY (ttype) REFERENCES ticket_type (ttype));

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions

Question

Discuss all branches of science

Answered: 1 week ago