Home All Groups Group Topic Archive Search About

SQL Express - Identity specification

Author
23 Nov 2007 7:54 AM
Mike
Hi, I use SQL Server Enterprise Manager for MS SQL Express and i want
to change the column properites for [int]
type of column, but I cann't change it.

More in details...
I'd like to set autoincremntal option and in order to change that I am
trying to change Identity specification from no to yes, without
success.
It is primary key too,
Name AricleID,
int type,
Primary set of binding --> ((0))
Full text specification --> No
Identity specification --> No --> I want to change this

Everything else is disabled

Thanks

Author
23 Nov 2007 2:33 PM
Russell Fields
Mike,

You cannot alter a table to change a column to use the IDENTITY property.
What you will have to do is:

CREATE TABLE v2_MyTable
(AutoNum INT IDENTITY,
  OtherColumn NVARCHAR(100))

SET IDENTITY_INSERT v2_MyTable ON
INSERT INTO v2MyTable SELECT * FROM MyTable
SET IDENTITY_INSERT v2_MyTable OFF

DROP TABLE MyTable
EXEC sp_rename 'v2_MyTable', 'MyTable'

Of course, this outline did not add constraints, indexes, and so forth, so
be sure to readd those as well.

RLF


Show quote
"Mike" <ablyp***@yahoo.com> wrote in message
news:4p1dk3lje3jv24n1sdk7kufctu86dpdk9u@4ax.com...
> Hi, I use SQL Server Enterprise Manager for MS SQL Express and i want
> to change the column properites for [int]
> type of column, but I cann't change it.
>
> More in details...
> I'd like to set autoincremntal option and in order to change that I am
> trying to change Identity specification from no to yes, without
> success.
> It is primary key too,
> Name AricleID,
> int type,
> Primary set of binding --> ((0))
> Full text specification --> No
> Identity specification --> No --> I want to change this
>
> Everything else is disabled
>
> Thanks
>
Author
24 Nov 2007 11:49 AM
Mike
On Fri, 23 Nov 2007 09:33:14 -0500, "Russell Fields"
<russellfie***@nomail.com> wrote:

Show quote
>Mike,
>
>You cannot alter a table to change a column to use the IDENTITY property.
>What you will have to do is:
>
>CREATE TABLE v2_MyTable
> (AutoNum INT IDENTITY,
>  OtherColumn NVARCHAR(100))
>
>SET IDENTITY_INSERT v2_MyTable ON
>INSERT INTO v2MyTable SELECT * FROM MyTable
>SET IDENTITY_INSERT v2_MyTable OFF
>
>DROP TABLE MyTable
>EXEC sp_rename 'v2_MyTable', 'MyTable'
>
>Of course, this outline did not add constraints, indexes, and so forth, so
>be sure to readd those as well.
>
>RLF
>
>
>"Mike" <ablyp***@yahoo.com> wrote in message
>news:4p1dk3lje3jv24n1sdk7kufctu86dpdk9u@4ax.com...
>> Hi, I use SQL Server Enterprise Manager for MS SQL Express and i want
>> to change the column properites for [int]
>> type of column, but I cann't change it.
>>
>> More in details...
>> I'd like to set autoincremntal option and in order to change that I am
>> trying to change Identity specification from no to yes, without
>> success.
>> It is primary key too,
>> Name AricleID,
>> int type,
>> Primary set of binding --> ((0))
>> Full text specification --> No
>> Identity specification --> No --> I want to change this
>>
>> Everything else is disabled
>>
>> Thanks
>>
>
Author
24 Nov 2007 11:50 AM
Mike
Russel,

Does it means that I should create table from beggining.

I really do not understand why I cann't change it within properties?

Mike

On Fri, 23 Nov 2007 09:33:14 -0500, "Russell Fields"
<russellfie***@nomail.com> wrote:

Show quote
>Mike,
>
>You cannot alter a table to change a column to use the IDENTITY property.
>What you will have to do is:
>
>CREATE TABLE v2_MyTable
> (AutoNum INT IDENTITY,
>  OtherColumn NVARCHAR(100))
>
>SET IDENTITY_INSERT v2_MyTable ON
>INSERT INTO v2MyTable SELECT * FROM MyTable
>SET IDENTITY_INSERT v2_MyTable OFF
>
>DROP TABLE MyTable
>EXEC sp_rename 'v2_MyTable', 'MyTable'
>
>Of course, this outline did not add constraints, indexes, and so forth, so
>be sure to readd those as well.
>
>RLF
>
>
>"Mike" <ablyp***@yahoo.com> wrote in message
>news:4p1dk3lje3jv24n1sdk7kufctu86dpdk9u@4ax.com...
>> Hi, I use SQL Server Enterprise Manager for MS SQL Express and i want
>> to change the column properites for [int]
>> type of column, but I cann't change it.
>>
>> More in details...
>> I'd like to set autoincremntal option and in order to change that I am
>> trying to change Identity specification from no to yes, without
>> success.
>> It is primary key too,
>> Name AricleID,
>> int type,
>> Primary set of binding --> ((0))
>> Full text specification --> No
>> Identity specification --> No --> I want to change this
>>
>> Everything else is disabled
>>
>> Thanks
>>
>
Author
26 Nov 2007 1:53 PM
Russell Fields
Mike,

Yes, it means recreating the table from the beginning.  The identity
property is not one that can be added and removed from a column (at least
not up through SQL Server 2005), so the extra work is necessary.

You can add a new column with the identity property, as such:
    alter table MyTable add NewIdentityColumn int identity

However, this will not allow you to move any existing keys into the new
column.  It is automatically populated when it is created, so if you were
trying to preserve existing values this will not work for you.  If you are
happy with the new ID values and are willing to make whatever changes your
database needs to refer to these new values, then use this approach.

RLF


Show quote
"Mike" <ablyp***@yahoo.com> wrote in message
news:du3gk393qkkdr0o9hdm8girvu5f36ocqmo@4ax.com...
> Russel,
>
> Does it means that I should create table from beggining.
>
> I really do not understand why I cann't change it within properties?
>
> Mike
>
> On Fri, 23 Nov 2007 09:33:14 -0500, "Russell Fields"
> <russellfie***@nomail.com> wrote:
>
>>Mike,
>>
>>You cannot alter a table to change a column to use the IDENTITY property.
>>What you will have to do is:
>>
>>CREATE TABLE v2_MyTable
>> (AutoNum INT IDENTITY,
>>  OtherColumn NVARCHAR(100))
>>
>>SET IDENTITY_INSERT v2_MyTable ON
>>INSERT INTO v2MyTable SELECT * FROM MyTable
>>SET IDENTITY_INSERT v2_MyTable OFF
>>
>>DROP TABLE MyTable
>>EXEC sp_rename 'v2_MyTable', 'MyTable'
>>
>>Of course, this outline did not add constraints, indexes, and so forth, so
>>be sure to readd those as well.
>>
>>RLF
>>
>>
>>"Mike" <ablyp***@yahoo.com> wrote in message
>>news:4p1dk3lje3jv24n1sdk7kufctu86dpdk9u@4ax.com...
>>> Hi, I use SQL Server Enterprise Manager for MS SQL Express and i want
>>> to change the column properites for [int]
>>> type of column, but I cann't change it.
>>>
>>> More in details...
>>> I'd like to set autoincremntal option and in order to change that I am
>>> trying to change Identity specification from no to yes, without
>>> success.
>>> It is primary key too,
>>> Name AricleID,
>>> int type,
>>> Primary set of binding --> ((0))
>>> Full text specification --> No
>>> Identity specification --> No --> I want to change this
>>>
>>> Everything else is disabled
>>>
>>> Thanks
>>>
>>

AddThis Social Bookmark Button