-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbanco.sql
40 lines (31 loc) · 946 Bytes
/
banco.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
CREATE DATABASE aula_13_10;
USE aula_13_10;
CREATE TABLE setor (
id INT AUTO_INCREMENT PRIMARY KEY,
nome VARCHAR(50) NOT NULL
);
CREATE TABLE funcionarios(
id INT AUTO_INCREMENT PRIMARY KEY,
primeiro_nome VARCHAR(50) NOT NULL,
sobrenome VARCHAR(50) NOT NULL,
data_admissao DATE NOT NULL,
status_funcionario BOOL NOT NULL,
id_setor INT,
FOREIGN KEY (id_setor) REFERENCES setor(id)
);
SELECT * FROM setor;
SELECT * FROM cargos;
UPDATE cargos
SET id_setor = 2
WHERE id = 4;
ALTER TABLE funcionarios ADD COLUMN cargo VARCHAR(50) NOT NULL;
ALTER TABLE funcionarios DROP COLUMN cargo;
CREATE TABLE cargos(
id INT AUTO_INCREMENT PRIMARY KEY,
nome VARCHAR(50),
id_setor INT,
FOREIGN KEY (id_setor) REFERENCES setor(id)
);
ALTER TABLE cargos MODIFY COLUMN nome VARCHAR(50) NOT NULL;
ALTER TABLE funcionarios ADD COLUMN id_cargo INT;
ALTER TABLE funcionarios ADD FOREIGN KEY (id_cargo) REFERENCES cargos(id);