If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > ANSI SQL > Populating a record

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 04-20-04, 13:01
sqlhelp sqlhelp is offline
Registered User
 
Join Date: Apr 2004
Posts: 9
Populating a record

Greetings,

Assume that a database table named “tblA” has 3 numeric fields (field1 to field3) that are NOT NULL and another text field (field4) that has a Default value of ‘Unknown’ . The Primary Key (field1) is an Identity column.

I'm looking to create one SQL statement example to populate 1 record when the information for field4 is Unknown.

Would I use the Insert Into statment:

Example
INSERT INTO tbla(Name, EmployeeID, Position) VALUES(‘Albert Grant’, 100, ‘Salesman’);

Any words of advice would be greatly appreciated.
Reply With Quote
  #2 (permalink)  
Old 04-20-04, 14:07
Pat Phelan Pat Phelan is offline
Resident Curmudgeon
 
Join Date: Feb 2004
Location: In front of the computer
Posts: 12,605
Without actually seeing your assignment, I'd say you've got it!

-PatP
Reply With Quote
  #3 (permalink)  
Old 04-26-04, 16:29
joebednarz joebednarz is offline
Registered User
 
Join Date: Dec 2003
Location: Oklahoma, USA
Posts: 354
I would recommend writing your inserts in the way you specified. Reasoning is that if table structures change, simply writing your INSERT script as:

INSERT INTO myTable VALUES ('abc', 'xyz', 123);

will require a change to the code. Without specifying a column list, your respective SQL parser will assume you will be inputting values into each of the defined columns of the table.

In your specific case, since it may not always be the case that the final value will be NULL, go ahead and specify it in your input list, and simply insert a NULL value in the VALUES part of your statement.

Of course this is just my opinion, which is only important to me...
JoeB
Reply With Quote
  #4 (permalink)  
Old 04-26-04, 16:39
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,524
bzzzt, wrong, sorry

the question was: “tblA” has 3 numeric fields (field1 to field3) and a text field (field4) with field1 being the PK

no way this is right --

INSERT INTO tbla(Name, EmployeeID, Position)
VALUES(‘Albert Grant’, 100, ‘Salesman’)

syntax error all over the floor
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #5 (permalink)  
Old 04-26-04, 22:06
Pat Phelan Pat Phelan is offline
Resident Curmudgeon
 
Join Date: Feb 2004
Location: In front of the computer
Posts: 12,605
Quote:
Originally Posted by r937
bzzzt, wrong, sorry

the question was: “tblA” has 3 numeric fields (field1 to field3) and a text field (field4) with field1 being the PK

no way this is right --

INSERT INTO tbla(Name, EmployeeID, Position)
VALUES(‘Albert Grant’, 100, ‘Salesman’)

syntax error all over the floor
Can you defend your answer?

They didn't say that those were the only defaults in the row, and they also failed to give at least one of the other criteria about field 1 that was specified in class. As you might suspect, I have some insight into this one!

-PatP

Last edited by Pat Phelan; 04-26-04 at 22:13.
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On