Guest User

Untitled

a guest
May 28th, 2018
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.33 KB | None | 0 0
  1. drop table Editora cascade constraint;
  2.  
  3. drop sequence seq_editora;
  4.  
  5. create sequence seq_editora
  6. start with 1
  7. increment by 1;
  8.  
  9. create table Editora (
  10. cod_editora number not null,
  11. nomeEditora varchar(100) not null,
  12. primary key(cod_editora),
  13. unique (nomeEditora)
  14. );
  15.  
  16. drop table Tags cascade constraint;
  17.  
  18. drop sequence seq_tags;
  19.  
  20. create sequence seq_tags
  21. start with 1
  22. increment by 1;
  23.  
  24. create table Tags (
  25. cod_tag number not null,
  26. nomeTag varchar(100) not null,
  27. primary key(cod_tag),
  28. unique (nomeTag)
  29. );
  30.  
  31. drop sequence seq_socios;
  32.  
  33. create sequence seq_socios
  34. start with 1
  35. increment by 1;
  36.  
  37. drop table Socios cascade constraint;
  38.  
  39. create table Socios (
  40. cod_socio number not null,
  41. nomeSocio varchar(100) not null,
  42. data_insc date not null,
  43. morada varchar(100) not null,
  44. sexo char(1) not null CHECK (sexo IN ('F' , 'M')),
  45. primary key (cod_socio)
  46. );
  47.  
  48.  
  49. drop sequence seq_autores;
  50.  
  51. create sequence seq_autores
  52. start with 1
  53. increment by 1;
  54.  
  55. drop table Autores cascade constraint;
  56.  
  57. create table Autores (
  58. cod_autor number not null,
  59. nomeAutor varchar(100) not null,
  60. primary key(cod_autor),
  61. unique (nomeAutor)
  62. );
  63.  
  64. drop sequence seq_empregados;
  65.  
  66. create sequence seq_empregados
  67. start with 1
  68. increment by 1;
  69.  
  70. drop table Empregados cascade constraint;
  71.  
  72. create table Empregados (
  73. cod_empregado number not null,
  74. nomeEmpregado varchar(100) not null,
  75. salario number not null,
  76. morada varchar(100) not null,
  77. sexo char(1) not null CHECK (sexo IN ('F' , 'M')),
  78. primary key(cod_empregado)
  79. );
  80.  
  81. drop table Periodic_pub cascade constraint;
  82.  
  83. create table Periodic_pub (
  84. ISSN number not null,
  85. nomePeriodic varchar(100) not null,
  86. volume number,
  87. edicao number not null,
  88. data_pub date not null,
  89. cod_editora number not null,
  90. primary key(ISSN),
  91. foreign key (cod_editora) references Editora
  92. );
  93.  
  94. drop table Caracteriza_periodic cascade constraint;
  95.  
  96. create table Caracteriza_periodic (
  97. cod_tag number not null,
  98. ISSN number not null,
  99. primary key(cod_tag, ISSN),
  100. foreign key (cod_tag) references Tags,
  101. foreign key (ISSN) references Periodic_Pub
  102. );
  103.  
  104. drop table Localizacao_fisica cascade constraint;
  105.  
  106. drop sequence seq_loc_fisica;
  107.  
  108. create sequence seq_loc_fisica
  109. start with 1
  110. increment by 1;
  111.  
  112. create table Localizacao_fisica (
  113. cod_loc number not null,
  114. corredor varchar(3) not null,
  115. primary key(cod_loc),
  116. unique (corredor)
  117. );
  118.  
  119. drop table Livros cascade constraint;
  120.  
  121. create table Livros (
  122. ISBN number not null,
  123. nomeLivro varchar(100) not null,
  124. edicao number not null,
  125. data_pub date not null,
  126. cod_editora number not null,
  127. primary key(ISBN),
  128. foreign key (cod_editora) references Editora
  129. );
  130.  
  131. drop table Caracteriza_livro cascade constraint;
  132.  
  133. create table Caracteriza_livro (
  134. cod_tag number not null,
  135. ISBN number not null,
  136. primary key(cod_tag, ISBN),
  137. foreign key (cod_tag) references Tags,
  138. foreign key (ISBN) references Livros
  139. );
  140.  
  141. drop table Livros_fisicos cascade constraint;
  142.  
  143. drop sequence seq_livros_fisicos;
  144.  
  145. create sequence seq_livros_fisicos
  146. start with 1
  147. increment by 1;
  148.  
  149. create table Livros_fisicos (
  150. cod_livro number not null,
  151. ISBN number not null,
  152. cod_loc number not null,
  153. primary key (cod_livro),
  154. foreign key (ISBN) references Livros,
  155. foreign key (cod_loc) references Localizacao_fisica
  156. );
  157.  
  158. drop table Escrito_por cascade constraint;
  159.  
  160. create table Escrito_por (
  161. cod_autor number not null,
  162. ISBN number not null,
  163. primary key(cod_autor, ISBN),
  164. foreign key (cod_autor) references Autores,
  165. foreign key (ISBN) references Livros
  166. );
  167.  
  168. drop table Solicitacao cascade constraint;
  169.  
  170. create table Solicitacao (
  171. data_req date not null,
  172. cod_livro number not null,
  173. cod_socio number not null,
  174. resp_req number not null,
  175. foreign key (cod_livro) references Livros_fisicos,
  176. foreign key (cod_socio) references Socios,
  177. foreign key (resp_req) references Empregados (cod_empregado),
  178. primary key (data_req, cod_livro, cod_socio)
  179. );
  180.  
  181. drop table Devolucao cascade constraint;
  182.  
  183. create table Devolucao (
  184. data_dev date not null,
  185. data_req date not null,
  186. cod_livro number not null,
  187. cod_socio number not null,
  188. resp_dev number not null,
  189. foreign key (data_req, cod_livro, cod_socio) references Solicitacao (data_req, cod_livro, cod_socio),
  190. primary key (data_dev, data_req, cod_livro, cod_socio)
  191. );
Add Comment
Please, Sign In to add comment