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)
 Alter Table Alter column with dynamic sql

Author  Topic 

Bex
Aged Yak Warrior

580 Posts

Posted - 2009-01-12 : 13:47:41
I am trying to alter an identity column using dynamic sql, but get the following error:

Msg 156, Level 15, State 1, Line 2
Incorrect syntax near the keyword 'IDENTITY'.

ALTER TABLE crdm.Header_20090111
ALTER COLUMN TransactionID BIGINT IDENTITY (3,1)

Is this not possible?

Thanks

Hearty head pats

Skorch
Constraint Violating Yak Guru

300 Posts

Posted - 2009-01-12 : 13:56:30
I think you may have to remove the identity and re-add it to alter it
Go to Top of Page

sodeep
Master Smack Fu Yak Hacker

7174 Posts

Posted - 2009-01-12 : 14:23:26
Why dynamic sql?
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2009-01-13 : 00:21:51
http://www.mssqltips.com/tip.asp?tip=1397
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2009-01-13 : 01:38:03
quote:
Originally posted by Bex

I am trying to alter an identity column using dynamic sql, but get the following error:

Msg 156, Level 15, State 1, Line 2
Incorrect syntax near the keyword 'IDENTITY'.

ALTER TABLE crdm.Header_20090111
ALTER COLUMN TransactionID BIGINT IDENTITY (3,1)

Is this not possible?

Thanks

Hearty head pats


But the code you posted is non-dynamic
You cant alter the column to have a identity property

Madhivanan

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

Bex
Aged Yak Warrior

580 Posts

Posted - 2009-01-13 : 05:04:05
Hi all

Thank you for your replies. SOrry for not replying sooner, but I had gone home.

To answer some of your questions:

Example code not dynamic:
That was just for ease of posting.

Why dynamic:
Long story, but I have to generate a DB scheme to emulate partitioning (with a different partition each day). Therefore, the code has to create the tables using template examples, and recreate all constraints, keys, etc, but using different names based on dates. Hope that makes sense???

THanks for the link, I think that concludes what Skorch said, I shall have to drop and recreate the column.

Thanks guys

Hearty head pats
Go to Top of Page
   

- Advertisement -