Skip to content
Advertisement

Unable to assign default constraint in an existing column in SQL Server

I am using SQL Server and have a table Employee. I want to change the constraint of Starting_Date from NULL to NOT NULL and add a DEFAULT with GETDATE() function. Please check the screenshot and suggest how to solve the error I get:

enter image description here

Advertisement

Answer

Try this TSQL command for add, not null constraint

If your table had any rows with null Starting_Date run this query before adding the constraint

and then this, for default constraint from your function output result

User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement