Advertisement
Guest User

Untitled

a guest
May 21st, 2019
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.67 KB | None | 0 0
  1. -- create the tables
  2. CREATE TABLE customers (
  3. customer_id INTEGER
  4. CONSTRAINT customers_pk PRIMARY KEY,
  5. first_name VARCHAR2(10) NOT NULL,
  6. last_name VARCHAR2(10) NOT NULL,
  7. dob DATE,
  8. phone VARCHAR2(12)
  9. );
  10.  
  11. CREATE TABLE product_types (
  12. product_type_id INTEGER
  13. CONSTRAINT product_types_pk PRIMARY KEY,
  14. name VARCHAR2(10) NOT NULL
  15. );
  16.  
  17. CREATE TABLE products (
  18. product_id INTEGER
  19. CONSTRAINT products_pk PRIMARY KEY,
  20. product_type_id INTEGER
  21. CONSTRAINT products_fk_product_types
  22. REFERENCES product_types(product_type_id),
  23. name VARCHAR2(30) NOT NULL,
  24. description VARCHAR2(50),
  25. price NUMBER(5, 2)
  26. );
  27.  
  28. CREATE TABLE purchases (
  29. product_id INTEGER
  30. CONSTRAINT purchases_fk_products
  31. REFERENCES products(product_id),
  32. customer_id INTEGER
  33. CONSTRAINT purchases_fk_customers
  34. REFERENCES customers(customer_id),
  35. quantity INTEGER NOT NULL,
  36. CONSTRAINT purchases_pk PRIMARY KEY (product_id, customer_id)
  37. );
  38.  
  39. CREATE TABLE employees (
  40. employee_id INTEGER
  41. CONSTRAINT employees_pk PRIMARY KEY,
  42. manager_id INTEGER,
  43. first_name VARCHAR2(10) NOT NULL,
  44. last_name VARCHAR2(10) NOT NULL,
  45. title VARCHAR2(20),
  46. salary NUMBER(6, 0)
  47. );
  48.  
  49. CREATE TABLE salary_grades (
  50. salary_grade_id INTEGER
  51. CONSTRAINT salary_grade_pk PRIMARY KEY,
  52. low_salary NUMBER(6, 0),
  53. high_salary NUMBER(6, 0)
  54. );
  55.  
  56.  
  57.  
  58.  
  59.  
  60. -- insert sample data into customers table
  61.  
  62. INSERT INTO customers (
  63. customer_id, first_name, last_name, dob, phone
  64. ) VALUES (
  65. 1, 'Jan', 'Nikiel', '1965/01/01', '800-555-1211'
  66. );
  67.  
  68. INSERT INTO customers (
  69. customer_id, first_name, last_name, dob, phone
  70. ) VALUES (
  71. 2, 'Lidia', 'Stal', '1968/02/05', '800-555-1212'
  72. );
  73.  
  74. INSERT INTO customers (
  75. customer_id, first_name, last_name, dob, phone
  76. ) VALUES (
  77. 3, 'Stefan', 'Br�z', '1971/03/16', '800-555-1213'
  78. );
  79.  
  80. INSERT INTO customers (
  81. customer_id, first_name, last_name, dob, phone
  82. ) VALUES (
  83. 4, 'Gra�yna', 'Cynk', NULL, '800-555-1214'
  84. );
  85.  
  86. INSERT INTO customers (
  87. customer_id, first_name, last_name, dob, phone
  88. ) VALUES (
  89. 5, 'Jadwiga', 'Mosi�dz', '1970/05/20', NULL
  90. );
  91.  
  92.  
  93. -- insert sample data into product_types table
  94.  
  95. INSERT INTO product_types (
  96. product_type_id, name
  97. ) VALUES (
  98. 1, 'Ksi��ka'
  99. );
  100.  
  101. INSERT INTO product_types (
  102. product_type_id, name
  103. ) VALUES (
  104. 2, 'VHS'
  105. );
  106.  
  107. INSERT INTO product_types (
  108. product_type_id, name
  109. ) VALUES (
  110. 3, 'DVD'
  111. );
  112.  
  113. INSERT INTO product_types (
  114. product_type_id, name
  115. ) VALUES (
  116. 4, 'CD'
  117. );
  118.  
  119. INSERT INTO product_types (
  120. product_type_id, name
  121. ) VALUES (
  122. 5, 'Czasopismo'
  123. );
  124.  
  125. -- commit the transaction
  126. COMMIT;
  127.  
  128. -- insert sample data into products table
  129.  
  130. INSERT INTO products (
  131. product_id, product_type_id, name, description, price
  132. ) VALUES (
  133. 1, 1, 'Nauka wsp�?czesna', 'Opis wsp�?czesnej nauki', 19.95
  134. );
  135.  
  136. INSERT INTO products (
  137. product_id, product_type_id, name, description, price
  138. ) VALUES (
  139. 2, 1, 'Chemia', 'Wprowadzenie do chemii', 30.00
  140. );
  141.  
  142. INSERT INTO products (
  143. product_id, product_type_id, name, description, price
  144. ) VALUES (
  145. 3, 2, 'Supernowa', 'Eksplozja gwiazdy', 25.99
  146. );
  147.  
  148. INSERT INTO products (
  149. product_id, product_type_id, name, description, price
  150. ) VALUES (
  151. 4, 2, 'Wojny czo?g�w', 'Film akcji o nadchodz�cej wojnie', 13.95
  152. );
  153.  
  154. INSERT INTO products (
  155. product_id, product_type_id, name, description, price
  156. ) VALUES (
  157. 5, 2, 'Z Files', 'Serial o tajemniczych zjawiskach', 49.99
  158. );
  159.  
  160. INSERT INTO products (
  161. product_id, product_type_id, name, description, price
  162. ) VALUES (
  163. 6, 2, '2412: Powr�t', 'Powr�t obcych', 14.95
  164. );
  165.  
  166. INSERT INTO products (
  167. product_id, product_type_id, name, description, price
  168. )
  169. VALUES (
  170. 7, 3, 'Space Force 9', 'Przygody bohater�w', 13.49
  171. );
  172.  
  173. INSERT INTO products (
  174. product_id, product_type_id, name, description, price
  175. ) VALUES (
  176. 8, 3, 'Z innej planety', 'Obcy z innej planety l�duje na Ziemi', 12.99
  177. );
  178.  
  179. INSERT INTO products (
  180. product_id, product_type_id, name, description, price
  181. ) VALUES (
  182. 9, 4, 'Muzyka klasyczna', 'Nalepsze dzie?a muzyki klasycznej', 10.99
  183. );
  184.  
  185. INSERT INTO products (
  186. product_id, product_type_id, name, description, price
  187. ) VALUES (
  188. 10, 4, 'Pop 3', 'Najlepsze utwory popowe', 15.99
  189. );
  190.  
  191. INSERT INTO products (
  192. product_id, product_type_id, name, description, price
  193. ) VALUES (
  194. 11, 4, 'Tw�rczy wrzask', 'Album debiutancki', 14.99
  195. );
  196.  
  197. INSERT INTO products (
  198. product_id, product_type_id, name, description, price
  199. ) VALUES (
  200. 12, NULL, 'Pierwsza linia', 'Najwi�ksze hity', 13.49
  201. );
  202.  
  203. -- commit the transaction
  204. COMMIT;
  205.  
  206. -- insert sample data into purchases table
  207.  
  208. INSERT INTO purchases (
  209. product_id, customer_id, quantity
  210. ) VALUES (
  211. 1, 1, 1
  212. );
  213.  
  214. INSERT INTO purchases (
  215. product_id, customer_id, quantity
  216. ) VALUES (
  217. 2, 1, 3
  218. );
  219.  
  220. INSERT INTO purchases (
  221. product_id, customer_id, quantity
  222. ) VALUES (
  223. 1, 4, 1
  224. );
  225.  
  226. INSERT INTO purchases (
  227. product_id, customer_id, quantity
  228. ) VALUES (
  229. 2, 2, 1
  230. );
  231.  
  232. INSERT INTO purchases (
  233. product_id, customer_id, quantity
  234. ) VALUES (
  235. 1, 3, 1
  236. );
  237.  
  238. INSERT INTO purchases (
  239. product_id, customer_id, quantity
  240. ) VALUES (
  241. 1, 2, 2
  242. );
  243.  
  244. INSERT INTO purchases (
  245. product_id, customer_id, quantity
  246. ) VALUES (
  247. 2, 3, 1
  248. );
  249.  
  250. INSERT INTO purchases (
  251. product_id, customer_id, quantity
  252. ) VALUES (
  253. 2, 4, 1
  254. );
  255.  
  256. INSERT INTO purchases (
  257. product_id, customer_id, quantity
  258. ) VALUES (
  259. 3, 3, 1
  260. );
  261.  
  262. -- commit the transaction
  263. COMMIT;
  264.  
  265. -- insert sample data into employees table
  266.  
  267. INSERT INTO employees (
  268. employee_id, manager_id, first_name, last_name, title, salary
  269. ) VALUES (
  270. 1, NULL, 'Jan', 'Kowalski', 'CEO', 800000
  271. );
  272.  
  273. INSERT INTO employees (
  274. employee_id, manager_id, first_name, last_name, title, salary
  275. ) VALUES (
  276. 2, 1, 'Roman', 'Jo?wierz', 'Kierownik sprzeda�y', 600000
  277. );
  278.  
  279. INSERT INTO employees (
  280. employee_id, manager_id, first_name, last_name, title, salary
  281. ) VALUES (
  282. 3, 2, 'Fryderyk', 'Helc', 'Sprzedawca', 150000
  283. );
  284.  
  285. INSERT INTO employees (
  286. employee_id, manager_id, first_name, last_name, title, salary
  287. ) VALUES (
  288. 4, 2, 'Zofia', 'Nowak', 'Sprzedawca', 500000
  289. );
  290.  
  291. -- commit the transaction
  292. COMMIT;
  293.  
  294. -- insert sample data into salary_grade table
  295.  
  296. INSERT INTO salary_grades (
  297. salary_grade_id, low_salary, high_salary
  298. ) VALUES (
  299. 1, 1, 250000
  300. );
  301.  
  302. INSERT INTO salary_grades (
  303. salary_grade_id, low_salary, high_salary
  304. ) VALUES (
  305. 2, 250001, 500000
  306. );
  307.  
  308. INSERT INTO salary_grades (
  309. salary_grade_id, low_salary, high_salary
  310. ) VALUES (
  311. 3, 500001, 750000
  312. );
  313.  
  314. INSERT INTO salary_grades (
  315. salary_grade_id, low_salary, high_salary
  316. ) VALUES (
  317. 4, 750001, 999999
  318. );
  319.  
  320. -- commit the transaction
  321. COMMIT;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement