-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStoredProcedure.sql
More file actions
88 lines (75 loc) · 2.15 KB
/
StoredProcedure.sql
File metadata and controls
88 lines (75 loc) · 2.15 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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
-- Create AddSightseeing stored procedure
CREATE OR ALTER PROCEDURE AddSightseeing
@SightseeingId INT,
@DestinationId INT,
@Name VARCHAR(50),
@Description VARCHAR(255)
AS
BEGIN
INSERT INTO Sightseeing (SightseeingId ,DestinationId, Name, Description)
VALUES (@SightseeingId,@DestinationId, @Name, @Description);
END;
GO
BEGIN TRANSACTION
-- Kör AddSightseeing-proceduren
SELECT * FROM dbo.Sightseeing
EXEC AddSightseeing @SightseeingId = 11 ,@DestinationId = 5, @Name = 'Royal Palace', @Description = 'Historic royal residence';
SELECT * FROM dbo.Sightseeing
ROLLBACK
-- Create AddComment stored procedure
CREATE OR ALTER PROCEDURE AddComment
@CommentId INT,
@SightseeingId INT,
@UserId INT,
@Comment VARCHAR(255)
AS
BEGIN
INSERT INTO Comment ( CommentId, SightseeingId, UserId, Comment)
VALUES (@CommentId, @SightseeingId, @UserId, @Comment);
END;
GO
BEGIN TRANSACTION
-- Kör AddComment-proceduren
SELECT * FROM dbo.Comment
EXEC AddComment @CommentId= 61 , @Comment = 'VERI VERI NICE' , @SightseeingId = 10, @UserId = 4 ;
SELECT * FROM dbo.Comment
ROLLBACK
-- Create AddRating stored procedure
CREATE OR ALTER PROCEDURE AddRating
@RatingValue DECIMAL(3, 1),
@CommentId INT
AS
BEGIN
UPDATE Comment
SET RatingValue = @RatingValue
WHERE CommentId = @CommentId
END;
GO
BEGIN TRANSACTION
-- Kör AddRating-proceduren
SELECT * FROM dbo.Comment
EXEC AddRating @CommentId = 60 , @RatingValue = 3 ;
SELECT * FROM dbo.Comment
ROLLBACK
-- Create AddUser stored procedure
CREATE OR ALTER PROCEDURE AddUser
@UserId INT,
@Username VARCHAR(50),
@Password VARCHAR(50),
@Email VARCHAR(100)
AS
BEGIN
INSERT INTO [User] (UserId, Username, Password, Email)
VALUES ( @UserId , @Username, @Password, @Email);
END;
GO
BEGIN TRANSACTION
-- Kör AddUser-proceduren
SELECT * FROM dbo.[User]
EXEC AddUser @UserId = 6 , @Username = 'Daniella' , @Password = 'password123' , @Email = 'Daniella.bwedne@gmail.com' ;
SELECT * FROM dbo.[User]
ROLLBACK
--DROP PROCEDURE IF EXISTS AddSightseeing;
--DROP PROCEDURE IF EXISTS AddComment;
-- DROP PROCEDURE IF EXISTS AddRating;
-- DROP PROCEDURE IF EXISTS AddUser;