Guest User

Untitled

a guest
Jun 19th, 2018
829
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 11.09 KB | None | 0 0
  1. -----------------------------------------------
  2. -- MySQL
  3. -- @ Author Dat Nguyen and Reid Stagemeyer
  4. -- Host: localhost Database: datduyn
  5. -- ------------------------------------------------------
  6. -- Server version 5.1.57
  7.  
  8.  
  9.  
  10.  
  11.  
  12.  
  13. -- Uncomment these piece to test them locally
  14. -- use rstagemeyer;
  15. -- use datduyn;
  16. -- use ims;
  17.  
  18. -- drop the old version before creating new DB
  19. DROP TABLE IF EXISTS `InvoiceProducts`;
  20. DROP TABLE IF EXISTS `Invoices`;
  21. DROP TABLE IF EXISTS `Refreshments`;
  22. DROP TABLE IF EXISTS `ParkingPasses`;
  23. DROP TABLE IF EXISTS `SeasonPasses`;
  24. DROP TABLE IF EXISTS `MovieTickets`;
  25. DROP TABLE IF EXISTS `Products`;
  26. DROP TABLE IF EXISTS `Customers`;
  27. DROP TABLE IF EXISTS `Emails`;
  28. DROP TABLE IF EXISTS `Persons`;
  29. DROP TABLE IF EXISTS `Addresses`;
  30. DROP TABLE IF EXISTS `StateCountries`;
  31. DROP TABLE IF EXISTS `Countries`;
  32.  
  33. --
  34. -- Tables structure for Products
  35. --
  36.  
  37. CREATE TABLE Products(
  38. id INT NOT NULL PRIMARY KEY AUTO_INCREMENT,
  39. productCode VARCHAR(255) UNIQUE NOT NULL,
  40. productType VARCHAR(2) NOT NULL
  41. );
  42. -- Dumping data For table `Product`
  43. INSERT INTO Products(productCode, productType) VALUES
  44. ('b29e','S'),
  45. ('ff23','R'),
  46. ('fp12','M'),
  47. ('90fa','P'),
  48. ('1239','M'),
  49. ('782g','M'),
  50. ('3289','P'),
  51. ('32f4','R'),
  52. ('3y92','S'),
  53. ('90fb','P'),
  54. ('xer4','S'),
  55. ('yp23','R');
  56.  
  57. -- create product related object table.
  58. -- Refreshment DB table
  59. CREATE TABLE Refreshments(
  60. id INT NOT NULL PRIMARY KEY AUTO_INCREMENT,
  61. name varchar(255) NOT NULL,
  62. cost float NOT NULL default '0.0',
  63. haveTicket boolean NOT NULL default 0,# TODO:
  64. productID INT NOT NULL,
  65. FOREIGN KEY(productID) REFERENCES Products(id)
  66. );
  67. -- Dumping data For table `Refreshment`
  68. INSERT INTO Refreshments(name, cost, haveTicket, productID) VALUES
  69. ('Labatt Beer-20oz',4.99,0,2),
  70. ('Caramel Popcorn',5.50,0,8),
  71. ('Double Cheeseburger',9.00,0,12);
  72.  
  73. -- Parkingpass DB table.
  74. CREATE TABLE ParkingPasses(
  75. id INT NOT NULL PRIMARY KEY AUTO_INCREMENT,
  76. fee float NOT NULL DEFAULT '0.0',
  77. productID INT NOT NULL,
  78. FOREIGN KEY(productID) REFERENCES Products(id)
  79. );
  80. -- Dumping data For table `ParkingPass`
  81. INSERT INTO ParkingPasses(fee, productID) VALUES
  82. (25.00,4),
  83. (55.00,7),
  84. (20.00,10);
  85.  
  86. #Seasonpass DB table.
  87. CREATE TABLE SeasonPasses(
  88. id INT NOT NULL PRIMARY KEY AUTO_INCREMENT,
  89. name varchar(255) NOT NULL DEFAULT 'na',
  90. startDate DATE NOT NULL,
  91. endDate DATE NOT NULL,
  92. cost float NOT NULL DEFAULT '0.0',
  93. productID INT NOT NULL,
  94. FOREIGN KEY(productID) REFERENCES Products(id)
  95. );
  96. -- Dumping data For table `ParkingPass`
  97. INSERT INTO SeasonPasses(name, startDate, endDate, cost, productID) VALUES
  98. ('Winter Special','2016-12-13','2017-01-07',120.00,1),
  99. ('BlackFriday Deal','2016-11-24','2016-11-29',58.00,9),
  100. ('FiveWeeks-Unlimited','2016-10-07','2016-11-11',185.00,11);
  101.  
  102. -- create Countries, States databases table
  103. CREATE TABLE Countries(
  104. id INT NOT NULL PRIMARY KEY AUTO_INCREMENT,
  105. name VARCHAR(255) NOT NULL DEFAULT 'na'
  106. );
  107.  
  108. -- dumping data for Countries
  109. INSERT INTO Countries(name)
  110. VALUES ('USA'),('Canada'),('Mexico');
  111.  
  112.  
  113. -- create States database table
  114. CREATE TABLE StateCountries(
  115. id INT NOT NULL PRIMARY KEY AUTO_INCREMENT,
  116. name VARCHAR(5) NOT NULL DEFAULT 'na',
  117. fullName VARCHAR(255) NOT NULL DEFAULT 'na',
  118. countryID INT NOT NULL,
  119. FOREIGN KEY(countryID) REFERENCES Countries(id)
  120. );
  121. -- Dumping data for States
  122. INSERT INTO StateCountries(name,fullName,countryID) VALUES
  123. ('AL', 'Alabama',1),('AK', 'Alaska',1),('AZ', 'Arizona',1),('AR', 'Arkansas',1),
  124. ('CA', 'California',1),('CO', 'Colorado',1),('CT', 'Connecticut',1),('DE', 'Delaware',1),
  125. ('DC', 'District of Columbia',1),('FL', 'Florida',1),('GA', 'Georgia',1),('HI', 'Hawaii',1),
  126. ('ID', 'Idaho',1),('IL', 'Illinois',1),('IA', 'Iowa',1),('KS', 'Kansas',1),('KY', 'Kentucky',1),
  127. ('LA', 'Louisiana',1),('ME', 'Maine',1),('MD', 'Maryland',1),('MA', 'Massachusetts',1),
  128. ('MI', 'Michigan',1),('MN', 'Minnesota',1),('MS', 'Mississippi',1),('MO', 'Missouri',1),
  129. ('MT', 'Montana',1),('NE', 'Nebraska',1),('NV', 'Nevada',1),('NH', 'New Hampshire',1),
  130. ('NJ', 'New Jersey',1),('NM', 'New Mexico',1),('NY', 'New York',1),('NC', 'North Carolina',1),
  131. ('ND', 'North Dakota',1),('OH', 'Ohio',1),('OK', 'Oklahoma',1),('OR', 'Oregon',1),
  132. ('PA', 'Pennsylvania',1),('PR', 'Puerto Rico',1),('RI', 'Rhode Island',1),('SC', 'South Carolina',1),
  133. ('SD', 'South Dakota',1),('TN', 'Tennessee',1),('TX', 'Texas',1),('UT', 'Utah',1),
  134. ('VT', 'Vermont',1),('VA', 'Virginia',1),('WA', 'Washington',1),('WV', 'West Virginia',1),
  135. ('WI', 'Wisconsin',1),('WY', 'Wyoming',1),('ON','Ontra',2),('FD','Farade',3),('BCS','BaoCCongSang',3);
  136.  
  137.  
  138. -- create address DB table
  139. CREATE TABLE Addresses(
  140. id INT NOT NULL PRIMARY KEY AUTO_INCREMENT,
  141. street varchar(255) NOT NULL DEFAULT 'na',
  142. city varchar(255) NOT NULL DEFAULT 'na',
  143. stateCountryID INT NOT NULL,
  144. zipcode varchar(255) NOT NULL DEFAULT 'na',
  145. FOREIGN KEY(stateCountryID) REFERENCES StateCountries(id)
  146. );
  147. -- Dumping data For table `Address`
  148. INSERT INTO Addresses(street,city,stateCountryID,zipcode) VALUES
  149. ('1060 West Addison Street','Chicago',14,'600613'),
  150. ('123 N 1st Street','Omaha',27,'68116'),
  151. ('8753 West 3rd Ave.','Dallas',44,'75001'),
  152. ('123 Friendly Street','Ottawa',52,'KA 0G9'),
  153. ('1 Wall Street ','New York',32,'10005-0012'),
  154. ('321 Bronx Street','New York',32,'10004'),
  155. ('301 Front St W','Toronto',52,'M5V 2T6'),
  156. ('1 Blue Jays Way','Toronto',52,'M5V 1J1'),
  157. ('Campos El290','Mexico City', 53,' '),
  158. ('Avery Hall','Lincoln',27,'68503'),
  159. ('126-01 Roosevelt Ave','Flushing',32,'11368'),
  160. ('1 MetLife Stadium Dr', 'East Rutherford', 30,'07073'),
  161. ('1 E 161st St', 'Bronx', 32,'10451'),
  162. ('700 E Grand Ave', 'Chicago', 14, '60611'),
  163. ('333 W 35th St', 'Chicago', 14,'60616'),
  164. ('800 West 7th Street', 'Albuquerque', 31, '87105'),
  165. ('123 Cabo San Lucas', 'Los Cabos', 54,'11111'),
  166. ('259 Concorde Suites', 'Lincoln', 27,'68588-0115'),
  167. ('1223 Oldfather Hall', 'Lincoln', 27,'68503'),
  168. ('123 Venture Way', 'Culver City', 5,'90230' ),
  169. ('9800 Savage Rd', 'Fort Meade', 20,'20755'),
  170. ('456 West 7th St.', 'Omaha', 27,'68500'),
  171. ('3555 South 140th Plaza', 'Omaha', 27,'68144'),
  172. ('755 Willard Drive','Ashwaubenon',50,'54304'),
  173. ('6301 University Ave','Cedar Falls',15,'50613');
  174.  
  175.  
  176. -- Movie Ticket DB table
  177. CREATE TABLE MovieTickets(
  178. id INT NOT NULL PRIMARY KEY AUTO_INCREMENT,
  179. dateTime datetime NOT NULL,
  180. movieName VARCHAR(255) NOT NULL,
  181. addressID INT NOT NULL,
  182. screenNumber VARCHAR(255) NOT NULL,
  183. pricePerUnit FLOAT NOT NULL DEFAULT '0.0',
  184. productID INT NOT NULL,
  185. FOREIGN KEY(productID) REFERENCES Products(id),
  186. FOREIGN KEY(addressID) REFERENCES Addresses(id)
  187. );
  188. -- Dumping data For table `MovieTicket`
  189. INSERT INTO MovieTickets(dateTime, movieName, addressID, screenNumber, pricePerUnit, productID) VALUES
  190. ('2016-10-21 13:10','A Monster Calls',23,'2A',21.50,3),
  191. ('2016-09-13 15:30','The Wild Life',24,'12F',11.00,5),
  192. ('2016-11-10 10:00','Shut In',25,'32D',25.00,6);
  193.  
  194. --
  195. -- Tables structure for Person
  196. --
  197.  
  198. -- create PersonDB
  199. CREATE TABLE Persons(
  200. id INT NOT NULL PRIMARY KEY AUTO_INCREMENT,
  201. personCode varchar(255) UNIQUE NOT NULL,
  202. lastName varchar(255) NOT NULL,
  203. firstName varchar(255) NOT NULL,
  204. addressID INT NOT NULL,
  205. foreign key(addressID) references Addresses(id)
  206. );
  207.  
  208. INSERT INTO Persons(personCode,lastName,firstName,addressID) VALUES
  209. ('944c','Castro','Starlin',1),
  210. ('306a','Sampson','Brock',2),
  211. ('55bb','O''Brien','Miles',3),
  212. ('2342','O''Brien','Miles',4),
  213. ('aef1','Gekko','Gordon',5),
  214. ('321f','Fox','Bud',6),
  215. ('ma12','Sveum','Dale',7),
  216. ('321nd','Hartnell','William',8),
  217. ('nf32a','Troughton','Patrick',9),
  218. ('321na','Pertwee','Jon',10),
  219. ('231','Baker','Tom',11),
  220. ('6doc','Hurndall','Richard',12),
  221. ('321dr','Baker','C.',13),
  222. ('1svndr','McCoy','Sylvester',14),
  223. ('1231st','McGann','Paul',15),
  224. ('nwdoc1','Eccleston','Chris',16),
  225. ('2ndbestd','Tennant','David',17),
  226. ('wrddoc','Smith','Matt',18),
  227. ('bbchar','Ehrmantraut','Kaylee',19),
  228. ('doc05','Davison','Peter',20);
  229.  
  230. -- create join table named Emails
  231. create table Emails(
  232. id INT NOT NULL PRIMARY KEY AUTO_INCREMENT,
  233. personID INT NOT NULL,
  234. email VARCHAR(255) NOT NULL,
  235. FOREIGN KEY(personID) REFERENCES Persons(id)
  236. );
  237.  
  238. INSERT INTO Emails(personID,email) VALUES
  239. (1,'scastro@cubs.com'),
  240. (1, 'starlin_castro13@gmail.com'),
  241. (2,'brock_f_sampson@gmail.com'),
  242. (2, 'bsampson@venture.com'),
  243. (3,'obrien@ds9.com'),
  244. (3, 'obrien@enterprise.gov'),
  245. (6,'bfox@gmail.com'),
  246. (6, 'csheen@crazy.net'),
  247. (7,'sveum@cubs.com'),
  248. (8, 'whartnell@doctors.com'),
  249. (8,'dr@who.com'),
  250. (9, 'ptroug@cse.unl.edu'),
  251. (9,'ptrou32@unl.edu'),
  252. (10, 'jpet@whofan.com'),
  253. (11,'famousdoc@who.com'),
  254. (11, 'tbaker@cse.unl.edu'),
  255. (11,'mostfamous@whoian.com'),
  256. (11, 'thedoctor@bbc.com'),
  257. (12,'rhurndall@cse.unl.edu'),
  258. (12, 'richard@unl.edu'),
  259. (13,'dr@baker.com'),
  260. (14, 'slyguy@hotmail..com'),
  261. (14, 'mccoy@whofan.com'),
  262. (15, 'pmcgann@mlb.com'),
  263. (15, 'foo@bar.com'),
  264. (15, 'pmc@unl.edu'),
  265. (16, 'newguy@whoian.com'),
  266. (17, 'actor@shakespeare.com'),
  267. (17, 'tdavid@unl.edu'),
  268. (18, 'msmith@who.com'),
  269. (18, 'thedoc@cse.unl.edu');
  270. --
  271. -- Tables structure for Customer
  272. --
  273. CREATE TABLE Customers(
  274. id INT NOT NULL PRIMARY KEY AUTO_INCREMENT,
  275. customerCode VARCHAR(255) UNIQUE NOT NULL,
  276. customerName VARCHAR(255) NOT NULL,
  277. customerType VARCHAR(255) NOT NULL DEFAULT 'na',
  278. primaryContactID INT NOT NULL,
  279. addressID INT NOT NULL,
  280. FOREIGN KEY(primaryContactID) REFERENCES Persons(id),
  281. FOREIGN KEY(AddressID) REFERENCES Addresses(id)
  282. );
  283.  
  284.  
  285. INSERT INTO Customers(customerCode,customerName,customerType,primaryContactID,addressID) VALUES
  286. ('C001','Clark Consultants','G',11, 19),
  287. ('C002','CAS International Fellows','S',1, 20),
  288. ('C003','Valueless Club','S',2, 21),
  289. ('C004','Stony Brook','G', 6, 22),
  290. ('C005','Hewlett Industries','G', 19, 1),
  291. ('C006','Gregory Smith','S', 13, 23);
  292.  
  293. --
  294. -- Table structure for Invoices
  295. --
  296. -- create table to store Invoice attribute
  297. CREATE TABLE Invoices(
  298. id INT NOT NULL PRIMARY KEY AUTO_INCREMENT,
  299. invoiceCode VARCHAR(255) UNIQUE NOT NULL,
  300. customerID INT NOT NULL DEFAULT 0,
  301. salesPersonID INT NOT NULL DEFAULT 0,
  302. invoiceDate DATE NOT NULL,
  303. FOREIGN KEY(CustomerID) REFERENCES Customers(id),
  304. FOREIGN KEY(salesPersonID) REFERENCES Persons(id)
  305. );
  306.  
  307. INSERT INTO Invoices(invoiceCode,customerID,salesPersonID,invoiceDate) VALUES
  308. ('INV001',1,16,'2016-09-03'),
  309. ('INV002',2,17,'2016-11-10'),
  310. ('INV003',5,18,'2016-11-26'),
  311. ('INV004',3,12,'2016-10-16');
  312.  
  313.  
  314.  
  315. -- create table to store product associate to an invoice.
  316. -- note field were created so user can add any additional note
  317. -- for ex. ticket asociated with the Parkingpass
  318. -- or if he want to add special discount for any specfic product
  319. --
  320. CREATE TABLE InvoiceProducts(
  321. id INT NOT NULL PRIMARY KEY AUTO_INCREMENT,
  322. invoiceID INT NOT NULL ,
  323. productID INT NOT NULL,
  324. unit INT NOT NULL,
  325. note VARCHAR(255),
  326. FOREIGN KEY(invoiceID) REFERENCES Invoices(id),
  327. FOREIGN KEY(productID) REFERENCES Products(id),
  328. CONSTRAINT uniqueIP UNIQUE(invoiceID, productID)
  329. );
  330.  
  331. -- Added CONSTRAIN unique key word to prevent duplicate product in the
  332. -- same Invocie
  333. INSERT INTO InvoiceProducts(invoiceID, productID, unit) VALUES
  334. (1,3,2),
  335. (1,7,1),
  336. (1,2,4),
  337. (2,1,23),
  338. (2,5,31),
  339. (2,4,30),
  340. (2,8,17),
  341. (3,6,7),
  342. (3,9,6),
  343. (3,7,2),
  344. (3,12,4),
  345. (4,10,3),
  346. (4,8,3);
  347.  
  348. --
  349. -- General select Statesments to see if tables are created and stored properly
  350. --
  351. -- select * from Addresses;
  352. -- select * from Persons;
  353. -- select * from Customers;
  354. -- select * from Emails;
  355. -- select * from Products;
  356. -- select * from MovieTickets;
  357. -- select * from SeasonPasses;
  358. -- select * from ParkingPasses;
  359. -- select * from Refreshments;
  360. -- select * from Invoices;
  361. -- select * from InvoiceProducts;
Add Comment
Please, Sign In to add comment