Demo entry 6741234

MySQL_Assignment

   

Submitted by anonymous on May 15, 2018 at 01:18
Language: MQL. Code size: 1.2 kB.

CREATE TABLE `STATE` (
	`Name` varchar(20) NOT NULL,
	`Region` varchar(20) NOT NULL,
	PRIMARY KEY (`Name`)
);

CREATE TABLE `CONGRESSPERSON` (
	`Congress_ID` int(20) NOT NULL AUTO_INCREMENT,
	`Name` varchar(20) NOT NULL,
	`District` varchar(20) NOT NULL,
	`Start_date` DATE,
	`Party` varchar(20) NOT NULL,
	PRIMARY KEY (`Congress_ID`)
);

CREATE TABLE `BILL` (
	`Bill_code` int(20) NOT NULL,
	`Bill_name` varchar(50) NOT NULL AUTO_INCREMENT,
	`Date_of_vote` DATE NOT NULL,
	`Passed_or_failed` varchar(10) NOT NULL,
	`Sponsor` int(20) NOT NULL,
	PRIMARY KEY (`Bill_code`)
);

CREATE TABLE `VOTE` (
	`Congress_ID` int(20) NOT NULL,
	`Bill_code` int(20) NOT NULL,
	`Result` varchar(20) NOT NULL
);

ALTER TABLE `CONGRESSPERSON` ADD CONSTRAINT `CONGRESSPERSON_fk0` FOREIGN KEY (`District`) REFERENCES `STATE`(`Name`);

ALTER TABLE `BILL` ADD CONSTRAINT `BILL_fk0` FOREIGN KEY (`Sponsor`) REFERENCES `CONGRESSPERSON`(`Congress_ID`);

ALTER TABLE `VOTE` ADD CONSTRAINT `VOTE_fk0` FOREIGN KEY (`Congress_ID`) REFERENCES `CONGRESSPERSON`(`Congress_ID`);

ALTER TABLE `VOTE` ADD CONSTRAINT `VOTE_fk1` FOREIGN KEY (`Bill_code`) REFERENCES `BILL`(`Bill_code`);

This snippet took 0.00 seconds to highlight.

Back to the Entry List or Home.

Delete this entry (admin only).