Elegabalus
Programmer
I've got a simple question:
I'm building a web-based app, and I'm wondering what is the best way to get a single value out of the database? For instance, if I'm inserting a record into a table, and I want to get the identity value back out, should I be using an OUTPUT variable, a return value, or simply Selecting the identity?
i.e., which way is best:
1)
2)
3)
As far as I am aware, all three of these methods work, but I'm just wondering which is the best way, and if there are any downsides to any of them.
I'm building a web-based app, and I'm wondering what is the best way to get a single value out of the database? For instance, if I'm inserting a record into a table, and I want to get the identity value back out, should I be using an OUTPUT variable, a return value, or simply Selecting the identity?
i.e., which way is best:
1)
Code:
DECLARE @Identity int OUTPUT
INSERT (...)
VALUES (...)
SET @Identity = SCOPE_IDENTITY()
2)
Code:
INSERT (...)
VALUES (...)
RETURN SCOPE_IDENTITY()
3)
Code:
INSERT (...)
VALUES (...)
SELECT SCOPE_IDENTITY()
As far as I am aware, all three of these methods work, but I'm just wondering which is the best way, and if there are any downsides to any of them.