Re: complex inserting
From: Anith Sen (anith_at_bizdatasolutions.com)
Date: 11/01/04
- Next message: Ilya Margolin: "Re: data dictionary relation problem"
- Previous message: fvauser: "Update Statement"
- In reply to: Renjith Chembakarayil: "Re: complex inserting"
- Next in thread: Renjith Chembakarayil: "Re: complex inserting"
- Reply: Renjith Chembakarayil: "Re: complex inserting"
- Messages sorted by: [ date ] [ thread ]
Date: Mon, 1 Nov 2004 11:34:56 -0600
Renjith,
When you have an identity column in a t-SQL table, SCOPE_IDENTITY() function
can return the newly inserted identity column value within the the same
scope ( Note that, in previous versions @@IDENTITY was used which had global
scope ). So, for instance when you do:
INSERT Invoices ( col1, col2.. )
VALUES ( val1, val2,... );
SELECT SCOPE_IDENTITY()
-- will return the newly inserted value for InvoiceGID
In a well modularized stored procedure, you can extract the newly inserted
indentity value in a local variable & insert into the referencing columns in
other tables like CompanyInvoice, BranchInvoice & so forth.
There are other related functions like IDENT_CURRENT which gives the last
identity value generated for a specified table in any session and any scope.
You can find all the details about @@IDENTITY, SCOPE_IDENTITY() and
IDENT_CURRENT along with specific examples, if you spend some time with SQL
Server Books Online.
-- Anith
- Next message: Ilya Margolin: "Re: data dictionary relation problem"
- Previous message: fvauser: "Update Statement"
- In reply to: Renjith Chembakarayil: "Re: complex inserting"
- Next in thread: Renjith Chembakarayil: "Re: complex inserting"
- Reply: Renjith Chembakarayil: "Re: complex inserting"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|