DEFAULT Constraint IN SQL
DEFAULT Constraint
How to create DEFAULT Constraint on TABLE in SQL:- The following SQL creates a DEFAULT constraint on the "Email" column when the "tblEmployees" table is created:
The DEFAULT constraint can also be used to insert system values, by using functions like GETDATE():-
How to Alter DEFAULT Constraint on TABLE in SQL:-
How To DROP a DEFAULT Constraint in SQL:-
- The DEFAULT constraint is used to insert a default value into a column.
- The default value will be added to all new records, if no other value is specified.
How to create DEFAULT Constraint on TABLE in SQL:- The following SQL creates a DEFAULT constraint on the "Email" column when the "tblEmployees" table is created:
CREATE TABLE tblEmployees ( EmpID INT PRIMARY KEY, EmpName VARCHAR(100), Address varchar(200), MobileNo bigint, Email NVARCHAR(200) DEFAULT 'sa@gmail.com' )
The DEFAULT constraint can also be used to insert system values, by using functions like GETDATE():-
CREATE TABLE tblEmployees ( EmpID INT PRIMARY KEY, EmpName VARCHAR(100), Address varchar(200), MobileNo bigint, Email NVARCHAR(200) DEFAULT 'sa@gmail.com', JoinDate date DEFAULT GETDATE() )
How to Alter DEFAULT Constraint on TABLE in SQL:-
ALTER TABLE tblEmployees ALTER COLUMN Email SET DEFAULT 'sa@gmail.com'
How To DROP a DEFAULT Constraint in SQL:-
ALTER TABLE tblEmployees ALTER Email DROP DEFAULT