-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patherror_handling.sql
More file actions
32 lines (30 loc) · 850 Bytes
/
Copy patherror_handling.sql
File metadata and controls
32 lines (30 loc) · 850 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
ALTER PROC usp_UpdateStudent
@Id INT, @Name VARCHAR(50), @Email VARCHAR(100)
AS
BEGIN
BEGIN TRY
BEGIN TRANSACTION
IF(NOT EXISTS(SELECT * FROM tblStudents WHERE Id=@Id))
BEGIN
RAISERROR('Student with given Id not found',16,1)
END
UPDATE tblStudents SET Name = @Name WHERE Id=@Id
IF(EXISTS(SELECT Email FROM tblStudents WHERE Id<>@Id AND Email=@Email))
BEGIN
RAISERROR('Already exist the provided email, try with another email address',16,1)
END
UPDATE tblStudents SET Email=@Email WHERE Id=@Id
COMMIT TRAN
END TRY
BEGIN CATCH
ROLLBACK TRANSACTION
SELECT
ERROR_NUMBER() AS ErrNumber,
ERROR_MESSAGE() AS ErrMessage,
ERROR_PROCEDURE() AS ErrProcedure,
ERROR_STATE() AS ErrState,
ERROR_LINE() AS ErrLine
END CATCH
END
EXEC usp_UpdateStudent 1, 'Ashiqs','mralex@gmail.com'
SELECT * FROM tblStudents