Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Insert new empty record??

Author  Topic 

phrankbooth
Posting Yak Master

162 Posts

Posted - 2007-10-30 : 16:10:34
Is there a way to INSERT a new empty record without having to designate a field?

I tried the obvious but they issue errors.

--PhB

X002548
Not Just a Number

15586 Posts

Posted - 2007-10-30 : 16:18:51
what do you mean by an empty record?



Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx

Add yourself!
http://www.frappr.com/sqlteam



Go to Top of Page

phrankbooth
Posting Yak Master

162 Posts

Posted - 2007-10-30 : 16:22:31
A record with no fields filled(they're all nullable) in except the identity.

--PhB
Go to Top of Page

dataguru1971
Master Smack Fu Yak Hacker

1464 Posts

Posted - 2007-10-30 : 16:22:43
In order to insert a new record, you have to identify the fields, even if the value is NULL (provided the field allows NULLS)

But at least one field would have to have a value, otherwise it would be pointless.
Go to Top of Page

dataguru1971
Master Smack Fu Yak Hacker

1464 Posts

Posted - 2007-10-30 : 16:44:07
Insert 1 NULL into any one of the fields. If the ID is an identity that populates on trigger or such, it should work to create essentially a blank row.

Insert Into Table (Field1)
Select NULL
Go to Top of Page

Van
Constraint Violating Yak Guru

462 Posts

Posted - 2007-10-30 : 17:15:22
His original post asked if there was a way to do it without designating a field.

You could do an insert with a bunch of NULLs as the values (by a bunch, I mean the same number of fields you have excluding the identity column). It would be easier to designate one field and insert one NULL though.

This sounds like a test question to me. Maybe a bonus take home question.
Go to Top of Page

phrankbooth
Posting Yak Master

162 Posts

Posted - 2007-10-30 : 17:15:40
OK, thanks all.

--PhB
Go to Top of Page

Lamprey
Master Smack Fu Yak Hacker

4614 Posts

Posted - 2007-10-30 : 18:15:04
Maybe something like this?
[url]http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=90116[/url]
Go to Top of Page

arorarahul.0688
Posting Yak Master

125 Posts

Posted - 2007-10-31 : 08:04:23
this may stisfy you
make all the fields nullable
and use
insert into join1 values( null,null,null )as per i know values(,,) will never work you will have to introduce null


Rahul Arora
MCA 07 Batch
NCCE Israna, Panipat
HRY, INDIA
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2007-10-31 : 08:17:51
quote:
Originally posted by arorarahul.0688

this may stisfy you
make all the fields nullable
and use
insert into join1 values( null,null,null )as per i know values(,,) will never work you will have to introduce null


Rahul Arora
MCA 07 Batch
NCCE Israna, Panipat
HRY, INDIA


In that case, you need to omit the identity column. So you need to explicitely specify all other columns

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

DonAtWork
Master Smack Fu Yak Hacker

2167 Posts

Posted - 2007-10-31 : 10:14:14
quote:
Originally posted by phrankbooth

Is there a way to INSERT a new empty record without having to designate a field?

I tried the obvious but they issue errors.

--PhB



Not that i can figure out. You must specify at least ONE field on the insert. How about, read the links in my sig, and restate your question?

[Signature]For fast help, follow this link:
http://weblogs.sqlteam.com/brettk/archive/2005/05/25.aspx
Learn SQL
http://www.sql-tutorial.net/
http://www.firstsql.com/tutor.htm
http://www.w3schools.com/sql/default.asp
Go to Top of Page

pgedney
Starting Member

1 Post

Posted - 2008-03-16 : 05:04:21
This will work in SQL Server,

... meeting all criteria of the original post.

1) Insert a blank record
2) Statement requiring no Value Arguments

This syntax also triggers all default values.
--------------------------------------
insert into TableName Default values
--------------------------------------

I tried it and it worked!

Go to Top of Page
   

- Advertisement -