fork download
  1. CREATE TABLE Vehicle_Type
  2. (
  3. TypeID char (3) not null PRIMARY KEY,
  4. [Description] varchar (100) not null
  5. );
  6. GO
  7.  
  8. INSERT into Vehicle_Type VALUES
  9. ('TT','Tracter Trailor'),
  10. ('ST','Semi-Tracter Trailor');
  11. GO
  12.  
  13. SELECT* from Vehicle_Type
  14. GO
  15.  
  16. CREATE TABLE Maintenance_Code
  17. (
  18. Maintenance_Type_ID varchar (5) not null PRIMARY KEY,
  19. [Description] varchar (100) not null
  20. );
  21. GO
  22.  
  23. INSERT INTO Maintenance_Code VALUES
  24. ('MOC4','Oil Change'),
  25. ('MHR9','Hose Replacement'),
  26. ('MTR5','Tire Ratation'),
  27. ('MAB8','Alignment & Balancing Tires');
  28. GO
  29.  
  30. SELECT * from Maintenance_Code
  31. GO
  32.  
  33. CREATE TABLE Maintenance_Descriptions
  34. (
  35. Maintenance_Type_ID varchar (5) not null PRIMARY KEY
  36. FOREIGN KEY REFERENCES Maintenance_Code(Maintenance_Type_ID),
  37. Level_Code varchar (10) not null,
  38. Average_Hours_Required varchar (5) not null,
  39. Days_Between_Recommended_Maintenance int not null,
  40. Maximum_Days_Between_Maintenance int not null
  41. );
  42. GO
  43.  
  44. INSERT INTO Maintenance_Descriptions VALUES
  45. ('MOC4','LvL1','1.25','90','120'),
  46. ('MHR9','LvL2','3.5','180','200'),
  47. ('MTR5','LvL3','2.0','180','210'),
  48. ('MAB8','LvL4','5.30','180','210');
  49. GO
  50.  
  51. SELECT* from Maintenance_Descriptions
  52. GO
  53.  
  54. CREATE TABLE Vehicles
  55. (
  56. VIN_Number varchar (17) not null PRIMARY KEY,
  57. TypeID char (3) not null
  58. FOREIGN KEY REFERENCES Vehicle_Type(TypeID),
  59. Class_Code varchar (6) not null,
  60. Put_Into_Service_Date date not null,
  61. Gross_Weight varchar (7) not null,
  62. Milleage varchar (9) not null,
  63. Purchase_Price varchar (9) not null,
  64. Accumulated_Depreciation varchar (9) not null,
  65. Taken_Out_Of_Service date,
  66. Capacity varchar (20) not null
  67. );
  68. GO
  69.  
  70. INSERT INTO Vehicles VALUES
  71. ('2HNYD28478H501589','ST','CL7GVW','2000-04-02','58,510','30,004','$65,350','$23,314','2010-04-30','45,000 53X13.6X102'),
  72. ('2T1FF28PX1C539447','TT','CL5GVW','2001-05-29','47,850','89,347','$57,950','$17,964','2012-06-01','97,000 55X15.25X102');
  73. GO
  74.  
  75. SELECT * from Vehicles
  76. GO
  77.  
  78. CREATE TABLE Vehicle_Maintenance
  79. (
  80. VIN_Number varchar (17) not null,
  81. PartsID varchar (10) not null,
  82. Maintenance_Type_ID varchar (5) not null,
  83. Put_Into_Service_Date date not null,
  84. Last_Maintenance_Date date not null,
  85. Next_Scheduled_Maintenance date not null,
  86. Under_Warranty_Flag char (1) not null
  87. );
  88. GO
  89.  
  90. INSERT INTO Vehicle_Maintenance VALUES
  91. ('2HNYD28478H501589','QH1300AS','MOC4','2011-06-15','2012-01-31','2013-01-31','Y'),
  92. ('2T1FF28PX1C539447','1590002','MHR9','2011-02-22','2012-03-25','2012-12-01','Y');
  93. GO
  94.  
  95. select * from Vehicle_Maintenance;
  96. GO
  97.  
  98. CREATE TABLE Tire_Maintenance
  99. (
  100. Barcode varchar (17) not null PRIMARY KEY,
  101. Maintenance_Type_ID varchar (5) not null
  102. FOREIGN KEY REFERENCES Maintenance_Code(Maintenance_Type_ID),
  103. TypeID char (3) not null
  104. FOREIGN KEY REFERENCES Vehicle_Type(TypeID),
  105. Manufacture_ID varchar (15) not null,
  106. Put_Into_Service_Date date not null,
  107. Rotated_Scheduled_Date date not null,
  108. Last_Rotated_Date date not null,
  109. Disposal_Date date not null
  110. );
  111. GO
  112.  
  113. INSERT INTO Tire_Maintenance VALUES
  114. ('79008 40228','MTR5','ST','GoodYr2002','2006-10-06','2012-08-10','2012-05-12','2012-05-17'),
  115. ('96018 13820','MAB8','TT','Yukon2010','2009-07-02','2012-05-31','2012-02-28','2012-02-10');
  116. GO
  117.  
  118. SELECT * from Tire_Maintenance
  119. GO
  120.  
  121. CREATE TABLE Maintenance_Work_Order
  122. (
  123. Work_Order_ID varchar (5) not null PRIMARY KEY,
  124. VIN_Number varchar (17) not null
  125. FOREIGN KEY REFERENCES Vehicles (VIN_Number),
  126. Maintenance_Type_ID varchar (5) not null
  127. FOREIGN KEY REFERENCES Maintenance_Code(Maintenance_Type_ID),
  128. Assignment_To varchar (9) not null,
  129. Date_Started date not null,
  130. Date_Completed date not null,
  131. [Hours] varchar (7) not null
  132. );
  133. GO
  134.  
  135.  
  136. INSERT INTO Maintenance_Work_Order VALUES
  137. ('H1000','2HNYD28478H501589','MOC4','Blue Team','2012-05-09','2012-05-11','3.0'),
  138. ('H1001','2T1FF28PX1C539447','MHR9','Black Team','2012-04-28','2012-04-30','2.75');
  139. GO
  140.  
  141. select * from Maintenance_Work_Order
  142. GO
  143.  
  144. CREATE TABLE Vendors
  145. (
  146. Vendor_ID varchar (7) not null PRIMARY KEY,
  147. Name varchar (10) not null,
  148. Order_Address varchar (5) not null,
  149. Order_Street varchar (10) not null,
  150. Order_City varchar (15) not null,
  151. Order_State char (2) not null,
  152. Order_Zip int not null,
  153. Order_Contact char (15) not null,
  154. Order_Phone_Number varchar (15) not null,
  155. Order_Fax_Number varchar (15),
  156. Billing_Address varchar (5) not null,
  157. Billing_Street varchar (10) not null,
  158. Billing_City varchar (15) not null,
  159. Billing_State char (2) not null,
  160. Billing_Zip int not null,
  161. Billing_Contact char (15) not null,
  162. Billing_Phone_Number varchar (15) not null,
  163. Billing_Fax_Number varchar (15) not null
  164. );
  165. GO
  166.  
  167.  
  168. INSERT into Vendors VALUES
  169. ('SAP8','Sears','5178','Pearl Road','Cleveland','OH','44129','Mary Kay','(216)351-3279','(216)351-7500','6600','Bessemer Avenue','Cleveland','OH','44127','John Smith','(216)341-7140','(216)429-3523'),
  170. ('NA00','NAPA','3141','Superior Avenue','Cleveland','OH','44114','Andrew Linder','(216)771-1515','(216)398-9800','6600','Bessemer Avenue','Cleveland','OH','44127','John Smith','(216)341-7140','(216)429-3523')
  171. GO
  172.  
  173. SELECT* from Vendors
  174. GO
  175.  
Runtime error #stdin #stdout 0s 3008KB
stdin
select * from Names WHERE Fname = 'John' AND Lname = 'Doe';
stdout
Standard output is empty