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
 Transact-SQL (2005)
 Creating IdentityValue

Author  Topic 

baburk
Posting Yak Master

108 Posts

Posted - 2009-03-20 : 06:58:38
Hi,

I am creating my own IdentityValue like b1, b2,..

I truncated the table Test

Truncate table dbo.Test

SELECT 'b'+ CONVERT(VARCHAR, (IDENT_CURRENT ('dbo.Test'))) AS Current_Identity;
GO

b1

before Insert.

After record inserted,

Next Time also I got the same value

b1. So I got PrimaryKey Exception.

How can I able to create It.

Is there is any better way.

Thanks.

sunitabeck
Master Smack Fu Yak Hacker

5155 Posts

Posted - 2009-03-20 : 07:41:05
Truncating reseeds the identity value. Use delete if you want to preserve identity value.
http://msdn.microsoft.com/en-us/library/ms175098.aspx
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2009-03-20 : 09:46:20
http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=57069

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2009-03-20 : 09:51:23
how did it cause pk violation? if you truncate table, there wont be any data. then in subsequent insert how will pk violate?
Go to Top of Page
   

- Advertisement -