Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
From VFP auto incremental key to SQL Server
Message
From
16/10/2006 02:47:37
 
 
To
16/10/2006 02:35:21
General information
Forum:
Microsoft SQL Server
Category:
Import/Export
Miscellaneous
Thread ID:
01162137
Message ID:
01162167
Views:
20
OK. In SQL 2005, you can actually include the OUTPUT keyword into an INSERT statement.

Here's an example that creates a table variable with an identity column, inserts a new row, and outputs the value of the identity column as a result set.

You can also use the scope_identity that I mentioned before, or you can use this.
DECLARE @tTestTable TABLE ( MyIdentityCol int IDENTITY, Name char(100))

 
INSERT INTO @tTestTable 
	OUTPUT Inserted.MyIdentityCol    
               VALUES ('KEVIN')   
Note the reference to 'inserted'....this, along with 'deleted' were two system tables previously available only in insert/update triggers. They're now accessible during an insert/update statement/delete statement.

Not trying to overload you, but figured it might be worth knowing down the road.

Kevin
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform