-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProcedures.sql
More file actions
41 lines (33 loc) · 1.32 KB
/
Procedures.sql
File metadata and controls
41 lines (33 loc) · 1.32 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
USE Exercicio
-- Exemplo: Crie uma procedure para cadastrar uma nova assinatura de um contrato na tabela fContratos (com parâmetros).
-- Gerente: Lucas Sampaio
-- Cliente: Gustavo Barbosa
-- Valor do Contrato: 5000
-- 1º Passo: Definir as variáveis a serem utilizadas.
-- 2º Passo: Armazenar o valor de id_gerente de acordo com o gerente associado
-- 3º Passo: Armazenar o valor de id_cliente de acordo com o nome do cliente
-- 4º Passo: Armazenar a data da assinatura como sendo a data atual do sistema
-- 5º Passo: Utilizar o INSERT INTO para inserir os dados na tabela fContratos
CREATE OR ALTER PROCEDURE prRegistraContrato(@gerente VARCHAR(MAX), @cliente VARCHAR(MAX), @valor FLOAT)
AS
BEGIN
DECLARE
@vIDGerente INT,
@vIDCliente INT
SELECT
@vIDGerente = id_gerente
FROM
dGerente
WHERE nome_gerente = @gerente
SELECT
@vIDCliente = id_cliente
FROM
dCliente
WHERE nome_cliente = @cliente
INSERT INTO fContratos(data_assinatura, id_cliente, id_gerente, valor_contrato) VALUES(GETDATE(), @vIDCliente, @vIDGerente, @valor)
PRINT 'Contrato registrado com sucesso'
EXECUTE prRegistraContrato @gerente='Lucas Sampaio', @cliente = 'Gustavo Barbosa', @valor=5000
SELECT * FROM fContratos
-- DELETE FROM fContratos WHERE id_contrato >= 1002 (Correção de bug no IDENTITY de ID)
DBCC CHECKIDENT ('fContratos', RESEED, 11);
END