Guest User

Untitled

a guest
Oct 20th, 2016
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 11.62 KB | None | 0 0
  1. USE master
  2. go
  3. if exists (select 'true' from sys.databases where name = 'Colegiu')
  4. begin
  5. ALTER DATABASE Colegiu
  6. SET SINGLE_USER
  7. WITH ROLLBACK IMMEDIATE;
  8. drop database Colegiu
  9. end
  10. GO
  11. set dateformat dmy
  12. GO
  13. create database Colegiu
  14. GO
  15. Use Colegiu
  16. GO
  17. exec sp_changedbowner 'sa'
  18. GO
  19. Create table Catedre
  20. (
  21. idcatedre int primary key
  22. ,nmcatedre Char(50) Unique
  23. ,idprofesor INT
  24. )
  25. Go
  26. -- Crearea tabelei Objstud
  27. Create table objstud
  28. (
  29. idobjstud int primary key
  30. ,mnobjstud Char(50) unique
  31. ,idcatedre INT Default 1
  32. )
  33. Go
  34. Create table Profesor
  35. (
  36. idprofesor INT PRIMARY KEY
  37. ,nmprofesor Char(50) Unique
  38. )
  39. GO
  40. Create table ObjStGr
  41. (
  42. idobjstgr INT primary key
  43. ,idgrupa INT
  44. ,idobjstud INT
  45. ,idprofesor INT
  46. )
  47. GO
  48. Create table grupa
  49. (
  50. idgrupa INT PRIMARY KEY
  51. ,nmgrupa Char(50)Unique
  52. ,anadm INT
  53. ,idprofesor INT
  54. ,idspec INT
  55. )
  56. GO
  57. Create table student
  58. (
  59. idstudent INT Primary key
  60. ,nmstud char(50)
  61. ,prenstud char(50)
  62. ,patrstud char(50)
  63. ,sexstud Char(1) Check (sexstud='m' or sexstud='f')
  64. ,Ncarnet char(10)
  65. ,DataNs Date
  66. ,GSM char(15)
  67. ,idgrupa INT
  68. ,idlocalit INt
  69. )
  70. GO
  71. Create table raion
  72. (
  73. idraion INT Primary key
  74. ,nmraion char(50) Unique
  75. )
  76. Go
  77. Create table spec
  78. (
  79. idspec INT primary key
  80. ,nmspec char(50) Unique
  81. )
  82. GO
  83. Create table localit
  84. (
  85. idlocalit INT Primary key
  86. ,nmlocalit char(50)Unique
  87. ,idraion INT
  88. )
  89. GO
  90. Create table notele
  91. (
  92. idnotele INT primary key
  93. ,idstudent INT
  94. ,Idobjstud INT
  95. ,data date
  96. ,nota decimal(4,2) Check(1<=nota and nota<=10)
  97. )
  98. Go
  99.  
  100. Alter table catedre
  101. Add constraint Fk_Catedre_idprofesor
  102. Foreign key (idprofesor) references profesor (idprofesor)
  103.  
  104. Alter table objstud
  105. Add constraint Fk_ObjStud_idcatedre
  106. Foreign key (idcatedre) references catedre (idcatedre)
  107.  
  108. Alter table grupa
  109. Add constraint Fk_grupa_idprofesor
  110. Foreign key (idprofesor) references profesor (idprofesor)
  111.  
  112. Alter table grupa
  113. Add constraint Fk_grupa_idspec
  114. Foreign key (idspec) references spec (idspec)
  115.  
  116. Alter table objstgr
  117. Add constraint Fk_objstr_idprofesor
  118. Foreign key (idprofesor) references profesor (idprofesor)
  119.  
  120. Alter table objstgr
  121. Add constraint Fk_objstr_idgrupa
  122. Foreign key (idgrupa) references grupa (idgrupa)
  123.  
  124. Alter table objstgr
  125. Add constraint Fk_objstr_idobjstud
  126. Foreign key (idobjstud) references objstud (idobjstud)
  127.  
  128. Alter table student
  129. Add constraint Fk_student_idgrupa
  130. Foreign key (idgrupa) references grupa (idgrupa)
  131.  
  132. Alter table student
  133. Add constraint Fk_student_idlocalit
  134. Foreign key (idlocalit) references localit (idlocalit)
  135.  
  136. Alter table localit
  137. Add constraint Fk_localit_idraion
  138. Foreign key (idraion) references raion (idraion)
  139.  
  140. Alter table notele
  141. Add constraint Fk_notele_idstudent
  142. Foreign key (idstudent) references student (idstudent)
  143.  
  144. Alter table notele
  145. Add constraint Fk_notele_idobjstud
  146. Foreign key (idobjstud) references objstud (idobjstud)
  147.  
  148. GO
  149. --**************|| inserarile ||***********************
  150. Use Colegiu
  151.  
  152. select *
  153. from raion
  154. go
  155. insert into profesor (idprofesor,nmprofesor)
  156. values (1,'Damaschin I.')
  157. ,(2,'Golub A.')
  158. ,(3,'Jalba R.')
  159. ,(4,'Gonta V.')
  160. ,(5,'Frunza O.')
  161. ,(6,'Pasecinic I.')
  162. ,(7,'Ciobanu A.')
  163. ,(8,'Melnic L.')
  164. ,(9,'Petrovshi A.')
  165. ,(10,'Botnariuc L.')
  166. ,(11,'Cotorcea C.')
  167. ,(12,'Polucci T.')
  168. ,(13,'Lisnic B.')
  169. ,(14,'Manea C.')
  170. ,(15,'Goreanu I.')
  171. ,(16,'Cosulean A.')
  172. ,(17,'Mihailov T.')
  173. ,(18,'Cuznetov A.')
  174. ,(19,'Talmaci N.')
  175. ,(20,'Bulat V.');
  176.  
  177. go
  178. insert into raion (idraion,nmraion)
  179. values (1,'Anenii Noi')
  180. ,(2,'Basarabeasca')
  181. ,(3,'Balti')
  182. ,(4,'Briceni')
  183. ,(5,'Cahul')
  184. ,(6,'Cantemir')
  185. ,(7,'Calarasi')
  186. ,(8,'Causeni')
  187. ,(9,'Chisinau')
  188. ,(10,'Cimislia')
  189. ,(11,'Criuleni')
  190. ,(12,'Donduseni')
  191. ,(13,'Drochia')
  192. ,(14,'Dubasari')
  193. ,(15,'Edinet')
  194. ,(16,'Falesti')
  195. ,(17,'Floresti')
  196. ,(18,'Glodeni')
  197. ,(19,'Hincesti')
  198. ,(20,'Ialoveni')
  199. ,(21,'Leova')
  200. ,(22,'Nisporeni')
  201. ,(23,'Ocnita')
  202. ,(24,'Orhei')
  203. ,(25,'Rezina')
  204. ,(26,'Riscani')
  205. ,(27,'Singerei')
  206. ,(28,'Soroca')
  207. ,(29,'Straseni')
  208. ,(30,'Soldanesti')
  209. ,(31,'Stefan Voda')
  210. ,(32,'Taraclia')
  211. ,(33,'Telenesti')
  212. ,(34,'Ungheni')
  213. ,(35,'UTA Gagauzia')
  214. ,(36,'Transnistria');
  215. go
  216. insert into spec (idspec,nmspec)
  217. values (1,'Informatica')
  218. ,(2,'Contabilitate')
  219. ,(3,'Secretariat-birotica')
  220. ,(4,'Finante')
  221. ,(5,'Turism')
  222. ,(6,'Calculatoare')
  223. ,(7,'Administrarea aplicatiilor Web')
  224. ,(8,'Retele calculatoare')
  225. ,(9,'Servicii administrative si de secretariat')
  226. ,(10,'Operator pentru suportul tehnic al calculatoarelor');
  227. go
  228. insert into localit (idraion,nmlocalit,idlocalit)
  229. values (1 ,'Anenii Noi',1)
  230. ,(1 ,'Botnaresti',2)
  231. ,(1 ,'Calfa',3)
  232. ,(2 ,'Basarabeasca',4)
  233. ,(2 ,'Sadaclia',5)
  234. ,(2 ,'Carabetovca',6)
  235. ,(3 ,'Balti',7)
  236. ,(3 ,'Sadovoe',8)
  237. ,(3 ,'Elizaveta',9)
  238. ,(4 ,'Briceni',10)
  239. ,(4 ,'Balcauti',11)
  240. ,(4 ,'Bulboaca',12)
  241. ,(5 ,'Cahul',13)
  242. ,(5 ,'Borceag',14)
  243. ,(5 ,'Bucuria',15)
  244. ,(6 ,'Cantemir',16)
  245. ,(6 ,'Cirpesti',17)
  246. ,(6 ,'Baimaclia',18)
  247. ,(7 ,'Calarasi',19)
  248. ,(7 ,'Bahmut',20)
  249. ,(7 ,'Buda',21)
  250. ,(8 ,'Causeni',22)
  251. ,(8 ,'Cainari',23)
  252. ,(8 ,'Baurci',24)
  253. ,(9 ,'Chisinau',25)
  254. ,(9 ,'Singera',26)
  255. ,(9 ,'Codru',27)
  256. ,(10,'Cimislia',28)
  257. ,(10,'Batir',29)
  258. ,(10,'Mihailovca',30)
  259. ,(11,'Criuleni',31)
  260. ,(11,'Boscana',32)
  261. ,(11,'Cimiseni',33)
  262. ,(12,'Donduseni',34)
  263. ,(12,'Baraboi',35)
  264. ,(12,'Horodiste',36)
  265. ,(13,'Drochia',37)
  266. ,(13,'Chetrosu',38)
  267. ,(13,'Baroncea',39)
  268. ,(14,'Dubasari',40)
  269. ,(14,'Cosnita',41)
  270. ,(14,'Cocieri',42)
  271. ,(15,'Edinet',43)
  272. ,(15,'Buzdugeni',44)
  273. ,(15,'Blenesti',45)
  274. ,(16,'Falesti',46)
  275. ,(16,'Chetris',47)
  276. ,(16,'Bocsa',48)
  277. ,(17,'Floresti',49)
  278. ,(17,'Casunca',50)
  279. ,(17,'Capresti',51)
  280. ,(18,'Glodeni',52)
  281. ,(18,'Cajba',53)
  282. ,(18,'Camenca',54)
  283. ,(19,'Hincesti',55)
  284. ,(19,'Cioara',56)
  285. ,(19,'Carpineni',57)
  286. ,(20,'Ialoveni',58)
  287. ,(20,'Bardar',59)
  288. ,(20,'Alexandrovca',60)
  289. ,(21,'Leova',61)
  290. ,(21,'Ceadir',62)
  291. ,(21,'Cneazevca',63)
  292. ,(22,'Nisporeni',64)
  293. ,(22,'Cirnesti',65)
  294. ,(22,'Gaureni',66)
  295. ,(23,'Ocnita',67)
  296. ,(23,'Berezovca',68)
  297. ,(23,'Codreni',69)
  298. ,(24,'Orhei',70)
  299. ,(24,'Breanova',71)
  300. ,(24,'Cismea',72)
  301. ,(25,'Rezina',73)
  302. ,(25,'Buciusca',74)
  303. ,(25,'Ciorna',75)
  304. ,(26,'Riscani',76)
  305. ,(26,'Balanu Nou',77)
  306. ,(26,'Ciobanovca',78)
  307. ,(27,'Singerei',79)
  308. ,(27,'Bobletici',80)
  309. ,(27,'Chirileni',81)
  310. ,(28,'Soroca',82)
  311. ,(28,'Baliniti',83)
  312. ,(28,'Cerlina',84)
  313. ,(29,'Straseni',85)
  314. ,(29,'Ciobanca',86)
  315. ,(29,'Gornoe',87)
  316. ,(30,'Soldanesti',88)
  317. ,(30,'Cot',89)
  318. ,(30,'Cuselauca',90)
  319. ,(31,'Stefan Voda',91)
  320. ,(31,'Lazo',92)
  321. ,(31,'Olanesti',93)
  322. ,(32,'Taraclia',94)
  323. ,(32,'Ciumai',95)
  324. ,(32,'Chrilovca',96)
  325. ,(33,'Telenesti',97)
  326. ,(33,'Chersac',98)
  327. ,(33,'Ciofu',99)
  328. ,(34,'Ungheni',100)
  329. ,(34,'Bulhac',101)
  330. ,(34,'Cornesti',102)
  331. ,(35,'Comrat',103)
  332. ,(35,'Vulcanesti',104)
  333. ,(35,'Cazaclia',105)
  334. ,(36,'Bender',106)
  335. ,(36,'Ribnita',107)
  336. ,(36,'Tiraspol',108);
  337.  
  338.  
  339. go
  340. insert into Catedre(idcatedre,idprofesor,nmcatedre)
  341. values (1,5,'Informatica')
  342. ,(2,7,'Informatica Aplicata')
  343. ,(3,20,'Economii')
  344. ,(4,10,'Limba si literatura romana')
  345. ,(5,14,'Limbi straine')
  346. ,(6,9,'Matematica')
  347. ,(7,8,'Istorie si stiinte socioumane')
  348. ,(8,11,'Chimie, biologie si fizica')
  349. ,(9,16,'Educatia fizica');
  350. go
  351. insert into objstud (idcatedre,idobjstud,mnobjstud)
  352. values (4,1,'Limba Romana')
  353. ,(6,2,'Matematica')
  354. ,(1,3,'Informatica')
  355. ,(2,4,'Adm. Web')
  356. ,(9,16,'Educatia fizica')
  357. ,(8,5,'Chimia')
  358. ,(8,6,'Biologie')
  359. ,(8,7,'Fizica')
  360. ,(7,8,'Geografia')
  361. ,(7,9,'Istoria')
  362. ,(7,10,'Filozofia')
  363. ,(5,11,'Limba engleza')
  364. ,(5,12,'Limba franceza')
  365. ,(3,13,'Contabilitatea')
  366. ,(2,14,'Adm. BD')
  367. ,(1,15,'POO');
  368. go
  369. insert into grupa (idgrupa,idprofesor,idspec,nmgrupa,anadm)
  370. values (1,1,1,'I-1432',2014)
  371. ,(2,2,1,'I-1522',2015)
  372. ,(3,3,2,'C-1345',2013)
  373. ,(4,4,2,'C-1521',2015)
  374. ,(5,5,3,'SB-1612',2016)
  375. ,(6,6,3,'SB-1342',2013)
  376. ,(7,7,4,'F-1524',2015)
  377. ,(8,8,4,'F-1431',2014)
  378. ,(9,9,5,'T-1612',2016)
  379. ,(10,10,5,'T-1341',2013)
  380. ,(11,11,6,'K-1521',2015)
  381. ,(12,12,6,'K-1610',2016)
  382. ,(13,13,7,'W-1611',2016)
  383. ,(14,14,7,'W-1612',2016)
  384. ,(15,15,8,'R-1432',2014)
  385. ,(16,16,8,'R-1522',2015)
  386. ,(17,17,9,'S-1614',2016)
  387. ,(18,18,9,'S-1345',2013)
  388. ,(19,19,10,'O-1615',2016)
  389. ,(20,20,10,'O-1522',2015);
  390.  
  391.  
  392. go
  393. insert into student (idstudent,Ncarnet,idgrupa,idlocalit,nmstud,patrstud
  394. ,prenstud,DataNs,GSM,sexstud)
  395. values (1,101,1,1,'Iscanderov','Rustamovici','Ebraghim','16.04.1997','067985662','m'),
  396. (2,102,2,12,'Coliban','Eugen','Serghei','22.10.1998','029756897','m')
  397. ,(3,103,3,23,'Petrovschi','Andreea','Igor','06.06.1999','079634567','f')
  398. ,(4,104,4,34,'Sula','Valeriu','Dumitru','07.08.1996','069556789','m')
  399. ,(5,105,5,45,'Munteanu','Valeria','Valeriu','24.02.1996','079876895','f')
  400. ,(6,106,6,56,'Railean','Vitalie','Ion','13.04.1998','067987654','m')
  401. ,(7,107,7,67,'Gribov', 'Corina','Vladimir','14.06.1999','07986543','f')
  402. ,(8,108,8,78,'Morosan','Ion','Lilian','16.09.1996','0786912345','m')
  403. ,(9,109,9,89,'Cazacu','Cristian','Anatolie','08.09.1996','079546325','m')
  404. ,(10,110,10,100,'Organ','Igor','Igor','24.07.1998','067895436','m')
  405. ,(11,111,11,11,'Donoaga','Elena','Efim','05.07.1999','079856782','f')
  406. ,(12,112,12,22,'Prodan','Vladimir','Alexandru','06.09.1999','029456789','m')
  407. ,(13,113,13,33,'Cojocaru','Liviu','Igor','29.08.1996','079865743','m')
  408. ,(14,114,14,44,'Morari','Sandu','Alexandr','17.7.1997','079865456','m')
  409. ,(15,115,15,55,'Barba','Pavel','Fiodor','19.9.1998','067898769','m')
  410. ,(16,116,16,66,'Elenciuc','Anastasia','Anatolii','21.11.1999','076589709','f')
  411. ,(17,117,17,77,'Gubciac','Cristian','Mihail','28.12.1997','067891245','m')
  412. ,(18,118,18,88,'Sarmaniuc','Alexandrina','Mihail','05.05.1997','069878943','f')
  413. ,(19,119,19,98,'Gaulica','Vlad','Valeriu','06.11.1998','078965489','m')
  414. ,(20,120,20,108,'Bandalac','Sergiu','Sergiu','13.12.1999','027896456','m')
  415. ;
  416. go
  417. insert into ObjStGr(idgrupa,idobjstgr,idobjstud,idprofesor)
  418. values (1,1,4,1)
  419. ,(2,2,5,1)
  420. ,(3,3,4,5)
  421. ,(4,4,3,2);
  422.  
  423. go
  424. insert into notele(idnotele,Idobjstud,idstudent,data,nota)
  425. values (1,1,1,'06.10.2016',10)
  426. ,(2,1,2,'07.09.2016',7)
  427. ,(3,2,3,'09.09.2016',6)
  428. ,(4,2,4,'10.09.2016',5)
  429. ,(5,3,5,'11.09.2016',4)
  430. ,(6,3,6,'12.10.2016',8)
  431. ,(7,4,7,'13.09.2016',9)
  432. ,(8,4,8,'14.09.2016',10)
  433. ,(9,5,9,'15.10.2016',10)
  434. ,(10,5,10,'16.09.2016',6)
  435. ,(11,6,11,'19.10.2016',5)
  436. ,(12,7,12,'20.10.2016',9)
  437. ,(13,7,13,'25.09.2016',8)
  438. ,(14,8,14,'26.10.2016',4)
  439. ,(15,8,15,'27.10.2016',5)
  440. ,(16,9,16,'26.09.2016',7)
  441. ,(17,9,17,'15.10.2016',9)
  442. ,(18,10,18,'16.09.2016',10)
  443. ,(19,10,19,'16.10.2016',9)
  444. ,(20,11,20,'25.10.2016',7)
  445. ,(21,11,19,'4.09.2016',8)
  446. ,(22,12,3,'14.10.2016',8)
  447. ,(23,12,4,'17.10.2016',8)
  448. ,(24,13,7,'06.09.2016',6)
  449. ,(25,13,9,'11.10.2016',5)
  450. ,(26,6,5,'05.10.2016',4)
  451. ,(27,14,6,'06.09.2016',9)
  452. ,(28,14,7,'16.10.2016',10)
  453. ,(29,15,15,'26.09.2016',10)
  454. ,(30,15,12,'19.10.2016',7);
  455.  
  456. go
  457. use master
  458. go
Advertisement
Add Comment
Please, Sign In to add comment