Default Constraint MS SQL Server

0
25

 

defaultconstraint in SQL server used to set a default value for a field when this field is intentionally or by keyword

creating table with default constraint

create table default_test
(
id int,
r_date datetime default(getdate()),
r_count int default(100)
)

here r_date will be current date and r_count will be 100 if skipped to insert

insert into default_test (id) values (1000)

select * from default_test

Result

1000 2011-04-13 12:07:28.930 100

 

insert into default_test (id,r_date) values (1000,default)

select * from default_test

1000 2011-04-13 12:07:28.930 100
1000 2011-04-13 12:08:29.760 100

but when insert values to all fields

insert into default_test select 1,’2010-04-13 00:00:00.000′,200

select * from default_test

1000 2011-04-13 12:07:28.930 100
1000 2011-04-13 12:08:29.760 100
1 2010-04-13 00:00:00.000 200

SHARE
Previous articleCreate Your Friends Birthday Calendar with facebook
Next articleGmail New themes and Colors
abhilash, is a programmer by profession and a technology addict with a passion towards browsing , shopping and imaging . My views may be biased on reviews. all images and videos are copyrighted to respective owners.

LEAVE A REPLY

Please enter your comment!
Please enter your name here