Default constraint is to maintain default value in the column. We have to mention the default value to the column while creating the table. In case no value inserted in that column, it will be filled with the default value which was supplied while creating the table.
Syntax:
CREATE TABLE <Table Name>(
<COLUMN NAME> Data Type DEFAULT(VALUE)
);
Example:
CREATE TABLE Employees (
ID int NOT NULL Primary Key IDENTITY(1,1),
LastName varchar(255) NOT NULL UNIQUE,
FirstName varchar(255),
Age int CHECK(Age>17 and Age<61),
Department Varchar(100) DEFAULT('Resource pool')
);
INSERT INTO Employees(LastName,FirstName,Age)VALUES('Naga','P',33);
Here no value supplied to the "Department" column, it will get default value 'Resource pool' as below
SELECT * FROM Employees
LastName FirstName Age ID Department
Naga P 33 1 Resource pool




SQL Server
C#.Net
ASP.Net
ADO.Net
jQuery
No comments:
Post a Comment