Re: complex inserting
From: Renjith Chembakarayil (RenjithChembakarayil_at_discussions.microsoft.com)
Date: 11/02/04
- Next message: Dan Guzman: "Re: HowTo: Append data to a table stored in another database?"
- Previous message: Louis Davidson: "Re: Inner Join Where Not Null"
- In reply to: Anith Sen: "Re: complex inserting"
- Messages sorted by: [ date ] [ thread ]
Date: Mon, 1 Nov 2004 21:25:02 -0800
thanx anith, i'll try this out..
one more thing .. ive explained my problem and asked for a solution which i
thought was the best way to use the relationships factor in tables
now is there a better way to do this or is my understanding of the
relationship table wrong?
Renjith
"Anith Sen" wrote:
> 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: Dan Guzman: "Re: HowTo: Append data to a table stored in another database?"
- Previous message: Louis Davidson: "Re: Inner Join Where Not Null"
- In reply to: Anith Sen: "Re: complex inserting"
- Messages sorted by: [ date ] [ thread ]