Created
November 12, 2014 13:07
-
-
Save dibikhin/1fe2425cd03c1869943b to your computer and use it in GitHub Desktop.
T-SQL insert test returning Id of a new row
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CREATE TABLE Customers | |
( | |
Id INT IDENTITY(1,1) NOT NULL, | |
Name NVARCHAR(255) NOT NULL | |
); | |
GO | |
SET IDENTITY_INSERT Customers OFF; | |
CREATE PROCEDURE CustomerAdd | |
( | |
@CustomerName NVARCHAR(255), | |
@Id INT OUTPUT | |
) | |
AS | |
BEGIN | |
INSERT INTO Customers | |
(Name) | |
VALUES | |
(@CustomerName); | |
SET @Id = SCOPE_IDENTITY(); | |
END; | |
GO | |
DECLARE @NewId INT | |
EXEC CustomerAdd 'Jimmy', @NewId OUTPUT | |
SELECT @NewId |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment