Thursday, 17 June 2010

How To Found Current Identity No

this is any tabel we get currnt identity
synatax: select ident_current('TABELNAME')
select ident_current('system1k.dbo.menu')


and SELECT @@IDENTITY;
this is used only when ever user insert rows using query then uwrite blow which is the identity then u use this statement

ex:INSERT INTO menu values( 'ggdg','dgytdytd','true','true',6,'tyu')
SELECT @@IDENTITY;

then display the current IDENTITY value

USE TempDB
GO
CREATE TABLE tst
( a int identity(1,1), s varchar(10))
GO
USE TempDB

CREATE TABLE tst2
( a int identity(1000,1), s varchar(10))
USE TempDB
GO
CREATE TRIGGER dbo.trgTst
ON tst
AFTER INSERT
AS INSERT tst2 SELECT inserted.s FROM inserted
GO
INSERT tst VALUES('a')
SELECT
@@IDENTITY AS [@@IDENTITY],
SCOPE_IDENTITY() AS [SCOPE_IDENTITY()]
GO
DROP TABLE tst2
DROP TABLE tst

No comments:

Post a Comment