forked from rafaelyudji/mscode-projeto-estoque
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcreate.sql
More file actions
42 lines (42 loc) · 1.18 KB
/
create.sql
File metadata and controls
42 lines (42 loc) · 1.18 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
-- Create categoria table
CREATE TABLE categoria (
id INT PRIMARY KEY AUTO_INCREMENT,
nome VARCHAR(50) NOT NULL
);
-- Create produto table
CREATE TABLE produto (
id INT PRIMARY KEY AUTO_INCREMENT,
nome VARCHAR(100) NOT NULL,
descricao TEXT,
categoria_id INT,
data_cadastro DATETIME DEFAULT CURRENT_TIMESTAMP,
quantidade_inicial INT,
quantidade_disponivel INT,
valor INT,
FOREIGN KEY (categoria_id) REFERENCES categoria(id)
);
-- Create usuario table
CREATE TABLE usuario (
id INT PRIMARY KEY AUTO_INCREMENT,
nome VARCHAR(100) NOT NULL,
email VARCHAR(100) NOT NULL UNIQUE,
senha VARCHAR(255) NOT NULL
);
-- Create venda table
CREATE TABLE venda (
id INT PRIMARY KEY AUTO_INCREMENT,
data_venda DATETIME DEFAULT CURRENT_TIMESTAMP,
cliente_id INT,
status ENUM('pendente', 'finalizada', 'cancelada') NOT NULL DEFAULT 'pendente',
FOREIGN KEY (cliente_id) REFERENCES usuario(id)
);
-- Create venda_item table
CREATE TABLE venda_item (
id INT PRIMARY KEY AUTO_INCREMENT,
venda_id INT,
produto_id INT,
quantidade INT NOT NULL,
preco_unitario DECIMAL(10, 2) NOT NULL,
FOREIGN KEY (venda_id) REFERENCES venda(id),
FOREIGN KEY (produto_id) REFERENCES produto(id)
);