Home All Groups Group Topic Archive Search About

Changing the datatype of a column which is part of a PK

Author
9 Mar 2006 9:15 PM
MittyKom
Hi All

I have a table made up of 2 columns as the PK. I am trying to write a script
that changes the datatype of one of the columns which is part of the primary
key. This is what i have tried but i seem not to be getting anywhere:

ALTER TABLE TB1 DROP CONSTRAINT PK_TB1
  ALTER COLUMN ACCOUNT VARCHAR(20) NOT NULL

Is there a way to do this? I tried to drop the PKs and then do the changes
and then recreate the PK again. All this gave me errors. Thank you in
advance.

Author
9 Mar 2006 9:37 PM
Aaron Bertrand [SQL Server MVP]
> Is there a way to do this? I tried to drop the PKs and then do the changes
> and then recreate the PK again. All this gave me errors.

What does "tried" mean?  What errors?

This is the way you do it.  You drop the constraints (both primary *and*
foreign key), you change the column, you re-apply the constraints.
Author
9 Mar 2006 10:18 PM
MittyKom
Thank you. It worked.


Show quote
"Aaron Bertrand [SQL Server MVP]" wrote:

> > Is there a way to do this? I tried to drop the PKs and then do the changes
> > and then recreate the PK again. All this gave me errors.
>
> What does "tried" mean?  What errors?
>
> This is the way you do it.  You drop the constraints (both primary *and*
> foreign key), you change the column, you re-apply the constraints.
>
>
>

AddThis Social Bookmark Button