/ Published in: SQL
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE PROCEDURE TestApp_UserCreate @Name NVARCHAR(128), @DateOfBirth DATE, @IdentityCard NVARCHAR(64) = NULL, @Nickname NVARCHAR(128) = NULL, @Email NVARCHAR(128), @Gender BIT, @MaritalStatusID SMALLINT = NULL, @NumberOfChildren SMALLINT = NULL, @UserID INT OUTPUT AS BEGIN BEGIN TRANSACTION INSERT INTO Users(Name, DateOfBirth, IdentityCard, Nickname, Email, Gender, MaritalStatusID, NumberOfChildren, CreateDate) VALUES(@Name, @DateOfBirth, @IdentityCard, @Nickname, @Email, @Gender, @MaritalStatusID, @NumberOfChildren, GETDATE()) IF(@@ERROR <> 0) BEGIN ROLLBACK TRANSACTION END ELSE BEGIN SELECT TOP 1 @UserID = UserID FROM Users ORDER BY CreateDate DESC COMMIT TRANSACTION END END GO