Setting a default value to a column in case a row in inserted with a no value provided for the column. Please find the below code to set a default value for a column. The example below adds a new column and applies the default constraint and default value of 'Hello' and the column doesn't allow null.
ALTER TABLE YourTable
ADD YourNewColumn VARCHAR(50)
CONSTRAINT DF_
YourTable_YourNewColumn DEFAULT 'Hello' NOT NULL
GO
Constraint name is not mandatory as SQL Server will take a default constraint name in case if you don't provide one.
Great..
ReplyDeleteThanks a lot. Helped me a lot..
Thanks for sharing your knowledge. This really helped me.
ReplyDelete