-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSQL5.sql
More file actions
82 lines (65 loc) · 1.95 KB
/
Copy pathSQL5.sql
File metadata and controls
82 lines (65 loc) · 1.95 KB
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
Create Table Alunos (
id_aluno int Primary Key NOT NULL,
nome varchar(200) NOT NULL,
data_nascimento date NOT NULL,
sexo varchar(1) NOT NULL, --M para Masculino ou F para Feminino
data_cadastro datetime NOT NULL,
login_cadastro varchar(15) NOT NULL,
);
Alter Table Alunos
DROP CONSTRAINT fk_Turmas;
--DROP TABLE Alunos;
Create Table Situacao(
id_situacao int PRIMARY KEY NOT NULL,
situacao varchar(25) NOT NULL,
data_cadastro datetime,
login_cadastro varchar(15),
);
Create Table Cursos(
id_cursos int PRIMARY KEY NOT NULL,
nome_cursos varchar(200) NOT NULL,
data_cadastro datetime not null,
login_cadastro varchar(15) not null
);
Create Table Turmas(
id_turma int PRIMARY KEY NOT NULL,
id_aluno int NOT NULL,
id_cursos int NOT NULL,
valor_turma numeric(15,2) NOT NULL,
desconto numeric (3,2) NOT NULL,
data_inicio date NOT NULL,
data_termino date,
data_cadastro datetime not null,
login_cadastro varchar(15) not null
);
Create table Registro_Presenca
(
id_turma int not null,
id_aluno int not null,
id_situacao int not null,
data_presenca date not null,
data_cadastro date not null,
login_cadastro varchar(15) not null
);
Alter Table Turmas
ADD CONSTRAINT fk_Curso FOREIGN KEY (id_cursos) REFERENCES Cursos (id_cursos);
Alter Table Turmas
ADD CONSTRAINT fk_Alunos FOREIGN KEY (id_aluno) REFERENCES Alunos (id_aluno);
Alter Table Registro_Presenca
ADD CONSTRAINT fk_TurmasRP FOREIGN KEY (id_turma) REFERENCES Turmas (id_turma);
Alter Table Registro_Presenca
ADD CONSTRAINT fk_AlunoRP FOREIGN KEY (id_aluno) REFERENCES Alunos (id_aluno);
Alter Table Registro_Presenca
ADD CONSTRAINT fk_SituacaoRP FOREIGN KEY (id_situacao) REFERENCES Situacao (id_situacao);
/*
drop table Turmas;
drop table Situacao;
drop table Registro_Presenca;
drop table Cursos;
drop table Alunos;
*/
insert into dbo.Alunos
(id_aluno, nome, data_nascimento, sexo, data_cadastro, login_cadastro)
VALUES
(2, 'Ralf Chen', '01/01/2001', 'M', '19/07/2021 13:57:23', 'Amorim')
Select * FROM dbo.Alunos;