xmlprogrammer
01-14-2008, 08:57 AM
How do you alter column datatypes that have a constraint attached to it?
For example, I want to change a dataype from col1 char to varchar however, col1 is part of the primary key as a key column. How can I generate a scrip to do this for all columns in a database?
alter tablename
alter columnname varchar(20)
It gives me an error message:
Msg 5074, Level 16, State 1, Line 2
The object 'PK_tablename' is dependent on column 'columnname'.
Msg 4922, Level 16, State 9, Line 2
ALTER TABLE ALTER COLUMN columnname failed because one or more objects access this column.
For example, I want to change a dataype from col1 char to varchar however, col1 is part of the primary key as a key column. How can I generate a scrip to do this for all columns in a database?
alter tablename
alter columnname varchar(20)
It gives me an error message:
Msg 5074, Level 16, State 1, Line 2
The object 'PK_tablename' is dependent on column 'columnname'.
Msg 4922, Level 16, State 9, Line 2
ALTER TABLE ALTER COLUMN columnname failed because one or more objects access this column.