Advertisement
Guest User

Untitled

a guest
Feb 18th, 2020
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.21 KB | None | 0 0
  1. --create database CentruDE420;
  2.  
  3. use CentruDE420;
  4. /*
  5. ------ crearea tabelelor ------
  6.  
  7. create table specialitati(
  8.  
  9. idSpec int primary key not null,
  10. numeSpec char(15) not null
  11.  
  12. );
  13.  
  14. create table profesori(
  15.  
  16. idProf int primary key not null,
  17. numeProf char(25) not null
  18.  
  19. );
  20.  
  21. create table grupe(
  22.  
  23. idGrupa int primary key not null,
  24. numeGrupa char(6) not null,
  25. anul int not null,
  26. idSpec int references specialitati(idSpec) not null,
  27. idProf int references profesori(idProf) not null
  28.  
  29. );
  30.  
  31. create table discipline(
  32.  
  33. idDisciplina int primary key not null,
  34. denumireDisciplina char(15) not null,
  35. idProf int references profesori(idProf) not null
  36.  
  37. );
  38.  
  39.  
  40. create table studenti(
  41.  
  42. idStud int primary key not null,
  43. numeStud char(15) not null,
  44. prenumeStud char(15) not null,
  45. sexStud char not null,
  46. dataStud date not null,
  47. telefonStud char(10) not null,
  48. idGrupa int references grupe(idGrupa) not null
  49.  
  50. );
  51.  
  52.  
  53.  
  54. insert into specialitati values
  55. (2, 'Contabilitate'),
  56. (4, 'Finante'),
  57. (1, 'Informatica'),
  58. (3, 'SB');
  59.  
  60. insert into profesori values
  61. (1, 'Arnaut G.'),
  62. (2, 'Popescu V.'),
  63. (3, 'Scurtu D.');
  64.  
  65. insert into grupe values
  66. (1,'I-1511', 2016, 1, 2),
  67. (2,'C-1421', 2017, 2, 1),
  68. (3,'F-1241', 2018, 3, 3);
  69.  
  70.  
  71. insert into discipline values
  72. (1,'Matematica', 1),
  73. (2,'Istoria',3),
  74. (3,'SGBD',2);
  75.  
  76. insert into studenti values
  77. (1,'Balan','Petru','m','1996-05-17','079564122', 1),
  78. (2,'Rusu','Ana','f','1995-02-23','057684971', 3),
  79. (3,'Cazacu','Ion','m','1994-11-07','05754159', 2),
  80. (4,'Rotaru','Maria','f','1997-09-18','069156945', 1);
  81.  
  82.  
  83. */
  84.  
  85. --select *
  86. -- from studenti;
  87. --select *
  88. -- from grupe;
  89. --select *
  90. -- from profesori;
  91. --select *
  92. -- from specialitati;
  93. --select *
  94. -- from discipline;
  95.  
  96. create view vStud as
  97. select numeStud, prenumeStud
  98. from studenti as s inner join grupe as g on s.idGrupa = g.idGrupa
  99. where numeGrupa = 'I-1511';
  100.  
  101. select numeProf
  102. from profesori as p inner join discipline as d on p.idProf = d.idProf inner join grupe as g on g.idProf = d.idProf inner join studenti as s on s.idGrupa = g.idGrupa
  103. where s.numeStud = 'Rotaru';
  104.  
  105. -- numele prof care o invata pe rotaru maria la sgbd
  106.  
  107. select * vStud;
  108.  
  109. exec sp_changedbowner 'sa';
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement