SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Insert new empty record??
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

phrankbooth
Posting Yak Master

USA
161 Posts

Posted - 10/30/2007 :  16:10:34  Show Profile  Reply with Quote
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 - 10/30/2007 :  16:18:51  Show Profile  Reply with Quote
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

USA
161 Posts

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

--PhB
Go to Top of Page

dataguru1971
Flowing Fount of Yak Knowledge

USA
1464 Posts

Posted - 10/30/2007 :  16:22:43  Show Profile  Send dataguru1971 an AOL message  Send dataguru1971 a Yahoo! Message  Reply with Quote
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
Flowing Fount of Yak Knowledge

USA
1464 Posts

Posted - 10/30/2007 :  16:44:07  Show Profile  Send dataguru1971 an AOL message  Send dataguru1971 a Yahoo! Message  Reply with Quote
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

458 Posts

Posted - 10/30/2007 :  17:15:22  Show Profile  Reply with Quote
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

USA
161 Posts

Posted - 10/30/2007 :  17:15:40  Show Profile  Reply with Quote
OK, thanks all.

--PhB
Go to Top of Page

Lamprey
Flowing Fount of Yak Knowledge

4614 Posts

Posted - 10/30/2007 :  18:15:04  Show Profile  Reply with Quote
Maybe something like this?
http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=90116
Go to Top of Page

arorarahul.0688
Posting Yak Master

India
125 Posts

Posted - 10/31/2007 :  08:04:23  Show Profile  Reply with Quote
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

India
22769 Posts

Posted - 10/31/2007 :  08:17:51  Show Profile  Send madhivanan a Yahoo! Message  Reply with Quote
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
Flowing Fount of Yak Knowledge

2161 Posts

Posted - 10/31/2007 :  10:14:14  Show Profile  Reply with Quote
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 Posts

Posted - 03/16/2008 :  05:04:21  Show Profile  Reply with Quote
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
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.12 seconds. Powered By: Snitz Forums 2000