Advertisement
mmouhib

LOSTINTHEHEATOFITALL

Nov 24th, 2021
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.26 KB | None | 0 0
  1. CREATE TABLE departement (num_dept number(8), nom_dept varchar2(20));
  2.  
  3. CREATE TABLE employe (
  4. NSS number(4),
  5. nom varchar2(30),
  6. prenom varchar2(30),
  7. date_naiss date,
  8. adresse varchar2(20),
  9. sexe varchar2 (1),
  10. salaire number(7, 3),
  11. NSS_sup number (3)
  12. );
  13.  
  14. CREATE TABLE projet (
  15. p_num number (3),
  16. p_nom varchar2(30),
  17. p_location varchar2(30),
  18. num_dept number(8)
  19. );
  20.  
  21. CREATE TABLE travail_dans (
  22. NSS number (4),
  23. p_num number (3),
  24. heure number(2)
  25. );
  26.  
  27. ALTER TABLE
  28. employe
  29. ADD
  30. CONSTRAINT check_salire CHECK (
  31. salaire BETWEEN 1000
  32. AND 8000
  33. );
  34.  
  35. ALTER TABLE projet
  36. ADD CONSTRAINT check_location CHECK (p_location IN ('tunis', 'sfax', 'sousse'));
  37.  
  38. ALTER TABLE projet
  39. ADD CONSTRAINT check_nom CHECK (p_nom LIKE 'P_%');
  40.  
  41. ALTER TABLE departement
  42. ADD CONSTRAINT pk_departement PRIMARY KEY(num_dept);
  43.  
  44. ALTER TABLE employe
  45. ADD CONSTRAINT pk_employe PRIMARY KEY(NSS);
  46.  
  47. ALTER TABLE projet
  48. ADD CONSTRAINT pk_projet PRIMARY KEY(p_num);
  49.  
  50. ALTER TABLE projet
  51. ADD CONSTRAINT pk_projet PRIMARY KEY(p_num);
  52.  
  53. ALTER TABLE travail_dans
  54. ADD CONSTRAINT pk_travail_dans FOREIGN KEY (NSS) REFERENCES employe(NSS);
  55.  
  56. ALTER TABLE travail_dans
  57. ADD CONSTRAINT pk_travail_dans2 FOREIGN KEY (p_num) REFERENCES projet(p_num);
  58.  
  59. ALTER TABLE travail_dans
  60. ADD CONSTRAINT fk_travail_dans_fkInsteadOfPk PRIMARY KEY(NSS, p_num);
  61.  
  62. ALTER TABLE employe
  63. ADD num_dept number(8);
  64.  
  65. ALTER TABLE employe
  66. ADD CONSTRAINT fk1_employe FOREIGN KEY (num_dept) REFERENCES departement(num_dept);
  67.  
  68. ALTER TABLE employe
  69. ADD CONSTRAINT fk2_employe FOREIGN KEY (NSS_sup) REFERENCES employe(NSS);
  70.  
  71. ALTER TABLE employe
  72. ADD CONSTRAINT check_sexe CHECK (sexe IN ('M', 'F', 'm', 'f'));
  73.  
  74. INSERT INTO departement
  75. VALUES (1, 'comptabilite');
  76.  
  77. INSERT INTO departement
  78. VALUES (2, 'infromatique');
  79.  
  80. INSERT INTO departement
  81. VALUES (3, 'gestion');
  82.  
  83. INSERT INTO departement
  84. VALUES (4, 'vente');
  85.  
  86. INSERT INTO employe VALUES (1236,'ali','mohamed', '09 Jan 56', 'Tunis', 'M', '4000', NULL, 3);
  87. INSERT INTO employe VALUES (4569,'Ben rejeb','Sami', '02 Sep 69', 'Sousse', 'M',3000, 1236, 3);
  88. INSERT INTO employe VALUES (8523,'Mabrouk','Mounir', '12 Jun 60', 'Sfax', 'M',4000, NULL , 1);
  89. INSERT INTO employe VALUES (1478,'Selmi','Riadh', '25 Mar 67', 'Tunis', 'M',2500, 8523, 2);
  90. INSERT INTO employe VALUES (8965,'Sandid','Imen', '25 Mar 67', 'Gabes', 'F',3500, 8523, 2);
  91. INSERT INTO employe VALUES (9632,'Saidan','Leila', '26 Aug 70', 'Monastir', 'F',3200, NULL, 1);
  92. INSERT INTO employe VALUES (5826,'Ben salah','Mehdi', '27 May 72', 'Tunis', 'M',5000, 9632, 1);
  93. INSERT INTO employe VALUES (3695,'Meladi','Houda', '14 Dec 73','Sfax','F',3000,1236,3);
  94.  
  95.  
  96. INSERT INTO projet VALUES (1, 'P_Production1', 'sfax', 1);
  97. INSERT INTO projet VALUES (23, 'P_Reorganisation', 'tunis', 3);
  98. INSERT INTO projet VALUES (3, 'ProductionX', 'tunis', 1);
  99. INSERT INTO projet VALUES (7, 'P_Communication', 'sousse', 2);
  100. INSERT INTO projet VALUES (18, 'P_Gestion1', 'sousse', 3);
  101.  
  102. ALTER TABLE travail_dans
  103. MODIFY (heure NUMBER(3));
  104.  
  105.  
  106. INSERT INTO travail_dans VALUES (1236,23,210);
  107. INSERT INTO travail_dans VALUES (1236,1,23);
  108. INSERT INTO travail_dans VALUES (8965,7,00);
  109. INSERT INTO travail_dans VALUES (5826,1,10);
  110. INSERT INTO travail_dans VALUES (4569,23,30);
  111. INSERT INTO travail_dans VALUES (8523,7,60);
  112. INSERT INTO travail_dans VALUES (5826,3,20);
  113. INSERT INTO travail_dans VALUES (3695,18,10);
  114. INSERT INTO travail_dans VALUES (3695,23,45);
  115. INSERT INTO travail_dans VALUES (9632,3,15);
  116. INSERT INTO travail_dans VALUES (1478,7,45);
  117. INSERT INTO travail_dans VALUES (8965,23,57);
  118.  
  119. delete from departement where num_dept = 4;
  120.  
  121. update employe set salaire = salaire + 100 where NSS_sup = 8523;
  122.  
  123. -- TP2
  124.  
  125. select * from employe where num_dept = 3;
  126.  
  127. select nom, num_dept from employe;
  128.  
  129. select nom_dept from departement where num_dept > 2;
  130.  
  131. select salaire, salaire*12 from employe where salaire*12 > 40000;
  132.  
  133. -- 5)
  134.  
  135. select nom, salaire from employe where salaire*12 BETWEEN 35000 and 40000;
  136.  
  137. select nom, salaire, date_naiss from employe where num_dept = 3 order by salaire DESC;
  138.  
  139. select nom from employe where nom like '__n%';
  140.  
  141. select nom from employe where nom like '%i%';
  142.  
  143. select NSS, nom from employe where adresse in ('Tunis', 'Sfax');
  144.  
  145. select NSS, nom from employe where adresse not in ('Tunis', 'Sfax');
  146.  
  147. select * from employe where date_naiss BETWEEN '1 Jan 60' and '31 Dec 70';
  148.  
  149. -- TP3
  150.  
  151.  
  152.  
  153.  
  154.  
  155. -- connect tpg2/tpg2
  156.  
  157. select p_num, num_dept from projet join departement using(num_dept)
  158. where p_location = 'tunis';
  159.  
  160. select p_num, num_dept from projet join departement using(num_dept)
  161. where nom_dept = 'gestion';
  162.  
  163. select nom, adresse from employe join departement using(num_dept)
  164. where nom_dept = 'informatique';
  165.  
  166. select nom, prenom
  167. from employe join departement using (num_dept) join travail_dans using(nss)
  168. where heure = (
  169. select heure from travail_dans where (
  170. nss = (select nss from employe where nom = 'Houda' and prenom = 'Meladi'))
  171. );
  172.  
  173.  
  174. select nom, prenom
  175. from employe, travail_dans
  176. where employe.nss= travail_dans.nss and heure = (
  177. select heure
  178. from travail_dans ,employe
  179. where employe.nss= travail_dans.nss and nom = 'ali' and prenom = 'mohamed' and p_num = 1
  180. )
  181. and nom != 'ali' and prenom != 'mohamed';
  182.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement