Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 SQL Server Administration (2005)
 Executing A sequence via Trigger

Author  Topic 

rocking25
Starting Member

5 Posts

Posted - 2009-01-12 : 06:42:22
I am using SQL SERVER 2005. I have a table named 'Punchdata' with four primary key. But I want a column named 'PunchdataID',I can't declare that column as a Primary Key.

So I want to creat a sequence which should execute when a new row is inserted in the table. and the PunchdataID should get auto incremented.

So I want a Sequence and a trigger to execute that sequence. If sequence is not required than it will better.

darkdusky
Aged Yak Warrior

591 Posts

Posted - 2009-01-13 : 10:47:44
No need for trigger etc, make the column an IDENTITY column
e.g.
alter TABLE Punchdata
add [PunchdataID] [int] IDENTITY(1,1) NOT NULL
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2009-01-13 : 12:13:04
and if its a custom sequence you want which is autogenerated you can create a computed column based on identity column value for that
Go to Top of Page
   

- Advertisement -