Re: Getting the Number from the next automatic increment
From: Steve _at_ BT (_at_)
Date: 04/25/04
- Next message: sunitha: "how to delete log files"
- Previous message: Uri Dimant: "Re: sp_sqlagent_get_perf_counters (was: Updating statistics)"
- In reply to: Greg O: "Re: Getting the Number from the next automatic increment"
- Messages sorted by: [ date ] [ thread ]
Date: Sun, 25 Apr 2004 11:24:33 +0000 (UTC)
Thanks Greg,
"Greg O" <greg-No-SPAM@No-SPAM.com> wrote in message
news:O4rJHpdKEHA.892@TK2MSFTNGP09.phx.gbl...
> Hi Steve,
> Here is a extract from BOL
>
> IDENT_CURRENT is similar to the Microsoft® SQL ServerT 2000 identity
> functions SCOPE_IDENTITY and @@IDENTITY. All three functions return
> last-generated identity values. However, the scope and session on which
> 'last' is defined in each of these functions differ.
>
> a.. IDENT_CURRENT returns the last identity value generated for a
specific
> table in any session and any scope.
>
>
> b.. @@IDENTITY returns the last identity value generated for any table
in
> the current session, across all scopes.
>
>
> c.. SCOPE_IDENTITY returns the last identity value generated for any
table
> in the current session and the current scope.
>
> What this means is that normally people use @@identity like this
>
> insert into Call_log(Name) values('Fred');select SCOPE_IDENTITY()
>
>
> but if you have a trigger on the table that say inserts a row into a
> different table then it might have an identity as well. So the value from
> @@identity won't be what you think. So you can use
>
> insert into Call_log(Name) values('Fred');select
SCOPE_IDENTITY("Call_log")
>
> now if you wanted the identity from the other table that the trigger
updated
> you could do
>
> insert into Call_log(Name) values('Fred');select
> SCOPE_IDENTITY("TriggerupdatedTable")
>
> for more scripts go to http://www.SQL-Scripts.com
> --
> I hope this helps
> --------------------------------
> Greg O
> Looking for SQL Scripts, Need Help? http://www.SQL-Scripts.com
> Document all your databases now.
> http://www.ag-software.com/ags_scribe_index.aspx
> Crosstab queries from SQL Server.
> http://www.ag-software.com/xp_ags_crosstab.aspx
> Edit Extended Properties as easy as can be.
> http://www.ag-software.com/ags_SSEPE_index.aspx
>
>
> "Steve @ BT" <stevenriley@btopenworld.com> wrote in message
> news:c6d81u$ca0$1@hercules.btinternet.com...
> Hi All
> I have a Table which generats a automatic number when i add a new record
>
> how do i get that number that has been been added
>
> e.g. My table is
>
> CREATE TABLE [dbo].[Call_Log] (
> [Ref] SMALLINT NOT NULL IDENTITY(1,1),
> [Name] [varchar] (50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL)
>
> when i add a new record, how do i get the Ref number it has created.
>
> Thanks
> Steve
>
>
>
- Next message: sunitha: "how to delete log files"
- Previous message: Uri Dimant: "Re: sp_sqlagent_get_perf_counters (was: Updating statistics)"
- In reply to: Greg O: "Re: Getting the Number from the next automatic increment"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|