Question

I am pretty new in Microsoft SQL Server and I am not so into DB in general.

I have the following doubt about an insert query that begin in this way:

insert into MyTable DEFAULT VALUES

What exactly mean the DEFAULT VALUES specification?

Tnx

Andrea

Was it helpful?

Solution 4

You can watch default specifications in work by checking that code:

DECLARE @tmp as table 
(
id int null,
num int null default(777),
txt varchar(10) null default('abc'),
date datetime null
)    
insert into @tmp DEFAULT VALUES    
select * from @tmp

Output is

id      num     txt     date
NULL    777     abc     NULL

OTHER TIPS

Reading the fine manual yields:

DEFAULT VALUES

Forces the new row to contain the default values defined for each column.

Well it uses the default values specified in your table.

So for example if you have a column CreationDate datetime default(getdate()) it will use it.

If each of the required columns in MyTable has specified DEFAULT VALUE then this statement insert such a row.

For example you could have column Date with default 01/01/2014 and position with DEFAULT 'Developer' and this statement would insert such a record.

You can read more here: http://msdn.microsoft.com/en-us/library/aa933206%28SQL.80%29.aspx

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top