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
/
pratica2.sql
77 lines (71 loc) · 2.15 KB
/
pratica2.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
CREATE TABLE DEPARTAMENTO(
COD_DEPART NUMBER,
NOME VARCHAR2(100) NOT NULL,
DATA_INICIAL DATE,
CONSTRAINT PK_DEPARTAMENTO PRIMARY KEY (COD_DEPART)
)
//
CREATE TABLE LOCALIZACAO(
COD_LOC NUMBER,
COD_DEPART NUMBER,
LOC_LOCAL VARCHAR2(252),
CONSTRAINT PK_LOCALIZACAO PRIMARY KEY (COD_LOC),
CONSTRAINT FK_LOCALIZACAO_COD_DEPART
FOREIGN KEY (COD_DEPART) REFERENCES DEPARTAMENTO(COD_DEPART)
)
//
CREATE TABLE FUNCIONARIO(
COD_FUNC NUMBER,
FUNC_NOME VARCHAR2(100) NOT NULL,
FUNC_CPF VARCHAR2(15),
FUNC_SALARIO DECIMAL(4,2),
FUNC_ENDERECO VARCHAR2(252),
FUNC_SEXO CHAR,
COD_SUPER NUMBER,
COD_DEPART NUMBER,
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,
COD_FUNC NUMBER,
DEP_SEQ NUMBER,
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,
COD_DEPART NUMBER,
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,
COD_PROJ NUMBER,
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)
)
//