April 13, 2010 at 2:48 am
Hi folks,
Is there any way to remove identity property from particular table column(say: TableA column colA).
Note:
1.TableA having more than one million records.
2. Need to remove identity property completely
if you give any assistance regarding this it would be greatly appreciated
Cheers,
Asan
April 13, 2010 at 2:51 am
April 13, 2010 at 2:55 am
SET IDENTITY_INSERT [ database. [ owner. ] ] { table } { ON | OFF }
SET IDENTITY_INSERT tablename ON
SET IDENTITY_INSERT tablename OFF
🙂
April 13, 2010 at 3:03 am
thanks joe
Sashi I asked to remove column identity property completely.. however thanks u too..
April 13, 2010 at 3:16 am
Buddy go thro this article
April 13, 2010 at 3:25 am
One more help guys.
Is it possible to specify seed increment dynamically for identity column.
I tried as follow but still getting error. Can u plz hav a look.
create table #t1(ID numeric identity(1,1), Product varchar(10))
go
Insert into #t1 values('DVD')
Insert into #t1 values('Fridge')
Insert into #t1 values('Fan')
go
Declare @MAX_ID numeric
Set @MAX_ID = (SELECT max(ID) from #t1)
Select IDENTITY(Numeric, @MAX_ID, 1) into #t2 from #t1
April 13, 2010 at 3:37 am
You wil have to use dynamic SQL for this.
Like
if object_id ('tempdb..#t1') is not null
drop table #t1
if object_id ('tempdb..#t2') is not null
drop table #t2
create table #t1(ID numeric identity(1,1), Product varchar(10))
go
Insert into #t1 values('DVD')
Insert into #t1 values('Fridge')
Insert into #t1 values('Fan')
go
Declare @MAX_ID numeric
Set @MAX_ID = (SELECT max(ID) from #t1)
-- only these lines are included
Declare @sql varchar(200)
set @sql = 'Select IDENTITY(Numeric, '+Cast(@MAX_ID as varchar(5))+', 1) as ident into #t2 from #t1'
print @sql
exec(@sql)
But be informed, that #t2 will be visible only inside that dynamic sql.. so will be have to perform all your operations w.r.t to #t2 inside @sql itself...
Cheers..
April 13, 2010 at 3:45 am
I think it should be
Select IDENTITY(Numeric, @MAX_ID, 1) AS RowNum, * into #t2 from #t1
How to post data/code on a forum to get the best help - Jeff Moden
http://www.sqlservercentral.com/articles/Best+Practices/61537/
April 13, 2010 at 3:48 am
thank u very much coldcoffee:-)
hi Kingston Dhasian, Hope you are not compiled this..
April 13, 2010 at 3:53 am
Yes, tried it just now. It doesn't work. I thought the alias name was the problem, hence didn't test. Even i would have done the same in such a case. Learnt something new today:-)
How to post data/code on a forum to get the best help - Jeff Moden
http://www.sqlservercentral.com/articles/Best+Practices/61537/
April 13, 2010 at 3:55 am
I agree.. 🙂
Viewing 11 posts - 1 through 10 (of 10 total)
You must be logged in to reply to this topic. Login to reply