Sunday, March 25, 2012

altering a column of a table

Hello,
I have an internet site, that supports ms-sql server 2000.
The hosting company for some reason have problems on there wizard of
creating columns on db,
and doesn't support the auto-increment.
How can I do alter to a column, with an sql command, to an auto-increment
one ?
Need sample code please.
Thanks I suggest that ALL changes on a live system should be made through SQL
scripts rather than using Enterprise Manager / Wizards. That way you can
more reliably reproduce and test your installation process.
IDENTITY is the correct name for the "auto-incrementing" column property in
SQL Server.
You can ADD an IDENTITY column to a table using an ALTER TABLE statement:
ALTER TABLE YourTable ADD col INTEGER IDENTITY
You cannot add the IDENTITY property to an existing column. Enterprise
Manager achieves this by creating a new table with IDENTITY, repopulating it
with the old data and then dropping the old table. That's something you may
want to avoid doing on a production system. If you do want to use that
approach then use Enterprise Manager to change the column on a development
copy of your data and select the Save Change Script option to save the
commands to a file. That way you can see exactly what the steps are.
David Portas
SQL Server MVP
--|||Hi Eitan,
you cannot alter columns to auto-increment. You can only add columns that
auto-increment.
try dropping the column and re-creating it. hopefully, you dont need the
existing values in that column.
Av.
http://dotnetjunkies.com/WebLog/avnrao
http://www28.brinkster.com/avdotnet
"Eitan" <no_spam_please@.nospam_please.com> wrote in message
news:#KVZ#BX8EHA.3336@.TK2MSFTNGP11.phx.gbl...
> Hello,
> I have an internet site, that supports ms-sql server 2000.
> The hosting company for some reason have problems on there wizard of
> creating columns on db,
> and doesn't support the auto-increment.
> How can I do alter to a column, with an sql command, to an auto-increment
> one ?
> Need sample code please.
> Thanks
>

No comments:

Post a Comment