- a.
stock |
|
|
|
|
|
stockcode |
firmname |
stockquantity |
stockdividend |
stockpe |
stkexcode |
listing |
|
|
listingprice |
stockcode |
stkexcode |
stockexchange |
|
|
stkexcode |
exchangename |
nationcode |
nation |
|
|
nationcode |
nationname |
exchangerate |
CREATE TABLE stock (
stockcode CHAR(3),
firmname VARCHAR(20),
stockquantity DECIMAL(8),
stockdividend DECIMAL(5,2),
stockpe DECIMAL(5),
stkexcode CHAR(5),
PRIMARY KEY (stockcode)
FOREIGN KEY fkhomeexchange (stkexcode) REFERENCES stockexchange);
CREATE TABLE listing (
listingprice DECIMAL(6,2),
stockcode CHAR(3),
stkexcode CHAR(5),
PRIMARY KEY (stockcode, stkexcode),
FOREIGN KEY fkstock(stockcode) REFERENCES stock,
FOREIGN KEY fkstockexchange(stkexcode) REFERENCES stockexchange);
CREATE TABLE STOCKEXCHANGE (
stkexcode CHAR(5),
exchangename VARCHAR(20),
nationcode CHAR(3),
PRIMARY KEY (stkexcode),
FOREIGN KEY fknation(nationcode) REFERENCES nation);
CREATE TABLE nation (
nationcode CHAR (3),
nationname VARCHAR(20),
exchangerate DECIMAL(9,5),
PRIMARY KEY (nationcode));
- b.
nation |
|
|
natname |
natpop |
natarea |
adminunit |
|
|
|
|
unitname |
unittype |
unitpop |
unitarea |
natname |
city |
|
|
|
|
|
|
cityname |
citypop |
cityarea |
captype |
natcaptype |
natname |
unitname |
adminunitcity |
|
|
|
unitcaptype |
cityname |
natname |
unitname |
CREATE TABLE nation (
natname VARCHAR(30),
natpop INTEGER,
natarea INTEGER,
PRIMARY KEY(natname));
CREATE TABLE adminunit (
unitname VARCHAR(30),
unittype VARCHAR(10),
unitpop INTEGER,
unitarea INTEGER,
natname VARCHAR(30),
PRIMARY KEY(natname,unitname),
CONSTRAINT fknationadmin FOREIGN KEY(natname) REFERENCES nation);
CREATE TABLE city (
cityname VARCHAR(30),
citypop INTEGER,
cityarea INTEGER,
natcaptype VARCHAR(10),
unitname VARCHAR(30),
natname VARCHAR(30),
PRIMARY KEY(natname,unitname,cityname),
CONSTRAINT fknationcity FOREIGN KEY(natname) REFERENCES nation;
CONSTRAINT fknationadmin FOREIGN KEY(natname,unitname) REFERENCES adminunit);
CREATE TABLE adminunitcity (
unitcaptype VARCHAR(10),
cityname VARCHAR(30),
natname VARCHAR(30),
unitname VARCHAR(30),
PRIMARY KEY(natname,unitname, cityname),
CONSTRAINT fkunit FOREIGN KEY(natname,unitname) REFERENCES adminunit,
CONSTRAINT fkcity FOREIGN KEY(natname,unitname,cityname) REFERENCES city);
- c.
person |
|
|
|
|
|
|
|
|
id |
dob |
fname |
oname |
lname |
gender |
spouse1 |
spouse2 |
marriageno |
marriage |
|
|
|
|
|
marriageno |
marriagestatus |
begindate |
enddate |
spouse1 |
spouse2 |
CREATE TABLE person (
id INTEGER,
dob DATE,
fname VARCHAR(20),
oname VARCHAR(20),
lname VARCHAR(20),
gender CHAR(1),
spouse1 INTEGER,
spouse2 INTEGER,
marriageno INTEGER,
PRIMARY KEY (id),
INDEX `INX_spouse1` (spouse1),
INDEX `INX_spouse2` (spouse2));
CREATE TABLE marriage (
marriageno INTEGER,
marriagestatus CHAR(5),
begindate DATE,
enddate DATE,
spouse1 INTEGER,
spouse2 INTEGER,
PRIMARY KEY (marriageno, spouse1, spouse2));
ALTER TABLE person
ADD CONSTRAINT fkchild
FOREIGN KEY (marriageno, spouse1, spouse2)
REFERENCES marriage(marriageno, spouse1, spouse2);
ALTER TABLE marriage
ADD CONSTRAINT fkspouse1
FOREIGN KEY (spouse1) REFERENCES person(spouse1),
ADD CONSTRAINT fkspouse2
FOREIGN KEY (spouse2) REFERENCES person(spouse2);
- d.
aircraft |
|
aircraftcode |
... |
lease |
|
|
|
|
startdate |
... |
aircraftcode |
agentid |
airlinename |
CREATE TABLE aircraft (
aircraftcode VARCHAR(10), ...
PRIMARY KEY (aircraftcode));
CREATE TABLE agent
agentid VARCHAR(10), ...,
PRIMARY KEY(AGENTID));
CREATE TABLE airline (
airlinename VARCHAR(20), ...,
PRIMARY KEY(airlinename));
CREATE TABLE lease (
startdate DATE, ...
aircraftcode VARCHAR(10),
agentid VARCHAR(10),
airlinename VARCHAR(20),
PRIMARY KEY (startdate, aircraftcode, agentid, airlinename),
FOREIGN KEY fkaircraft(aircraftcode) REFERENCES aircraft,
FOREIGN KEY fkagent(agentid) REFERENCES agent,
FOREIGN KEY fkairline(airlinename) REFERENCES airline);
- e.
monarch |
|
|
|
|
|
monname |
monnumb |
montype |
rgnbegin |
smonname |
smonnum |
CREATE TABLE monarch (
monname VARCHAR(30),
monnum VARCHAR(5),
montype CHAR(5) NOT NULL,
rgnbegin DATE,
smonname VARCHAR(30),
smonnumb CHAR(5),
PRIMARY KEY(monname,monnum));