December 5, 2006 at 1:49 am
Hi
I know below query alter only one column
ALTER TABLE MyCustomers ALTER COLUMN CustId IDENTITY (200, 2)
then
How to alter multiple column in table at a time
December 5, 2006 at 3:07 am
Only way to do that is to create a new table, copy the data over, drop the old table, rename the new. Then make sure that you replace the constraints and indexes.
Management studio/Enterprise manager can generate the code for you as it's how both do table modifications.
Otherwise it's multiple Alter Table Alter column statements.
Gail Shaw
Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability
December 5, 2006 at 3:31 am
its not possible to use Alter Table statement for altering multiple columns.
"Keep Trying"
December 5, 2006 at 6:45 am
BTW, this doesn't work either :
CREATE TABLE #Demo
(
ID INT NOT NULL IDENTITY (1,1)
)
GO
ALTER TABLE #Demo
ALTER COLUMN ID INT NOT NULL IDENTITY(200,2)
GO
DROP TABLE #Demo
December 5, 2006 at 10:41 am
Good catch Remi - I'm glad that Celko didn't come across this one...he'd have launched into a tirade immediately....
**ASCII stupid question, get a stupid ANSI !!!**
December 5, 2006 at 10:46 am
Let me find his phone number... I'll give him a ring .
December 5, 2006 at 11:41 am
Although the method used generally does work I have performed a script where a table was changed the way EM does it. After completion the table was gone. So make sure you have a backup beforehand. We restored ours and ran again without issue. The ALTER method even thou more time consuming has not done that to me before so weigh the difference and risks. Also a few large tables of mine have show to take longer with the EM method of new object, populate from original, drop original and rename new to original name.
Viewing 7 posts - 1 through 6 (of 6 total)
You must be logged in to reply to this topic. Login to reply