SHARE
TWEET

Untitled

a guest Jan 28th, 2020 71 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. --CREATE DATABASE depozITfinal;
  2.  
  3. USE depozITfinal;
  4.  
  5.  
  6. ----------------------------------------------------
  7. ------------------Crearea tabelelor-----------------
  8. ----------------------------------------------------
  9.  
  10. CREATE TABLE produse
  11. (
  12.     Producator char(1) NOT NULL,
  13.     Model int primary key NOT NULL,
  14.     Tip varchar(10) NOT NULL
  15. )
  16.  
  17. CREATE TABLE pc_uri
  18. (
  19.     Cod int primary key NOT NULL,
  20.     Model int REFERENCES produse(Model) NOT NULL,
  21.     Viteza decimal(3,0) NOT NULL,
  22.     Ram decimal(3,0) NOT NULL,
  23.     Hd decimal(2,0) NOT NULL,
  24.     Cd varchar(3) NOT NULL,
  25.     Pret float NOT NULL
  26. )
  27.  
  28. CREATE TABLE laptop_uri
  29. (
  30.     Cod int primary key NOT NULL,
  31.     Model int REFERENCES produse(Model) NOT NULL,
  32.     Viteza decimal(3,0) NOT NULL,
  33.     Ram decimal(3,0) NOT NULL,
  34.     Hd decimal(2,0) NOT NULL,
  35.     Pret float NOT NULL,
  36.     Ecran int NOT NULL
  37. )
  38.  
  39. CREATE TABLE imprimante
  40. (
  41.     Cod int primary key NOT NULL,
  42.     Model int REFERENCES produse(Model) NOT NULL,
  43.     Color char(2) NOT NULL,
  44.     Tip varchar(6) NOT NULL,
  45.     Pret float NOT NULL
  46. )
  47.  
  48.  
  49. ----------------------------------------------------
  50. --------------Definirea Cheilor Primare-------------
  51. ----------------------------------------------------
  52.  
  53. --ALTER TABLE produse ADD CONSTRAINT PK_Produs PRIMARY KEY(Model);
  54. --ALTER TABLE pc_uri ADD CONSTRAINT PK_Pc PRIMARY KEY(Cod);
  55. --ALTER TABLE laptop_uri ADD CONSTRAINT PK_Laptop PRIMARY KEY(Cod);
  56. --ALTER TABLE imprimante ADD CONSTRAINT PK_Imprimanta PRIMARY KEY(Cod);
  57.  
  58.  
  59. ----------------------------------------------------
  60. --------------Definirea Cheilor Externe-------------
  61. ----------------------------------------------------
  62.  
  63. --ALTER TABLE pc_uri ADD CONSTRAINT FK_Pc_Produse FOREIGN KEY(Model) REFERENCES produse(Model);
  64. --ALTER TABLE laptop_uri ADD CONSTRAINT FK_Laptop_Produse FOREIGN KEY(Model) REFERENCES produse(Model);
  65. --ALTER TABLE imprimante ADD CONSTRAINT FK_Imprimanta_Produse FOREIGN KEY(Model) REFERENCES produse(Model);
  66.  
  67.  
  68. ----------------------------------------------------
  69. -----------------Popularea Tabelelor----------------
  70. ----------------------------------------------------
  71.  
  72. INSERT INTO produse(Producator,Model,Tip)
  73. VALUES ('B','1121','PC');
  74. INSERT INTO produse(Producator,Model,Tip)
  75. VALUES ('A','1232','PC');
  76. INSERT INTO produse(Producator,Model,Tip)
  77. VALUES ('A','1233','PC');
  78. INSERT INTO produse(Producator,Model,Tip)
  79. VALUES ('E','1260','PC');
  80. INSERT INTO produse(Producator,Model,Tip)
  81. VALUES ('A','1276','Imprimante');
  82. INSERT INTO produse(Producator,Model,Tip)
  83. VALUES ('D','1288','Imprimante');
  84. INSERT INTO produse(Producator,Model,Tip)
  85. VALUES ('A','1298','Laptop_uri');
  86. INSERT INTO produse(Producator,Model,Tip)
  87. VALUES ('C','1321','Laptop_uri');
  88. INSERT INTO produse(Producator,Model,Tip)
  89. VALUES ('A','1401','Imprimante');
  90. INSERT INTO produse(Producator,Model,Tip)
  91. VALUES ('A','1408','Imprimante');
  92. INSERT INTO produse(Producator,Model,Tip)
  93. VALUES ('D','1433','Imprimante');
  94. INSERT INTO produse(Producator,Model,Tip)
  95. VALUES ('E','1434','Imprimante');
  96. INSERT INTO produse(Producator,Model,Tip)
  97. VALUES ('B','1750','Laptop_uri');
  98. INSERT INTO produse(Producator,Model,Tip)
  99. VALUES ('A','1752','Laptop_uri');
  100. INSERT INTO produse(Producator,Model,Tip)
  101. VALUES ('E','2111','PC');
  102. INSERT INTO produse(Producator,Model,Tip)
  103. VALUES ('E','2112','PC');
  104.  
  105.  
  106.  
  107. INSERT INTO pc_uri(Cod,Model,Viteza,Ram,Hd,Cd,Pret)
  108. VALUES (1,'1232',500,64,5,'12x',600);
  109. INSERT INTO pc_uri(Cod,Model,Viteza,Ram,Hd,Cd,Pret)
  110. VALUES (2,'1121',750,128,14,'40x',850);
  111. INSERT INTO pc_uri(Cod,Model,Viteza,Ram,Hd,Cd,Pret)
  112. VALUES (3,'1233',500,64,5,'12x',600);
  113. INSERT INTO pc_uri(Cod,Model,Viteza,Ram,Hd,Cd,Pret)
  114. VALUES (4,'1121',600,128,14,'40x',850);
  115. INSERT INTO pc_uri(Cod,Model,Viteza,Ram,Hd,Cd,Pret)
  116. VALUES (5,'1121',600,128,8,'40x',850);
  117. INSERT INTO pc_uri(Cod,Model,Viteza,Ram,Hd,Cd,Pret)
  118. VALUES (6,'1233',750,128,20,'50x',950);
  119. INSERT INTO pc_uri(Cod,Model,Viteza,Ram,Hd,Cd,Pret)
  120. VALUES (7,'1232',500,32,10,'12x',400);
  121. INSERT INTO pc_uri(Cod,Model,Viteza,Ram,Hd,Cd,Pret)
  122. VALUES (8,'1232',450,64,8,'24x',350);
  123. INSERT INTO pc_uri(Cod,Model,Viteza,Ram,Hd,Cd,Pret)
  124. VALUES (9,'1232',450,32,10,'24x',350);
  125. INSERT INTO pc_uri(Cod,Model,Viteza,Ram,Hd,Cd,Pret)
  126. VALUES (10,'1260',500,32,10,'12x',350);
  127. INSERT INTO pc_uri(Cod,Model,Viteza,Ram,Hd,Cd,Pret)
  128. VALUES (11,'1233',900,128,40,'40x',980);
  129.  
  130.  
  131. INSERT INTO laptop_uri(Cod,Model,Viteza,Ram,Hd,Pret,Ecran)
  132. VALUES (1,'1298',350,32,4,700,11);
  133. INSERT INTO laptop_uri(Cod,Model,Viteza,Ram,Hd,Pret,Ecran)
  134. VALUES (2,'1321',500,64,8,970,12);
  135. INSERT INTO laptop_uri(Cod,Model,Viteza,Ram,Hd,Pret,Ecran)
  136. VALUES (3,'1750',750,128,12,1200,14);
  137. INSERT INTO laptop_uri(Cod,Model,Viteza,Ram,Hd,Pret,Ecran)
  138. VALUES (4,'1298',600,64,10,1050,15);
  139. INSERT INTO laptop_uri(Cod,Model,Viteza,Ram,Hd,Pret,Ecran)
  140. VALUES (5,'1752',750,128,10,1150,14);
  141. INSERT INTO laptop_uri(Cod,Model,Viteza,Ram,Hd,Pret,Ecran)
  142. VALUES (6,'1298',450,64,10,950,12);
  143.  
  144.  
  145. INSERT INTO imprimante(Cod,Model,Color,Tip,Pret)
  146. VALUES (1,'1276','nu','Laser',400);
  147. INSERT INTO imprimante(Cod,Model,Color,Tip,Pret)
  148. VALUES (2,'1433','da','Jet',270);
  149. INSERT INTO imprimante(Cod,Model,Color,Tip,Pret)
  150. VALUES (3,'1434','da','Jet',290);
  151. INSERT INTO imprimante(Cod,Model,Color,Tip,Pret)
  152. VALUES (4,'1401','nu','Matrix',150);
  153. INSERT INTO imprimante(Cod,Model,Color,Tip,Pret)
  154. VALUES (5,'1408','nu','Matrix',270);
  155. INSERT INTO imprimante(Cod,Model,Color,Tip,Pret)
  156. VALUES (6,'1288','nu','Laser',400);
  157.  
  158. exec sp_changedbowner 'sa'
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top