Advertisement
alexarcan

dbd_export_lab5(not mine)

Oct 31st, 2016
288
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.57 KB | None | 0 0
  1. --------------------------------------------------------
  2. -- File created - luni-octombrie-31-2016
  3. --------------------------------------------------------
  4. --------------------------------------------------------
  5. -- DDL for Table CATEGORIES
  6. --------------------------------------------------------
  7.  
  8. CREATE TABLE "CATEGORIES"
  9. ( "ID_CATEGORY" NUMBER(20,0),
  10. "NAME" VARCHAR2(20 BYTE),
  11. "ID_PRODUCT" NUMBER(20,0),
  12. "ID_PARENTCATEGORY" NUMBER(10,0)
  13. ) ;
  14. /
  15. --------------------------------------------------------
  16. -- DDL for Table CLIENTS
  17. --------------------------------------------------------
  18.  
  19. CREATE TABLE "CLIENTS"
  20. ( "ID_CLIENT" NUMBER(20,0),
  21. "NAME" VARCHAR2(20 BYTE)
  22. ) ;
  23. /
  24. --------------------------------------------------------
  25. -- DDL for Table ORDERS
  26. --------------------------------------------------------
  27.  
  28. CREATE TABLE "ORDERS"
  29. ( "ID_ORDER" NUMBER(20,0),
  30. "CONFIRMED " VARCHAR2(20 BYTE),
  31. "ID_CLIENT" NUMBER(20,0),
  32. "ID_PRODUCT" NUMBER(20,0)
  33. ) ;
  34. /
  35. --------------------------------------------------------
  36. -- DDL for Table PRODUCTS
  37. --------------------------------------------------------
  38.  
  39. CREATE TABLE "PRODUCTS"
  40. ( "ID" NUMBER,
  41. "NAME" VARCHAR2(20 BYTE)
  42. ) ;
  43. /
  44. --------------------------------------------------------
  45. -- DDL for Table PROPERTIES
  46. --------------------------------------------------------
  47.  
  48. CREATE TABLE "PROPERTIES"
  49. ( "ID_PROPERTIES" NUMBER,
  50. "COLOR" VARCHAR2(20 BYTE),
  51. "WEIGHT" NUMBER,
  52. "PRICE" NUMBER(7,0),
  53. "ID_PRODUCT" NUMBER(20,0)
  54. ) ;
  55. /
  56. --------------------------------------------------------
  57. -- DDL for View A
  58. --------------------------------------------------------
  59.  
  60. CREATE OR REPLACE FORCE VIEW "A" ("PRODUCT_NAME", "CLIENT_NAME") AS
  61. SELECT p1.NAME AS PRODUCT_NAME, c1.NAME AS CLIENT_NAME
  62. from PRODUCTS p1, CATEGORIES c1,PROPERTIES pr
  63. where PRICE > 4000 AND p1.ID=c1.ID_PRODUCT AND p1.ID=pr.ID_PRODUCT;
  64. /
  65. --------------------------------------------------------
  66. -- DDL for View B
  67. --------------------------------------------------------
  68.  
  69. CREATE OR REPLACE FORCE VIEW "B" ("NAME", "ORDEREDPRODUCTS") AS
  70. SELECT c1.NAME, (select count(*) FROM orders o where o.ID_CLIENT=c1.ID_CLIENT) as ORDEREDPRODUCTS From clients c1;
  71. /
  72. --------------------------------------------------------
  73. -- DDL for View C
  74. --------------------------------------------------------
  75.  
  76. CREATE OR REPLACE FORCE VIEW "C" ("NAME", "NUMBEROFCATEGORIES") AS
  77. SELECT DISTINCT c1.NAME, ct1.ID_CATEGORY AS NUMBEROFCATEGORIES from clients c1, products p1, categories ct1, orders o1
  78. where c1.ID_CLIENT=o1.ID_CLIENT and ct1.ID_CATEGORY = (select count(ct2.ID_PRODUCT) from categories ct2
  79. where ct2.ID_PRODUCT=o1.ID_PRODUCT) ORDER BY ct1.ID_CATEGORY DESC;
  80. /
  81. --------------------------------------------------------
  82. -- DDL for View D
  83. --------------------------------------------------------
  84.  
  85. CREATE OR REPLACE FORCE VIEW "D" ("NAME", "TOTALPRICEOFPRODUCTS") AS
  86. select DISTINCT c1.name, avg(pr1.PRICE) as totalPriceOfProducts from clients c1, orders o1, properties pr1
  87. where pr1.ID_PRODUCT=o1.ID_PRODUCT and c1.ID_CLIENT=o1.ID_CLIENT GROUP BY c1.name order by avg(pr1.PRICE) desc;
  88. /
  89. REM INSERTING into CATEGORIES
  90. SET DEFINE OFF;
  91. Insert into CATEGORIES (ID_CATEGORY,NAME,ID_PRODUCT,ID_PARENTCATEGORY) values ('1','Mancare','1',null);
  92. Insert into CATEGORIES (ID_CATEGORY,NAME,ID_PRODUCT,ID_PARENTCATEGORY) values ('2','Piese','6',null);
  93. Insert into CATEGORIES (ID_CATEGORY,NAME,ID_PRODUCT,ID_PARENTCATEGORY) values ('3','Lactate','1','1');
  94. Insert into CATEGORIES (ID_CATEGORY,NAME,ID_PRODUCT,ID_PARENTCATEGORY) values ('4','Carne','2','1');
  95. Insert into CATEGORIES (ID_CATEGORY,NAME,ID_PRODUCT,ID_PARENTCATEGORY) values ('5','Lactate','3','1');
  96. Insert into CATEGORIES (ID_CATEGORY,NAME,ID_PRODUCT,ID_PARENTCATEGORY) values ('6','Lactate','4','1');
  97. Insert into CATEGORIES (ID_CATEGORY,NAME,ID_PRODUCT,ID_PARENTCATEGORY) values ('7','Carne','5','1');
  98. Insert into CATEGORIES (ID_CATEGORY,NAME,ID_PRODUCT,ID_PARENTCATEGORY) values ('8','Mancare','2',null);
  99. Insert into CATEGORIES (ID_CATEGORY,NAME,ID_PRODUCT,ID_PARENTCATEGORY) values ('9','Mancare','3',null);
  100. Insert into CATEGORIES (ID_CATEGORY,NAME,ID_PRODUCT,ID_PARENTCATEGORY) values ('10','Mancare','4',null);
  101. Insert into CATEGORIES (ID_CATEGORY,NAME,ID_PRODUCT,ID_PARENTCATEGORY) values ('11','Mancare','5',null);
  102. REM INSERTING into CLIENTS
  103. SET DEFINE OFF;
  104. Insert into CLIENTS (ID_CLIENT,NAME) values ('1','David');
  105. Insert into CLIENTS (ID_CLIENT,NAME) values ('2','Nick');
  106. Insert into CLIENTS (ID_CLIENT,NAME) values ('3','Cioti');
  107. Insert into CLIENTS (ID_CLIENT,NAME) values ('4','Alex');
  108. REM INSERTING into ORDERS
  109. SET DEFINE OFF;
  110. Insert into ORDERS (ID_ORDER,CONFIRMED ,ID_CLIENT,ID_PRODUCT) values ('1','YES','1','1');
  111. Insert into ORDERS (ID_ORDER,CONFIRMED ,ID_CLIENT,ID_PRODUCT) values ('2','YES','2','6');
  112. Insert into ORDERS (ID_ORDER,CONFIRMED ,ID_CLIENT,ID_PRODUCT) values ('3','YES','3','3');
  113. Insert into ORDERS (ID_ORDER,CONFIRMED ,ID_CLIENT,ID_PRODUCT) values ('4','NO','1','4');
  114. Insert into ORDERS (ID_ORDER,CONFIRMED ,ID_CLIENT,ID_PRODUCT) values ('5','YES','1','2');
  115. REM INSERTING into PRODUCTS
  116. SET DEFINE OFF;
  117. Insert into PRODUCTS (ID,NAME) values ('1','Lapte
  118. ');
  119. Insert into PRODUCTS (ID,NAME) values ('2','Salam');
  120. Insert into PRODUCTS (ID,NAME) values ('3','Branza');
  121. Insert into PRODUCTS (ID,NAME) values ('4','Cascaval');
  122. Insert into PRODUCTS (ID,NAME) values ('5','Sunca');
  123. Insert into PRODUCTS (ID,NAME) values ('6','Jante');
  124. REM INSERTING into PROPERTIES
  125. SET DEFINE OFF;
  126. Insert into PROPERTIES (ID_PROPERTIES,COLOR,WEIGHT,PRICE,ID_PRODUCT) values ('1','red','1400','2900','1');
  127. Insert into PROPERTIES (ID_PROPERTIES,COLOR,WEIGHT,PRICE,ID_PRODUCT) values ('2','black','1500','3450','2');
  128. Insert into PROPERTIES (ID_PROPERTIES,COLOR,WEIGHT,PRICE,ID_PRODUCT) values ('3','white','1200','8000','3');
  129. Insert into PROPERTIES (ID_PROPERTIES,COLOR,WEIGHT,PRICE,ID_PRODUCT) values ('4','purple','1300','2190','4');
  130. Insert into PROPERTIES (ID_PROPERTIES,COLOR,WEIGHT,PRICE,ID_PRODUCT) values ('5','white','1800','7500','5');
  131. Insert into PROPERTIES (ID_PROPERTIES,COLOR,WEIGHT,PRICE,ID_PRODUCT) values ('6','black','2500','1950','6');
  132. --------------------------------------------------------
  133. -- DDL for Index ORDERS_PK
  134. --------------------------------------------------------
  135.  
  136. CREATE UNIQUE INDEX "ORDERS_PK" ON "ORDERS" ("ID_ORDER")
  137. ;
  138. /
  139. --------------------------------------------------------
  140. -- DDL for Index CATEGORIES_PK
  141. --------------------------------------------------------
  142.  
  143. CREATE UNIQUE INDEX "CATEGORIES_PK" ON "CATEGORIES" ("ID_CATEGORY")
  144. ;
  145. /
  146. --------------------------------------------------------
  147. -- DDL for Index PRODUCTS_PK
  148. --------------------------------------------------------
  149.  
  150. CREATE UNIQUE INDEX "PRODUCTS_PK" ON "PRODUCTS" ("ID")
  151. ;
  152. /
  153. --------------------------------------------------------
  154. -- DDL for Index CLIENTS_PK
  155. --------------------------------------------------------
  156.  
  157. CREATE UNIQUE INDEX "CLIENTS_PK" ON "CLIENTS" ("ID_CLIENT")
  158. ;
  159. /
  160. --------------------------------------------------------
  161. -- Constraints for Table PRODUCTS
  162. --------------------------------------------------------
  163.  
  164. ALTER TABLE "PRODUCTS" ADD CONSTRAINT "PRODUCTS_PK" PRIMARY KEY ("ID") ENABLE;
  165.  
  166. ALTER TABLE "PRODUCTS" MODIFY ("ID" NOT NULL ENABLE);
  167.  
  168. ALTER TABLE "PRODUCTS" MODIFY ("NAME" NOT NULL ENABLE);
  169. /
  170. --------------------------------------------------------
  171. -- Constraints for Table PROPERTIES
  172. --------------------------------------------------------
  173.  
  174. ALTER TABLE "PROPERTIES" MODIFY ("ID_PROPERTIES" NOT NULL ENABLE);
  175.  
  176. ALTER TABLE "PROPERTIES" MODIFY ("PRICE" NOT NULL ENABLE);
  177. /
  178. --------------------------------------------------------
  179. -- Constraints for Table CATEGORIES
  180. --------------------------------------------------------
  181.  
  182. ALTER TABLE "CATEGORIES" ADD CONSTRAINT "CATEGORIES_PK" PRIMARY KEY ("ID_CATEGORY") ENABLE;
  183.  
  184. ALTER TABLE "CATEGORIES" MODIFY ("ID_CATEGORY" NOT NULL ENABLE);
  185. /
  186. --------------------------------------------------------
  187. -- Constraints for Table ORDERS
  188. --------------------------------------------------------
  189.  
  190. ALTER TABLE "ORDERS" ADD CONSTRAINT "ORDERS_PK" PRIMARY KEY ("ID_ORDER") ENABLE;
  191.  
  192. ALTER TABLE "ORDERS" MODIFY ("ID_ORDER" NOT NULL ENABLE);
  193. /
  194. --------------------------------------------------------
  195. -- Constraints for Table CLIENTS
  196. --------------------------------------------------------
  197.  
  198. ALTER TABLE "CLIENTS" ADD CONSTRAINT "CLIENTS_PK" PRIMARY KEY ("ID_CLIENT") ENABLE;
  199.  
  200. ALTER TABLE "CLIENTS" MODIFY ("ID_CLIENT" NOT NULL ENABLE);
  201. /
  202. --------------------------------------------------------
  203. -- Ref Constraints for Table CATEGORIES
  204. --------------------------------------------------------
  205.  
  206. ALTER TABLE "CATEGORIES" ADD CONSTRAINT "CATEGORIES_PRODUCTS_FK1" FOREIGN KEY ("ID_PRODUCT")
  207. REFERENCES "PRODUCTS" ("ID") ENABLE;
  208. /
  209. --------------------------------------------------------
  210. -- Ref Constraints for Table ORDERS
  211. --------------------------------------------------------
  212.  
  213. ALTER TABLE "ORDERS" ADD CONSTRAINT "ORDERS_CLIENTS_FK1" FOREIGN KEY ("ID_CLIENT")
  214. REFERENCES "CLIENTS" ("ID_CLIENT") ENABLE;
  215.  
  216. ALTER TABLE "ORDERS" ADD CONSTRAINT "ORDERS_PRODUCTS_FK1" FOREIGN KEY ("ID_PRODUCT")
  217. REFERENCES "PRODUCTS" ("ID") ENABLE;
  218. /
  219. --------------------------------------------------------
  220. -- Ref Constraints for Table PROPERTIES
  221. --------------------------------------------------------
  222.  
  223. ALTER TABLE "PROPERTIES" ADD CONSTRAINT "PROPERTIES_PRODUCTS_FK1" FOREIGN KEY ("ID_PRODUCT")
  224. REFERENCES "PRODUCTS" ("ID") ENABLE;
  225. /
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement