windows,linux,cpanel,sql server,classic asp,php,wordpress,facebook,magento,jquery,css,javascript Sql Server Defaults » abhilash

Sql Server Defaults



defaults are used for inserting default values to tables when the field is skipped or inserted iwth default values

To dmonstrate lets create a table first


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

Now insert values to fields except r_date

insert into default_test (id) values (1000)

r_date will be inserted with current date value

Again When the field is inserted with keyword default, this time too value on the r_date feld will be of current date

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

But when insert value to this field it ll accept it over default

insert into default_test (id,r_date) values (1000,’2011-3-3′)