Saturday, 19 July 2014

Add Default and Check Constrains for SQL Table


Create table MyTable
(
Sno Int,
EName varchar(30),
EGender Char(1) Default 'M' Check (EGender ='M' or EGender ='F')
)
When you insert null vallues MyTable it will work.
Check constrain will not check for null, since the default constrain will take care to insert default value as 'M'
But check constrain will validate if you enter some values other than 'M', or 'F'