-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdata.sql
75 lines (62 loc) · 1.9 KB
/
data.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
CREATE TABLE PESSOA(
NOME VARCHAR(50),
CPF VARCHAR(11),
DATA_NASC DATE,
MATRICULA INT NOT NULL PRIMARY KEY,
TELEFONE VARCHAR(20),
EMAIL VARCHAR(50),
SENHA VARCHAR(30)
);
CREATE TABLE ALUNO(
MATRICULA INT NOT NULL PRIMARY KEY,
fk_turma integer
)INHERITS(PESSOA);
CREATE TABLE FUNCIONARIO(
SALARIO FLOAT,
CARGA_H INTEGER
)INHERITS(PESSOA);
CREATE TABLE PROFESSOR(
MATRICULA INT NOT NULL PRIMARY KEY,
AREA VARCHAR(30),
NIVEL VARCHAR(30)
)INHERITS(FUNCIONARIO);
CREATE TABLE TECNICO(
MATRICULA INT NOT NULL PRIMARY KEY,
SETOR VARCHAR(30)
)INHERITS(FUNCIONARIO);
CREATE TABLE TURMA(
CODIGO INT NOT NULL PRIMARY KEY,
NOME VARCHAR(40)
);
ALTER TABLE ALUNO
ADD CONSTRAINT FK_TURMA FOREIGN KEY (fk_turma) REFERENCES TURMA (CODIGO);
create table diarios( cod_dos_diarios int not null primary key);
create table diario(
codigo int not null primary key,
disciplina varchar(15),
professor varchar(30),
fk_aluno integer,
fk_turma integer,
fk_notas integer
);
create table notas(
codigo int not null primary key,
mat integer,
B1 float,
B2 float,
B3 float,
B4 float
);
alter table diario add constraint fk_turma foreign key(fk_turma) references turma (codigo);
alter table diario add constraint fk_aluno foreign key(fk_aluno) references ALUNO (MATRICULA);
alter table diario add constraint fk_notas foreign key(fk_notas) references notas (codigo);
alter table NOTAS add constraint fk_mat foreign key (mat) references ALUNO (MATRICULA);
create table funcao(
id int not null primary key,
nome_func varchar(20)
);
alter table pessoa add column id_func integer;
alter table pessoa add constraint fk_func foreign key(id_func) references funcao (id);
insert into funcao values(1, 'ALUNO');
insert into funcao values(2, 'PROFESSOR');
insert into funcao values(3, 'TÉCNICO');