Advertisement
Guest User

Untitled

a guest
Dec 1st, 2016
165
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 13.56 KB | None | 0 0
  1. create table Manufacturer
  2. (
  3. ManufName varchar(16) Primary Key
  4. )
  5.  
  6. Create table Category
  7. (
  8. CategoryName varchar(20) Primary Key
  9. )
  10.  
  11. create table Product
  12. (
  13. ProductID int Primary Key Identity,
  14. PMfgPartNo int,
  15. PDescription varchar(25),
  16. PListPice decimal(19,2),
  17. MAnufName varchar(16) Foreign Key references Manufacturer(ManufName),
  18. CategoryName varchar(20) Foreign Key references Category(CategoryName)
  19. )
  20.  
  21. create table customer
  22. ( CustomerID int Primary Key Identity,
  23. CFName varchar(25) not null,
  24. CLName varchar (25) not null,
  25. CPhone int not null,
  26. CEmail varchar (18) not null,
  27. CAddress varchar (40),
  28. CCity varchar (15) not null,
  29. CState varchar (25) not null,
  30. CZip int not null
  31. )
  32.  
  33. Create table Employee
  34. (
  35. EmployeeID int not null Primary Key Identity,
  36. EFName varchar (18) not null,
  37. ELName varchar (18) not null,
  38. EPhone int,
  39. EEmail varchar (16) not null,
  40. EAddress varchar (14) not null,
  41. ECity varchar (30),
  42. EState varchar (17), EZip int not null,
  43. )
  44.  
  45. create table Sale
  46. (
  47. SaleId int Primary Key Identity,
  48. SaleDate date not null,
  49. EstReceiveDate date not null,
  50. SubTotal decimal(19,2) not null,
  51. Tax decimal(19,2) null,
  52. Discount decimal(19,2) not null,
  53. Total decimal(19,2) not null,
  54. EmployeeID int Foreign Key references Employee(EmployeeID),
  55. CustomerID int Foreign Key references Customer(CustomerID)
  56. )
  57.  
  58. Create table Boat
  59. (
  60. BoatID int not null Primary Key Identity,
  61. BBrand varchar(20) not null,
  62. BYear int not null,
  63. BNumEngines int not null,
  64. BLenght int,
  65. BPrice decimal(19,2) not null,
  66. BExtended decimal(19,2) not null,
  67. ManufName varchar (16) Foreign Key references Manufacturer(ManufName),
  68. CustomerID int foreign key references Customer(CustomerID)
  69. )
  70.  
  71. Create Table Engine
  72. (
  73. EngineId int Primary Key Identity,
  74. Ebrand varchar (10) not null,
  75. Eyear int not null,
  76. EOutDrive varchar(14),
  77. Eprice decimal(19,2) not null,
  78. EExtended decimal(19,2),
  79. ManufName varchar (16) Foreign Key references Manufacturer(ManufName),
  80. BoatID int foreign key references Boat(BoatID)
  81. )
  82.  
  83. Create table SaleItem
  84. (
  85. SaleItemID int Primary Key Identity,
  86. SIQuantity int not null,
  87. SIExtended decimal(19,2),
  88. ProductID int Foreign Key references Product(ProductID),
  89. SaleID int foreign key references Sale(SaleID)
  90. )
  91.  
  92.  
  93. Insert into Manufacturer
  94. Values ('Bombardier');
  95.  
  96. Insert into Manufacturer
  97. Values ('Kawasaki');
  98.  
  99. Insert into Manufacturer
  100. Values ('Z1 Boats');
  101.  
  102. Insert into Manufacturer
  103. Values ('Square');
  104.  
  105. Insert into Manufacturer
  106. values ('Honda');
  107.  
  108. Insert into Manufacturer
  109. Values ('Corsair');
  110.  
  111. Insert into Manufacturer
  112. Values ('Boston');
  113.  
  114. Insert into Manufacturer
  115. Values ('Company');
  116.  
  117.  
  118. Insert into Manufacturer
  119. Values ('Malibu');
  120.  
  121. Insert into Manufacturer
  122. Values ('MasterCraft');
  123.  
  124.  
  125.  
  126. Select *
  127. from Manufacturer
  128.  
  129. Insert into category
  130. values ('Steering Wheel');
  131.  
  132. Insert into category
  133. values ('Oil Pump');
  134.  
  135. Insert into category
  136. values ('Gasket');
  137.  
  138. Insert into category
  139. values ('Propeller');
  140.  
  141. Insert into category
  142. values ('Anchor');
  143.  
  144. Insert into category
  145. values ('Windshield Wiper');
  146.  
  147. Insert into category
  148. values ('Windshield');
  149.  
  150. Insert into category
  151. values ('Speed Limiter');
  152.  
  153. Insert into category
  154. values ('Battery');
  155.  
  156. Insert into category
  157. values ('Spark Plug');
  158.  
  159.  
  160. select *
  161. from Category
  162.  
  163. insert into Product
  164. values (2,'Good',500.00,'Honda', 'Steering Wheel');
  165.  
  166. Insert into Product
  167. values (3,'Okay', 400.00, 'Kawasaki','Propeller')
  168.  
  169. Insert into Product
  170. Values ( 5, 'Bad', 300.00, 'Bombardier', 'Spark Plug');
  171.  
  172. Insert Into Product
  173. values ( 6, 'Good', 200.00, 'Honda', 'Steering Wheel');
  174.  
  175. Insert into Product
  176. Values ( 7, 'Good', 100.00,'Z1 Boats','Battery');
  177.  
  178. Insert into Product
  179. values ( 8, 'Good', 50.00, 'Square', 'Speed Limiter');
  180.  
  181. Insert into Product
  182. values ( 9, 'Fair', 25.00,'Boston', 'Gasket');
  183.  
  184. Insert into Product
  185. values ( 4, 'Good', 24.00,'Honda', 'Battery');
  186.  
  187. Insert into Product
  188. values ( 1, 'Fair', 400.00,'Honda', 'Steering Wheel');
  189.  
  190. Insert into Product
  191. values ( 10, 'Good', 100.00,'Kawasaki', 'Propeller');
  192.  
  193. Insert into Product
  194. values ( 13, 'Used', 3500.00,'Kawasaki', 'Gasket');
  195.  
  196. Insert into Product
  197. values ( 14, 'Good', 220.00,'Kawasaki', 'Steering Wheel');
  198.  
  199. Insert into Product
  200. values ( 15, 'Okay', 1000.00,'Kawasaki', 'Propeller');
  201.  
  202. Insert into Product
  203. values ( 16, 'New', 7500.00,'Kawasaki', 'Spark Plug');
  204.  
  205. Insert into Product
  206. values ( 18, 'Fair', 29.00,'Kawasaki', 'Battery');
  207.  
  208. select *
  209. from product
  210.  
  211. set IDENTITY_INSERT customer on
  212.  
  213. Insert into Customer(CustomerID, CFName,CLName,CPhone,CEmail, CAddress, CCity, CState,CZip)
  214. values (1, 'William', 'Clifton',8010098, 'eclifton@uvu.edu','1468 N' ,'Orem', 'UT', 84058);
  215.  
  216. insert into customer (CustomerID, CFName,CLName,CPhone,CEmail, CAddress, CCity, CState,CZip)
  217. values (2, 'Anna', 'Soon', 8014567, 'asoon@yahoocom', '123 Cross', 'Orem', 'UT', 84058);
  218.  
  219. insert into customer(CustomerID, CFName,CLName,CPhone,CEmail, CAddress, CCity, CState,CZip)
  220. values (3, 'Riley', 'Hall', 8016167, 'rhall@yahoo.com', '616 Lane', 'Provo', 'UT',85064);
  221.  
  222. insert into customer(CustomerID, CFName,CLName,CPhone,CEmail, CAddress, CCity, CState,CZip)
  223. values (4, 'Vhan', 'Rid', 8016547, 'vrid@gmail.com', '123 Dane Street', 'American Fork','UT', 84003);
  224.  
  225. insert into customer(CustomerID, CFName,CLName,CPhone,CEmail, CAddress, CCity, CState,CZip)
  226. values (5, 'Kein', 'Tsung', 4358789, 'ktsung@gmail.com', '32 Jade Lane', 'Abraham', 'UT', 84635);
  227.  
  228. insert into customer(CustomerID, CFName,CLName,CPhone,CEmail, CAddress, CCity, CState,CZip)
  229. values (6, 'Jolly', 'Moore', 4355878, 'jmoore@aol.com', '5009 Duck Ave', 'Arches', 'UT', 84532);
  230.  
  231. insert into customer(CustomerID, CFName,CLName,CPhone,CEmail, CAddress, CCity, CState,CZip)
  232. values (7, 'Keith', 'Lim', 8011236, 'klim@yahoo.com', '5 Luke street', 'Saratoga', 'UT', 84092);
  233.  
  234. insert into customer(CustomerID, CFName,CLName,CPhone,CEmail, CAddress, CCity, CState,CZip)
  235. values (8, 'Jim', 'Myer', 4351245, 'jmyer@yahoo.com', '29 Winter Street', 'Bountiful', 'UT', 84010);
  236.  
  237. insert into customer(CustomerID, CFName,CLName,CPhone,CEmail, CAddress, CCity, CState,CZip)
  238. values (9, 'Ryan', 'Johnson', 8013546, 'rjohnson@yahoo.com', '8001 Lame Street', 'BryceCanyon','UT', 84764);
  239.  
  240. insert into customer(CustomerID, CFName,CLName,CPhone,CEmail, CAddress, CCity, CState,CZip)
  241. values (10, 'Jade', 'Rodrick', 4357895, 'jrodrick@yahoo.com', '432 SummerStreet', 'Brookside', 'UT', 84782);
  242.  
  243.  
  244. set IDENTITY_INSERT customer off
  245.  
  246.  
  247.  
  248. insert into employee
  249. values ('Chloe', 'Emily', 4351236, 'cemily@yahoo.com','44 Beaver Ln', 'Millard', 'UT', 84007);
  250.  
  251. insert into employee
  252. values ('Lucas', 'Noah', 8014351, 'lnoah@yahoo.com', '1 Wassach Ave','Garfield', 'UT', 84006);
  253.  
  254. insert into employee
  255. values ('Jean', 'Lau', 8014235, 'jlau@yahoo.com','2089 Piute Dr', 'Emery', 'UT', 89067);
  256.  
  257. insert into employee
  258. values ('Zoe', 'Mason', 8014235, 'zmason@yahoo.com','90 Sev St', 'Emery', 'UT', 89067);
  259.  
  260. insert into employee
  261. values ('Madelyn', 'Liam', 8011245, 'mliam@yahoo.com','908 Springs Dr', 'Emery', 'UT', 89067);
  262.  
  263. insert into employee
  264. values ('Arianna', 'Johnson', 8014256, 'ajohns@yahoo.com','3321 Box St', 'Emery', 'UT', 89067);
  265.  
  266. insert into employee
  267. values ('Scarlett', 'Brooklyn', 8014235, 'sbrook@yahoo.com','999 Morgan Ave', 'Summit', 'UT', 89067);
  268.  
  269. insert into employee
  270. values ('Keira', 'Viole', 8014235, 'kviol@yahoo.com','7652 Cache Rd', 'Wayne', 'UT', 89067);
  271.  
  272. insert into employee
  273. values ('Johnson', 'Adele', 8014335, 'aj1876@yahoo.com','960 StJohns Pl', 'Summit', 'UT', 89067);
  274.  
  275. insert into employee
  276. values ('Crane', 'Martin', 8015235, 'martrt@yahoo.com','190 ElliotBay', 'Wayne', 'UT', 89067);
  277.  
  278.  
  279.  
  280. insert into Boat
  281. values ('Isuzu',1999, 2, 22, 20000.00, 19000.00 , 'Square',1 );
  282.  
  283. insert into Boat
  284. values ('Kelvin', 2000, 1, 15, 13000.00, 120000.00, 'Square', 2);
  285.  
  286. insert into boat
  287. values ('Mercury', 2001, 1, 19, 12000.00, 11000.00,'Honda', 3);
  288.  
  289. insert into boat
  290. values ('Yarow', 2011, 2, 20, 81000.00, 60000.00, 'Z1 boats', 4);
  291.  
  292. insert into boat
  293. values ('Kawasaki', 2016, 1, 20, 81000.00, 60000.00, 'Kawasaki', 5);
  294.  
  295. insert into boat
  296. values ('Kelvin', 2004, 1, 20, 35000.00, 30000.00, 'Z1 boats', 6);
  297.  
  298. insert into boat
  299. values ('Yarow', 2016, 2, 20, 120000.00, 100000.00, 'Honda', 7);
  300.  
  301. insert into boat
  302. values ('Yarow', 2007, 1, 20, 20000.00, 15000.00, 'Z1 boats', 8);
  303.  
  304. insert into boat
  305. values ('Yarow', 2016, 1, 20, 90000.00, 80000.00, 'Square', 9);
  306.  
  307. insert into boat
  308. values ('Mercury', 2003, 1, 20, 34000.00, 30000.00, 'Z1 boats', 10);
  309.  
  310.  
  311. select * from boat
  312.  
  313. insert into Engine
  314. values ('Honda', 2000,'outdrive',7000.00,6900.00, 'Honda', 1);
  315.  
  316. insert into Engine
  317. values ('Honda', 2003,'non outdrive',10000.00,9600.00, 'Honda', 1);
  318.  
  319. insert into Engine
  320. values ('Honda', 2010,'outdrive',8200.00,8000.00, 'Honda', 2);
  321.  
  322. insert into Engine
  323. values ('Honda', 2005,'outdrive',3500.00,3200.00, 'Honda', 3);
  324.  
  325. insert into Engine
  326. values ('Honda', 2012,'non outdrive',7900.00,7700.00, 'Honda', 4);
  327.  
  328. insert into Engine
  329. values ('Honda', 2001,'outdrive',5400.00,5200.00, 'Honda', 4);
  330.  
  331. insert into Engine
  332. values ('Honda', 2015,'non outdrive',9000.00,8700.00, 'Honda', 5);
  333.  
  334. insert into Engine
  335. values ('Honda', 2001,'outdrive',7900.00, 7600.00, 'Honda', 6);
  336.  
  337. insert into Engine
  338. values ('Honda', 2007,'outdrive',6000.00,5900.00, 'Honda', 7);
  339.  
  340. insert into Engine
  341. values ('Honda', 2014,'non outdrive',5400.00,5000.00, 'Honda', 7);
  342.  
  343. insert into Engine
  344. values ('Honda', 2000,'non outdrive',7000.00,6600.00, 'Honda', 8);
  345.  
  346. insert into Engine
  347. values ('Honda', 2004,'outdrive',6000.00,5900.00, 'Honda', 9);
  348.  
  349. insert into Engine
  350. values ('Honda', 2000,'outdrive',7600.00,7200.00, 'Honda', 10);
  351.  
  352.  
  353. select *
  354. from Employee
  355.  
  356. insert into sale
  357. values ('2016-12-02', '2016-12-06', 500.00,.10,20.00,528.00, 6, 5);
  358.  
  359. insert into sale
  360. values ('2016-01-12', '2016-01-25', 400.00,.10,10.00, 429.00, 10, 4);
  361.  
  362. insert into sale
  363. values ('2016-01-16', '2016-01-25', 300.00,.10,10.00, 319.00, 10, 2);
  364.  
  365. insert into sale
  366. values ('2016-02-04', '2016-02-09', 150.00,.10, 5.00 ,148.5, 8, 1);
  367.  
  368. insert into sale
  369. values ('2016-12-01', '2016-12-05', 440.00,.10, 50.00 , 429.00 , 7, 3);
  370.  
  371. insert into sale
  372. values ('2016-02-15', '2016-02-20', 3524,.10, 504.00 ,3050.20 , 4, 6);
  373.  
  374. insert into sale
  375. values ('2016-02-19', '2016-02-23', 1025.00,.10, 55.00 , 1067, 6, 7);
  376.  
  377. insert into sale
  378. values ('2016-03-03', '2016-03-07', 400.00,.1 ,20.00 , 14.00, 6, 8);
  379.  
  380. insert into sale
  381. values ('2016-03-09', '2016-03-15', 29.00,.10, 4.00 , 27.5, 5, 9);
  382.  
  383. insert into sale
  384. values ('2016-03-20', '2016-03-25', 7500.00,.10, 7000.00 ,7700.00 , 4, 10);
  385.  
  386. select * from Sale
  387. order b
  388.  
  389. insert into SaleItem
  390. values(1, 480.00, 1,11)
  391.  
  392. insert into SaleItem
  393. values(1, 390.00 , 2, 12)
  394.  
  395. insert into SaleItem
  396. values(1, 290.00, 3, 13)
  397.  
  398. insert into SaleItem
  399. values(1, 190.00,4,15)
  400.  
  401. insert into SaleItem
  402. values(1, 45.00 , 5,14)
  403.  
  404. insert into SaleItem
  405. values(1, 20.00, 6,17)
  406.  
  407. insert into SaleItem
  408. values(1, 20.00 ,7,16)
  409.  
  410. insert into SaleItem
  411. values(1, 380.00, 8,18)
  412.  
  413. insert into SaleItem
  414. values(1, 80.00,9,15)
  415.  
  416. insert into SaleItem
  417. values(1, 90.00,10,14)
  418.  
  419. insert into SaleItem
  420. values(1, 3000.00,11 ,16)
  421.  
  422. insert into SaleItem
  423. values(1, 200.00, 12,15)
  424.  
  425. insert into SaleItem
  426. values(1, 950.00,13,17)
  427.  
  428. insert into SaleItem
  429. values(1, 7000.00, 14,20)
  430.  
  431. insert into SaleItem
  432. values(1, 25.00, 15,19)
  433.  
  434. select CFName +' '+ CLName as 'Customers Who Bought Propellers in February'
  435. from Sale as S
  436. join customer as C on c.CustomerID = s.CustomerID
  437. join SaleItem as SI on SI.SaleID = S.SaleId
  438. join Product as P on P.ProductID = SI.ProductID
  439.  
  440. where SaleDate like '2016-02%' and CategoryName = 'Propeller'
  441.  
  442. select * from Sale
  443. order by SaleDate
  444.  
  445. select CategoryName as 'Parts sold on February 20th'
  446. from Sale as S
  447. join SaleItem as SI on S.SaleId = SI.SaleID
  448. join Product as P on P.ProductID = SI.ProductID
  449. where SaleDate = '2016-02-15'
  450.  
  451. select top 1 PListPice as Price, MAnufName + ' ' + CategoryName as 'Steering Wheel'
  452. from product
  453. where CategoryName = 'Steering Wheel'
  454. order by PListPice desc
  455.  
  456. select count(SIQuantity) as 'Parts Sold', P.MAnufName as Manufacturer
  457. from Manufacturer as M
  458. join Product as P on M.ManufName = P.MAnufName
  459. join SaleItem as SI on SI.ProductID = P.ProductID
  460. group by P.ManufName
  461. order by 'Parts Sold' desc
  462.  
  463. select * from customer
  464. select * from Product
  465.  
  466. select count(CategoryName) as Parts, MAnufName
  467. from Product
  468. where CategoryName = 'Gasket'
  469. group by MAnufName
  470. order by Parts desc
  471.  
  472. select e.EmployeeID, efname + ' ' + elname as Name, sum(total) as 'Total Sales'
  473. from Employee as E
  474. join Sale as S on E.EmployeeID = S.EmployeeID
  475. group by e.EmployeeID, EFName, ELName
  476. order by 'Total Sales' desc
  477.  
  478. select SaleID, subtotal + (subtotal *.06) as 'Total Value With Tax'
  479. from Sale
  480.  
  481. select * from SaleItem
  482.  
  483. update SaleItem
  484. set SIQuantity= 2, SIExtended = 290.00, ProductID = 3, SaleID = 22
  485. where SaleItemID = 3
  486.  
  487. Insert into Product
  488. values ( 16, 'Good', 100.00,'Honda', 'Steering Wheel');
  489.  
  490.  
  491. select ManufName, CategoryName
  492. from product
  493.  
  494. Select SIExtended
  495. from SaleItem
  496. Select Discount
  497. from Sale
  498.  
  499. select CLName + ' '+ CFName as Person
  500. from customer
  501. union
  502. select EFName + ' ' + ELName
  503. from Employee
  504.  
  505.  
  506.  
  507. select * from Sale
  508. select * from SaleItem
  509.  
  510. select SaleID, Total
  511. from Sale
  512. where Discount <
  513. (select avg(Discount)
  514. from Sale
  515. )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement