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
 General SQL Server Forums
 New to SQL Server Programming
 Help with a statement

Author  Topic 

intern2424
Yak Posting Veteran

53 Posts

Posted - 2010-01-28 : 15:11:06
I keep on looking at this statement and can not find what is wrong.

alter table check_box_control
alter column control_id int not null primary key identity

Thanks for any help you can give.

Kristen
Test

22859 Posts

Posted - 2010-01-28 : 15:46:23
2 x "alter" ?
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2010-01-29 : 02:33:17
quote:
Originally posted by Kristen

2 x "alter" ?


No. Primary key constraint should be added when altering a column to primary key

Madhivanan

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

DaleTurley
Yak Posting Veteran

76 Posts

Posted - 2010-01-29 : 08:31:53
quote:
Originally posted by intern2424

I keep on looking at this statement and can not find what is wrong.

alter table check_box_control
alter column control_id int not null primary key identity

Thanks for any help you can give.



If you change to;
alter table check_box_control
alter control_id int not null identity(1,1)

Should work to change data type. If you're trying to add a primary key.

ALTER TABLE check_box_control
ADD CONSTRAINT <PK Name> PRIMARY KEY CLUSTERED
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2010-01-30 : 00:32:09
quote:
Originally posted by DaleTurley

quote:
Originally posted by intern2424

I keep on looking at this statement and can not find what is wrong.

alter table check_box_control
alter column control_id int not null primary key identity

Thanks for any help you can give.



If you change to;
alter table check_box_control
alter control_id int not null identity(1,1)

Should work to change data type. If you're trying to add a primary key.

ALTER TABLE check_box_control
ADD CONSTRAINT <PK Name> PRIMARY KEY CLUSTERED



you cant alter an already existing column to make it an identity column. for that you need to apply below work around

http://www.mssqltips.com/tip.asp?tip=1397
Go to Top of Page

chriztoph
Posting Yak Master

184 Posts

Posted - 2010-05-30 : 22:55:04
try this to edit your tables in using the design interface..

you can use this to edit the IsIdentity value of an existing column..

http://stevesmithblog.com/blog/sql-server-prevent-saving-changes-that-require-table-to-be-re-created/
Go to Top of Page
   

- Advertisement -