Advertisement
Guest User

bazy danych

a guest
Nov 17th, 2019
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MySQL 2.37 KB | None | 0 0
  1. USE master;
  2. IF EXISTS(select * from sys.databases where name='wu')
  3. ALTER DATABASE wu SET SINGLE_USER WITH ROLLBACK IMMEDIATE;
  4. DROP DATABASE if exists wu
  5. go
  6. CREATE DATABASE wu
  7. go
  8. USE wu
  9. go
  10.  
  11. /*instrukcje tworzace baze danych dla wyzszej uczelni BEZ DANYCH
  12. skladnia T-SQL
  13. */
  14.  
  15. create table oceny (
  16. ocena decimal(3,1) primary key);
  17.  
  18. create table grupy (
  19. nr_grupy char(10) primary key);
  20.  
  21. create table stopnie_tytuly (
  22. stopien_tytul varchar(25) primary key,
  23. stawka smallmoney not null);
  24.  
  25. create table pracownicy (
  26. id_pracownika int identity primary key,
  27. nazwisko varchar(30) not null,
  28. imie varchar(25),
  29. NIP char(13),
  30. PESEL char(11));
  31.  
  32. create table wykladowcy (
  33. id_wykladowcy int primary key,
  34. stopien_tytul varchar(25) not null,
  35. katedra varchar(100)
  36. );
  37. alter table wykladowcy add constraint rpw foreign key (id_wykladowcy) references pracownicy (id_pracownika) on delete cascade;
  38. alter table wykladowcy add constraint rwst foreign key (stopien_tytul) references stopnie_tytuly on delete no action on update cascade;
  39.  
  40. create table studenci (
  41. id_studenta int identity primary key,
  42. nazwisko varchar(30) not null,
  43. imie varchar(25),
  44. data_urodzenia date check(data_urodzenia<=dateAdd(year,-18,getdate())),
  45. nr_grupy char(10) not null
  46. );
  47. alter table studenci add constraint rsg foreign key (nr_grupy) references grupy on delete no action on update cascade;
  48.  
  49. create table wyklady (
  50. id_wykladu int identity primary key,
  51. nazwa_wykladu varchar(50) not null,
  52. liczba_godzin tinyint check(liczba_godzin<=60),
  53. id_wykladowcy int,
  54. foreign key (id_wykladowcy) references wykladowcy
  55. on delete no action on update cascade
  56. );
  57.  
  58. create table studenci_wyklady (
  59. id_studenta int,
  60. id_wykladu int,
  61. primary key (id_studenta, id_wykladu),
  62. foreign key (id_wykladu) references wyklady on delete no action,
  63. foreign key (id_studenta) references studenci on delete cascade
  64. );
  65.  
  66. create table oceny_studentow (
  67. id_studenta int,
  68. id_wykladu int,
  69. data_egzaminu date default getdate() check(data_egzaminu<=getdate()),
  70. ocena decimal(3,1) not null,
  71. primary key (id_studenta, id_wykladu, data_egzaminu),
  72. foreign key (id_studenta, id_wykladu) references studenci_wyklady
  73. on delete no action on update cascade,
  74. foreign key (ocena) references oceny on delete no action on update cascade
  75. );
  76. adjective: podstawowy, główny, pierwotny, prymarny, pierwiastkowy...
  77. noun: era paleozoiczna
  78. translated from: English
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement