Advertisement
jets-

setupOO - GDWin

Nov 5th, 2015
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
SQL 7.61 KB | None | 0 0
  1. /* Dale. Vai salvar รฉ? */
  2.  
  3. /* Drop tables */
  4. DROP TABLE funcionarios CASCADE CONSTRAINTS;
  5. DROP TABLE telefones_funcionarios CASCADE CONSTRAINTS;
  6. DROP TABLE enderecos_funcionarios CASCADE CONSTRAINTS;
  7. DROP TABLE clientes CASCADE CONSTRAINTS;
  8. DROP TABLE representantes CASCADE CONSTRAINTS;
  9. DROP TABLE telefones_clientes CASCADE CONSTRAINTS;
  10. DROP TABLE enderecos_clientes CASCADE CONSTRAINTS;
  11. DROP TABLE embarcacoes CASCADE CONSTRAINTS;
  12. DROP TABLE especificacoes CASCADE CONSTRAINTS;
  13. DROP TABLE responsaveis_setores CASCADE CONSTRAINTS;
  14. DROP TABLE setores CASCADE CONSTRAINTS;
  15. /* DROP TABLE projetos FORCE; tirei, visto que deixou de existir. Agora inserimos direto nas tabelas de especializaรงรตes usando somente o tipo_projetos */
  16. DROP TABLE projetos_criacoes CASCADE CONSTRAINTS;
  17. DROP TABLE projetos_restauracoes CASCADE CONSTRAINTS;
  18. DROP TABLE execucoes_projetos CASCADE CONSTRAINTS;
  19. DROP TABLE solicitacoes_projetos CASCADE CONSTRAINTS;
  20. DROP TABLE equipamentos CASCADE CONSTRAINTS;
  21. DROP TABLE compras_equipamentos CASCADE CONSTRAINTS;
  22. DROP TABLE manutencoes_equipamentos CASCADE CONSTRAINTS;
  23.  
  24. DROP TABLE lista_telefones_clientes CASCADE CONSTRAINTS;
  25. /* Drop types */
  26. DROP TYPE tipo_funcionarios FORCE;
  27. DROP TYPE tipo_telefone FORCE;
  28. DROP TYPE tipo_enderecos_funcionarios FORCE;
  29. DROP TYPE tipo_clientes FORCE;
  30. DROP TYPE tipo_representantes FORCE;
  31. DROP TYPE tipo_telefones_funcionarios FORCE;
  32. DROP TYPE tipo_nt_telefones_clientes FORCE;
  33. DROP TYPE tipo_enderecos_clientes FORCE;
  34. DROP TYPE tipo_embarcacoes FORCE;
  35. DROP TYPE tipo_especificacoes FORCE;
  36. DROP TYPE tipo_responsaveis_setores FORCE;
  37. DROP TYPE tipo_setores FORCE;
  38. DROP TYPE tipo_projetos_criacoes FORCE;
  39. DROP TYPE tipo_projetos_restauracoes FORCE;
  40. DROP TYPE tipo_execucoes_projetos FORCE;
  41. DROP TYPE tipo_solicitacoes_projetos FORCE;
  42. DROP TYPE tipo_equipamentos FORCE;
  43. DROP TYPE tipo_compras_equipamentos FORCE;
  44. DROP TYPE tipo_manutencoes_equipamentos FORCE;
  45.  
  46.  
  47. /* Create types*/
  48. CREATE OR REPLACE TYPE tipo_funcionarios AS object (
  49.   cpf VARCHAR2(11),
  50.   nome VARCHAR2(50),
  51.   data_admissao DATE,
  52.   data_nascimento DATE,
  53.   cpf_super REF tipo_funcionarios
  54. );
  55. /
  56. CREATE OR REPLACE TYPE tipo_telefone AS object(
  57.     numero VARCHAR(15)
  58. );
  59. /
  60. CREATE OR REPLACE TYPE tipo_telefones_funcionarios AS VARRAY(5) OF tipo_telefone;
  61. /
  62. CREATE OR REPLACE TYPE tipo_enderecos_funcionarios AS object(
  63.   funcionario_cpf REF tipo_funcionarios,
  64.   cep VARCHAR2(8),
  65.   descricao VARCHAR2(50)
  66. );
  67. /
  68.  
  69. CREATE OR REPLACE TYPE tipo_clientes AS object (
  70.   cnpj VARCHAR2(15),
  71.   nome_empresa VARCHAR2(50),
  72.   email VARCHAR2(50),
  73.   site VARCHAR2(50)
  74. );
  75. /
  76. CREATE OR REPLACE TYPE tipo_representantes AS object (
  77.   cpf_representante VARCHAR2(15),
  78.   empresa_cnpj REF tipo_clientes,
  79.   nome VARCHAR2(50)
  80. );
  81. /
  82. CREATE TYPE tipo_nt_telefones_clientes AS TABLE OF tipo_telefone;
  83. /
  84.  
  85. CREATE OR REPLACE TYPE tipo_enderecos_clientes AS object (
  86.   cliente_cnpj REF tipo_clientes,
  87.   cep VARCHAR2(8),
  88.   descricao VARCHAR2(50)
  89. );
  90. /
  91. CREATE OR REPLACE TYPE tipo_embarcacoes AS object(
  92.   certificado VARCHAR2(50),
  93.   tipo VARCHAR2(50),
  94.   data_fabricacao DATE
  95.   --CONSTRAINT embarcacao_tipo_ck CHECK (tipo IN ('CONTEINEIRO', 'GASEIRO', 'VLCC', 'PETROLEIRO'))
  96. );
  97. /
  98. CREATE OR REPLACE TYPE tipo_especificacoes AS object(
  99.   versao DECIMAL(5, 2),
  100.   peso DECIMAL(6, 3),
  101.   comprimento DECIMAL(5, 3),
  102.   altura DECIMAL(5, 3),
  103.   capacidade_ocupantes INTEGER,
  104.   capacidade_carga DECIMAL(5, 3),
  105.   certificado_embarcacao REF tipo_embarcacoes
  106. );
  107. /
  108. CREATE OR REPLACE TYPE tipo_setores AS object (
  109.   id INTEGER,
  110.   nome_setor VARCHAR2(50),
  111.   descricao VARCHAR2(50)
  112. );
  113. /
  114. CREATE OR REPLACE TYPE tipo_projetos AS object (
  115.   id INTEGER,
  116.   nome VARCHAR2(50),
  117.   descricao VARCHAR2(200),
  118.   orcamento DECIMAL(5, 2),
  119.   data_inicio DATE,
  120.   data_previsao_termino DATE,
  121.   data_termino DATE
  122. ) NOT FINAL NOT INSTANTIABLE;
  123. /
  124. CREATE OR REPLACE TYPE tipo_projetos_criacoes UNDER tipo_projetos (
  125.   modelagem VARCHAR2(50)
  126. );
  127. /
  128. CREATE OR REPLACE TYPE tipo_projetos_restauracoes UNDER tipo_projetos(
  129.   partes_reutilizadas INTEGER,
  130.   partes_descartadas INTEGER
  131. );
  132. /
  133. CREATE OR REPLACE TYPE tipo_responsaveis_setores AS object (
  134.   funcionario_cpf REF tipo_funcionarios,
  135.   setor_id REF tipo_setores
  136. );
  137. /
  138. CREATE OR REPLACE TYPE tipo_execucoes_projetos AS object (
  139.   setor_id REF tipo_setores,
  140.   projeto_id REF tipo_projetos
  141. );
  142. /
  143. CREATE OR REPLACE TYPE tipo_solicitacoes_projetos AS object (
  144.   projeto_id REF tipo_projetos,
  145.   embarcacao_certificado REF tipo_embarcacoes,
  146.   cliente_cnpj REF tipo_clientes,
  147.   DATA DATE
  148. );
  149. /
  150. CREATE OR REPLACE TYPE tipo_equipamentos AS object (
  151.   id INTEGER,
  152.   nome_equipamento VARCHAR2(50),
  153.   tipo VARCHAR2(50),
  154.   data_uso_inicio DATE,
  155.   data_uso_termino DATE
  156. );
  157. /
  158. CREATE OR REPLACE TYPE tipo_compras_equipamentos AS object (
  159.   equipamento_id REF tipo_equipamentos,
  160.   setor_id REF tipo_setores,
  161.   funcionario_cpf REF tipo_funcionarios
  162. );
  163. /
  164. CREATE OR REPLACE TYPE tipo_manutencoes_equipamentos AS object (
  165.   equipamento_id REF tipo_equipamentos,
  166.   DATA DATE,
  167.   situacao VARCHAR2(50)
  168.   --CONSTRAINT manutencao_situacao_ck CHECK (situacao IN ('PENDENTE', 'EM ANDAMENTO', 'CONCLUIDA'))
  169. );
  170. /
  171.  
  172. /*create tables*/
  173.  
  174. CREATE TABLE funcionarios OF tipo_funcionarios (
  175.     cpf PRIMARY KEY,
  176.     cpf_super WITH ROWID REFERENCES funcionarios
  177. );
  178.  
  179. CREATE TABLE telefones_funcionarios (
  180.   funcionario_cpf REF tipo_funcionarios,
  181.   lista_fones tipo_telefones_funcionarios
  182. );
  183.  
  184. CREATE TABLE enderecos_funcionarios OF tipo_enderecos_funcionarios (
  185.     cep PRIMARY KEY,
  186.     funcionario_cpf WITH rowid REFERENCES funcionarios
  187. );
  188.  
  189. CREATE TABLE clientes OF tipo_clientes (
  190.     cnpj PRIMARY KEY
  191. );
  192.  
  193. CREATE TABLE lista_telefones_clientes (
  194.   cliente_cnpj REF tipo_clientes,
  195.   lista_fones tipo_nt_telefones_clientes
  196. ) nested TABLE lista_fones store AS nt_lista_fones;
  197.  
  198. CREATE TABLE representantes OF tipo_representantes (
  199.     cpf_representante PRIMARY KEY,
  200.     empresa_cnpj WITH rowid REFERENCES clientes
  201. );
  202.  
  203. CREATE TABLE enderecos_clientes OF tipo_enderecos_clientes (
  204.   cep PRIMARY KEY,
  205.   cliente_cnpj WITH rowid REFERENCES clientes
  206. );
  207.  
  208. CREATE TABLE embarcacoes OF tipo_embarcacoes (
  209.     certificado PRIMARY KEY
  210. --tipo CHECK (tipo IN ('CONTEINEIRO', 'GASEIRO', 'VLCC', 'PETROLEIRO'))
  211. );
  212.  
  213. CREATE TABLE especificacoes OF tipo_especificacoes (
  214.     versao PRIMARY KEY,
  215.     certificado_embarcacao WITH rowid REFERENCES embarcacoes
  216. );
  217.  
  218. CREATE TABLE setores OF tipo_setores (
  219.     id PRIMARY KEY
  220. );
  221.  
  222. CREATE TABLE projetos_criacoes OF tipo_projetos_criacoes (
  223.     id PRIMARY KEY
  224. );
  225.  
  226. CREATE TABLE projetos_restauracoes OF tipo_projetos_restauracoes (
  227.     id PRIMARY KEY
  228. );
  229.  
  230. CREATE TABLE responsaveis_setores OF tipo_responsaveis_setores (
  231.     funcionario_cpf WITH rowid REFERENCES funcionarios,
  232.     setor_id WITH rowid REFERENCES setores
  233. );
  234.  
  235. CREATE TABLE execucoes_projetos OF tipo_execucoes_projetos (
  236.     setor_id WITH rowid REFERENCES setores,
  237.     projeto_id WITH rowid REFERENCES projetos_criacoes
  238. );
  239.  
  240. CREATE TABLE solicitacoes_projetos OF tipo_solicitacoes_projetos (
  241.   projeto_id WITH rowid REFERENCES projetos_criacoes,
  242.   embarcacao_certificado WITH rowid REFERENCES embarcacoes,
  243.   cliente_cnpj WITH rowid REFERENCES clientes
  244. );
  245.  
  246. CREATE TABLE equipamentos OF tipo_equipamentos (
  247.     id PRIMARY KEY
  248. );
  249.  
  250. CREATE TABLE compras_equipamentos OF tipo_compras_equipamentos (
  251.     equipamento_id WITH rowid REFERENCES equipamentos,
  252.     setor_id WITH rowid REFERENCES setores,
  253.     funcionario_cpf WITH rowid REFERENCES funcionarios
  254. );
  255.  
  256. CREATE TABLE manutencoes_equipamentos OF tipo_manutencoes_equipamentos (
  257.   DATA PRIMARY KEY,
  258.     equipamento_id WITH rowid REFERENCES equipamentos  
  259. --situacao CHECK (situacao IN ('PENDENTE', 'EM ANDAMENTO', 'CONCLUIDA'))
  260. );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement