-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathschema e tabelas.sql
More file actions
45 lines (36 loc) · 1006 Bytes
/
schema e tabelas.sql
File metadata and controls
45 lines (36 loc) · 1006 Bytes
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
--criando um schema
create schema clube_do_livro;
--criando tabelas
create table clube_do_livro.livros(
id_livro int not null,
nome_livro varchar(100) not null,
autoria varchar(100) not null,
editora varchar(100) not null,
categoria varchar(100) not null,
preco decimal(5,2) not null,
primary key (id_livro)
);
create table clube_do_livro.estoque (
id_livro int not null,
qtd_estoque int not null,
primary key (id_livro)
);
create table clube_do_livro.vendas (
id_pedido int not null,
id_vendedor int not null,
id_livro int not null,
qtd_vendida int not null,
data_venda date not null,
primary key (id_vendedor, id_pedido)
);
create table clube_do_livro.vendedores (
id_vendedor int not null,
nome_vendedor varchar(255) not null,
primary key (id_vendedor)
);
--alterando tabela
alter table clube_do_livro.estoque add constraint ce_estoque_livros
foreign key (id_livro)
references clube_do_livro.livros (id_livro)
on delete no action
on update no action;