What is Default constraint in sql server and How to write query. [Resolved]

Posted by Jitendrasoft09 under Sql Server on 6/26/2013 | Points: 10 | Views : 1293 | Status : [Member] [MVP] | Replies : 3
Hi All,
I want to understand What is Default constraint in sql server and How to write query., let me know if anybody knows.

Jitendra Kumar
If my post helps you, plz mark as an answer.



Responses

Posted by: Neeraaj.Sharma on: 6/27/2013 [Member] Starter | Points: 50

Up
0
Down

Resolved
In sql server we can create a default column(s) which accept(s) predefined values if not provided in sql statement.



Code below :



Create Table TableWithdefaultvalueVarchar (ID Int ,name Varchar(10) ,Country Varchar(10) constraint DF_Name default 'India' )

here Country is Default column And Default Value IS india


insert into TableWithdefaultvalueVarchar (name) values ('Neeraj')
select * From TableWithdefaultvalueVarchar


All default value to existing table syntax
Alter Table Table_Name Add Constraint Const_Name Default(Default_Value) For Column_Name

for complete ref visit : http://www.tutorialsqlserver.com/Create/Default-Value-in-Sql-Server.htm





Jitendrasoft09, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Satyapriyanayak on: 6/26/2013 [Member] [MVP] Silver | Points: 25

Up
0
Down
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.

http://www.w3schools.com/sql/sql_default.asp

If this post helps you mark it as answer
Thanks

Jitendrasoft09, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Jitendrasoft09 on: 6/27/2013 [Member] [MVP] Starter | Points: 25

Up
0
Down
Thanks Satya...,Nice explanation Neeraj...

Jitendra Kumar
If my post helps you, plz mark as an answer.

Jitendrasoft09, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response