How to set a default value for an existing column
This will work in SQL Server:
ALTER TABLE Employee ADD CONSTRAINT DF_SomeName DEFAULT N'SANDNES' FOR CityBorn;
The correct way to do this is as follows:
Run the command:
sp_help [table name]
Copy the name of the
CONSTRAINT
.Drop the
DEFAULT CONSTRAINT
:ALTER TABLE [table name] DROP [NAME OF CONSTRAINT]
Run the command below:
ALTER TABLE [table name] ADD DEFAULT [DEFAULT VALUE] FOR [NAME OF COLUMN]
cannot use alter column for that, use add instead
ALTER TABLE Employee
ADD DEFAULT('SANDNES') FOR CityBorn
ALTER TABLE Employee ADD DEFAULT 'SANDNES' FOR CityBorn