Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
80 changes: 80 additions & 0 deletions Test_Sql/CreateTableProduto.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
IF NOT EXISTS (SELECT * FROM sys.tables WHERE name = 'Produto')
BEGIN
PRINT 'Creating Product table';
CREATE TABLE Produto (
Id INT PRIMARY KEY,
Nome VARCHAR(255)
);
END

IF NOT EXISTS (SELECT * FROM sys.tables WHERE name = 'VendaDetalhe')
BEGIN
PRINT 'Creating VendaDetalhe table';
CREATE TABLE VendaDetalhe (
Id INT PRIMARY KEY,
Vendasid INT,
Quantidade INT,
Valor DECIMAL(10,2),
Produtold INT,
FOREIGN KEY (Produtold) REFERENCES Produto(Id)
);
END

IF NOT EXISTS (SELECT * FROM sys.tables WHERE name = 'Validade')
BEGIN
PRINT 'Creating Validade table';
CREATE TABLE Validade (
Validadeld INT PRIMARY KEY,
EstoqueProduto INT,
Dias INT
);
END

IF NOT EXISTS (SELECT * FROM sys.tables WHERE name = 'EstoqueProduto')
BEGIN
PRINT 'Creating EstoqueProduto table';
CREATE TABLE EstoqueProduto (
Id INT PRIMARY KEY,
Produtold INT,
FOREIGN KEY (Produtold) REFERENCES Produto(Id)
);
END

IF NOT EXISTS (SELECT * FROM sys.tables WHERE name = 'EstoqueProduto')
BEGIN
PRINT 'Creating EstoqueProduto table';
CREATE TABLE EstoqueProduto (
Id INT PRIMARY KEY,
Produtold INT,
FOREIGN KEY (Produtold) REFERENCES Produto(Id)
);
END

IF NOT EXISTS (SELECT * FROM sys.tables WHERE name = 'MovimentoEstoque')
BEGIN
PRINT 'Creating MovimentoEstoque table';
CREATE TABLE MovimentoEstoque (
Id INT PRIMARY KEY,
EstoqueProdutold INT,
Quantidade INT,
Data DATE,
TipoMovimentold INT,
VendaDetalheld INT,
FOREIGN KEY (EstoqueProdutold) REFERENCES EstoqueProduto(Id),
FOREIGN KEY (VendaDetalheld) REFERENCES VendaDetalhe(Id)
);
END

IF NOT EXISTS (SELECT * FROM sys.tables WHERE name = 'TipoMovimento')
BEGIN
PRINT 'Creating TipoMovimento table';
CREATE TABLE TipoMovimento (
Id INT PRIMARY KEY,
Descricao VARCHAR(255),
CHECK (Descricao IN ('Entrada', 'Saida'))
);
END

SELECT *
FROM Produto p
INNER JOIN TipoMovimento tm ON p.Nome = tm.Descricao AND tm.Descricao IS NOT NULL;
4 changes: 4 additions & 0 deletions Test_Sql/test.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
-- END: Test if table Produto is created successfully
-- BEGIN: Test if table Produto is created successfully
SELECT COUNT(*) FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'Produto';
-- END: Test if table Produto is created successfully