Categories
Sql Server

Default Constraint In SQL Server

Default Constraint In SQL Server

DEFAULT constraint is used to insert a default value into a column ,that is predefined by us.

Query to create a DEFAULT constraint:-

CREATE TABLE sales_order
(
Id int NOT NULL,
O_No int NOT NULL,
OrderDate date DEFAULT GETDATE(),city varchar(50)
)

Create a default constraint in already created table:-

ALTER TABLE sales_order
ALTER COLUMN City SET DEFAULT 'Delhi'

Query for Droping Default constraint:-

ALTER TABLE sales_order
ALTER COLUMN orderdate DROP DEFAULT