I have a table with a primary key column size is set to 50. Due to some new requirements, I need to increase the size to 255. After searching online, I understood it is not possible to alter a column if it is a part of a primary key constraint. So, I took the approach of dropping the constraint, altering the column and adding the constraint back.
But, I am still experiencing a small issue, my original column is of type Non Null and has a default value set, but now when i try the following sql, I get an error “Incorrect syntax near DEFAULT”
ALTER TABLE [tblLocation]
DROP CONSTRAINT [PK_tblLocation]
ALTER TABLE [tblLocation]
ALTER COLUMN Location VARCHAR(255) DEFAULT('New Location') NOT NULL
ALTER TABLE [tblLocation]
ADD
CONSTRAINT [PK_tblLocation] PRIMARY KEY CLUSTERED
(
[Location] ASC
)
Thanks for any help.
Javid
You cannot use `ALTER TABLE… ALTER COLUMN’ to modify both a column and a constraint (here, the default) at the same time. You will first need to alter the column, and then alter the default constraint. (You might need to first drop and then recreate the default.)