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.
Example
The following SQL query creates a DEFAULT constraint on the "AddedDate" column when the "Emp" table is created
CREATE TABLE Emp
(
EID INT PRIMARY KEY IDENTITY,
ENAME VARCHAR(100),
EAGE INT,
AddedDate DateTime Default GetDate()
)
Insert Record into the Emp table , here we are not specified any
value into the “AddedDate”
INSERT INTO Emp(ENAME,EAGE)
VALUES('abc',24)
AddedDate will be insert the default value (means the Current Date) into the table
Now with Column value is specified
INSERT INTO Emp(ENAME,EAGE,AddedDate)
VALUES('abc',24,getdate())
Comments
Post a Comment