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)
With Column value is specified
INSERT INTO Emp(ENAME,EAGE,AddedDate)
VALUES('abc',24,getdate())
In first Insert query Default current date are
inserted and in second column manually we insert the current date.
Comments
Post a Comment