daily pastebin goal
53%
SHARE
TWEET

Untitled

a guest Feb 22nd, 2019 51 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. CREATE TABLE dbo.TEST
  2. (
  3.    ID INT IDENTITY(1, 1) NOT NULL
  4.    CONSTRAINT PK_TEST_ID PRIMARY KEY CLUSTERED ( [ID] ASC )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON)
  5. )
  6.    
  7. CREATE PROCEDURE test_create @ID INT OUTPUT
  8. AS
  9.   BEGIN
  10.       -- SET NOCOUNT ON added to prevent extra result sets from
  11.       -- interfering with SELECT statements.
  12.       SET NOCOUNT ON;
  13.  
  14.       INSERT INTO TEST
  15.       DEFAULT VALUES
  16.  
  17.       SELECT @ID = SCOPE_IDENTITY()
  18.   END
  19.    
  20. DECLARE @ID INT
  21.  
  22. EXEC AZURE01.TestDB.dbo.test_create @ID OUTPUT
  23. SELECT @ID
  24.  
  25. INSERT INTO AZURE01.TestDB.dbo.TEST DEFAULT VALUES
  26. SELECT @ID = SCOPE_IDENTITY();
  27. SELECT @ID
  28.  
  29. INSERT INTO AZURE01.TestDB.dbo.TEST DEFAULT VALUES
  30. SELECT @ID = @@IDENTITY
  31. SELECT @ID
  32.  
  33. SELECT * FROM OPENQUERY(AZURE01, 'INSERT INTO TestDB.dbo.TEST DEFAULT VALUES; SELECT SCOPE_IDENTITY() AS ID');
  34.  
  35. DECLARE @ScopeIdentity TABLE (ID int);
  36. INSERT INTO @ScopeIdentity
  37. EXEC AZURE01.master..sp_executesql N'
  38.  ¬†INSERT TestDB.dbo.TEST DEFAULT VALUES;
  39.  ¬†SELECT SCOPE_IDENTITY()';
  40. SELECT * FROM @ScopeIdentity;
  41.  
  42. INSERT AZURE01.TestDB.dbo.TEST
  43. OUTPUT inserted.ID
  44. INTO @ScopeIdentity
  45. DEFAULT VALUES
  46. SELECT * FROM @ScopeIdentity
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top