This repository has been archived by the owner on Sep 28, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
pratica3.sql
127 lines (111 loc) · 3.81 KB
/
pratica3.sql
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
CREATE TABLE DEPARTAMENTO(
COD_DEPART NUMBER(4),
NOME VARCHAR2(100) NOT NULL,
DATA_INICIAL DATE,
CONSTRAINT PK_DEPARTAMENTO PRIMARY KEY (COD_DEPART)
)
//
CREATE TABLE LOCALIZACAO(
COD_DEPART NUMBER(4),
LOC_LOCAL VARCHAR2(252),
CONSTRAINT PK_LOCALIZACAO PRIMARY KEY (COD_DEPART, LOC_LOCAL),
CONSTRAINT FK_LOCALIZACAO_COD_DEPART
FOREIGN KEY (COD_DEPART) REFERENCES DEPARTAMENTO(COD_DEPART)
)
//
CREATE TABLE FUNCIONARIO(
COD_FUNC NUMBER(4),
FUNC_NOME VARCHAR2(100) NOT NULL,
FUNC_CPF VARCHAR2(15),
FUNC_SALARIO DECIMAL(4,2),
FUNC_ENDERECO VARCHAR2(252),
FUNC_SEXO CHAR(1),
COD_SUPER NUMBER(4),
COD_DEPART NUMBER(4),
CONSTRAINT UK_FUNCIONARIO_FUNC_CPF UNIQUE (FUNC_CPF),
CONSTRAINT CK_FUNCIONARIO_FUNC_SEXO CHECK (FUNC_SEXO IN ('M', 'F')),
CONSTRAINT CK_FUNCIONARIO_FUNC_SALARIO CHECK (FUNC_SALARIO > 1000),
CONSTRAINT PK_FUNCIONARIO PRIMARY KEY (COD_FUNC),
CONSTRAINT FK_FUNCIONARIO_COD_DEPART
FOREIGN KEY (COD_DEPART) REFERENCES DEPARTAMENTO(COD_DEPART),
CONSTRAINT FK_FUNCIONARIO_COD_SUPER
FOREIGN KEY (COD_SUPER) REFERENCES FUNCIONARIO(COD_FUNC)
)
//
CREATE TABLE DEPENDENTE(
COD_DEP NUMBER(4),
COD_FUNC NUMBER(4),
DEP_SEQ NUMBER(4),
DEP_NOME VARCHAR2(100) NOT NULL,
DEP_PARENTESCO VARCHAR2(30) NOT NULL,
DEP_DATA_NASC DATE,
CONSTRAINT CK_FUNCIONARIO_DEP_PARENTESCO
CHECK (DEP_PARENTESCO IN ('PAI','MAE', 'IRMAO', 'FILHO')),
CONSTRAINT PK_DEPENDENTE PRIMARY KEY (COD_DEP),
CONSTRAINT FK_FUNCIONARIO_COD_FUNC
FOREIGN KEY (COD_FUNC) REFERENCES FUNCIONARIO(COD_FUNC)
)
//
CREATE TABLE PROJETO(
COD_PROJ NUMBER(4),
COD_DEPART NUMBER(4),
PROJ_TITULO VARCHAR2(150) NOT NULL,
PROJ_DESCRICAO VARCHAR2(252),
PROJ_DATA_CAD DATE DEFAULT SYSDATE,
CONSTRAINT PK_PROJETO PRIMARY KEY (COD_PROJ),
CONSTRAINT FK_PROJETO_COD_DEPART
FOREIGN KEY (COD_DEPART) REFERENCES DEPARTAMENTO(COD_DEPART)
)
//
CREATE TABLE PARTICIPA(
COD_FUNC NUMBER(4),
COD_PROJ NUMBER(4),
PART_HORAS VARCHAR2(50),
CONSTRAINT PK_PARTICIPA PRIMARY KEY (COD_FUNC,COD_PROJ),
CONSTRAINT FK_PARTICIPA_COD_FUNC
FOREIGN KEY (COD_FUNC) REFERENCES FUNCIONARIO(COD_FUNC),
CONSTRAINT FK_PARTICIPA_COD_PROJ
FOREIGN KEY (COD_PROJ) REFERENCES PROJETO(COD_PROJ)
)
//
ALTER TABLE PROJETO ADD PROJ_STATUS NUMBER(1) CHECK (PROJ_STATUS IN (0, 1)) NOT NULL//
ALTER TABLE PROJETO MODIFY PROJ_TITULO VARCHAR2(252)//
ALTER TABLE PROJETO RENAME COLUMN PROJ_DATA_CAD TO PROJ_DATA_CADASTRO//
CREATE TABLE ENDERECO(
COD_END NUMBER(4),
END_ENDERECO VARCHAR2(150) NOT NULL,
CONSTRAINT PK_ENDERECO PRIMARY KEY (COD_END)
)
//
CREATE TABLE FUNCIONARIO_ENDERECO(
COD_END NUMBER(4),
COD_FUNC NUMBER(4),
CONSTRAINT PK_FUNCIONARIO_ENDERECO PRIMARY KEY (COD_END, COD_FUNC),
CONSTRAINT FK_FUNC_END_COD_FUNC
FOREIGN KEY (COD_FUNC) REFERENCES FUNCIONARIO(COD_FUNC),
CONSTRAINT FK_FUNC_END_COD_END
FOREIGN KEY (COD_END) REFERENCES ENDERECO(COD_END)
)
//
ALTER TABLE FUNCIONARIO DROP COLUMN FUNC_ENDERECO//
ALTER TABLE FUNCIONARIO DROP CONSTRAINT CK_FUNCIONARIO_FUNC_SALARIO//
ALTER TABLE FUNCIONARIO DISABLE CONSTRAINT UK_FUNCIONARIO_FUNC_CPF//
ALTER TABLE FUNCIONARIO ENABLE CONSTRAINT UK_FUNCIONARIO_FUNC_CPF//
CREATE TABLE PARENTESCO(
COD_PAR NUMBER(4),
PAR_DESCRICAO VARCHAR2(50),
CONSTRAINT PK_PARENTESCO PRIMARY KEY (COD_PAR)
)
//
ALTER TABLE DEPENDENTE ADD COD_PAR NUMBER//
ALTER TABLE DEPENDENTE ADD CONSTRAINT FK_DEPENDENTE_COD_PAR
FOREIGN KEY (COD_PAR) REFERENCES PARENTESCO(COD_PAR)//
ALTER TABLE DEPENDENTE DROP COLUMN DEP_PARENTESCO//
ALTER TABLE DEPENDENTE ADD DEP_CPF VARCHAR2(15)//
ALTER TABLE DEPENDENTE ADD CONSTRAINT
UK_DEPENDENTE_DEP_CPF UNIQUE (DEP_CPF)//
ALTER TABLE DEPENDENTE DROP CONSTRAINT FK_FUNCIONARIO_COD_FUNC//
ALTER TABLE DEPENDENTE ADD CONSTRAINT FK_FUNCIONARIO_COD_FUNC
FOREIGN KEY (COD_FUNC) REFERENCES FUNCIONARIO(COD_FUNC)
ON DELETE CASCADE//
RENAME PARTICIPA TO FUNC_PROJETO//