i have a table 'staff'... it already contains some 10-15 records
now i want to add a new column StaffCode to the table which is not null.... iam adding a default value otherwise it will throw error
the syntax is:
ALTER TABLE Staff ADD StaffCode varchar(10) DEFAULT ' ' NOT NULL;
iam able to create a default value and add the column but i want to change the name of default constraint... how to do it...
i tried the following steps
ALTER TABLE Staff ADD StaffCode varchar(10)NULL;
ALTER TABLE Staff ADD CONSTRAINT Staff_StaffCode_df DEFAULT ' '
ALTER TABLE Staff ALTER COLUMN StaffCode varchar(10) NOT NULL;
I get the error:-
Msg 4901, Level 16, State 1, Line 1
ALTER TABLE only allows columns to be added that can contain nulls, or have a DEFAULT definition specified, or the column being added is an identity or timestamp column, or alternatively if none of the previous conditions are satisfied the table must be empty to allow addition of this column. Column 'StaffCode' cannot be added to non-empty table 'Staff' because it does not satisfy these conditions.
Please help.... iam able to give default value but not able to give my own constraint name