Removing identity property

  • 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

  • http://www.sqlservercentral.com/articles/T-SQL/61979/

    ----------------------------------------------------------------------------------------------------------------------------------------------------
    Roshan Joe

    Jeff Moden -Forum Etiquette: How to post data/code on a forum to get the best help[/url]

  • SET IDENTITY_INSERT [ database. [ owner. ] ] { table } { ON | OFF }

    SET IDENTITY_INSERT tablename ON

    SET IDENTITY_INSERT tablename OFF

    🙂

  • thanks joe

    Sashi I asked to remove column identity property completely.. however thanks u too..

  • 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

  • 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..

  • I think it should be

    Select IDENTITY(Numeric, @MAX_ID, 1) AS RowNum, * into #t2 from #t1


    Kingston Dhasian

    How to post data/code on a forum to get the best help - Jeff Moden
    http://www.sqlservercentral.com/articles/Best+Practices/61537/

  • thank u very much coldcoffee:-)

    hi Kingston Dhasian, Hope you are not compiled this..

  • 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:-)


    Kingston Dhasian

    How to post data/code on a forum to get the best help - Jeff Moden
    http://www.sqlservercentral.com/articles/Best+Practices/61537/

  • I agree.. 🙂

Viewing 11 posts - 1 through 10 (of 10 total)

You must be logged in to reply to this topic. Login to reply