SQL Server - DEFAULT Key Constraint
What is DEFAULT key constraint in SQL Server ?
DEFAULT constraint help to insert default value in table when user not provide any value at the time of data insertion.
1) Add DEFAULT key constraint on table by Query.
In below example we are creating new table of tblStudentDetails and create IsActive column as default key constraint.
We are inserting BIT value (1, 0) in IsActive column, 1 indicate active and 0 indicate deactivate student.
Note : In above example we insert not null and default key constraint on IsActive column.
2) Add DEFAULT key constraint on table using table design.
Step 1 :
Step 2 : Save table.
Let's try to insert some record in student details.
Note : If you observe above insert statement then you can see that we not provide the value of IsActive column.
List the table after above insert statements.