Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

INSERT INTO

Status
Not open for further replies.

deSilentio

IS-IT--Management
Feb 13, 2008
2
US
I am in need of some help. We have a database that has two tables, one that holds a computers information and the other that holds model numbers that computers have.

The tables are set up like this:

tbl_comp: comp_ID (auto), comp_mod_ID (num), comp_desc (Char)

tbl_model: mod_ID (auto), mod_modelName (Char)

I can perform an INSERT command to enter a computer, but in order for it to reference the Model Number table, I have to use the mod_ID field. (which I think is best practice)

I want to be able to do the INSERT command, but use the modelName instead. So I think I need to do some kind of lookup, where I pass in the modelName, but it inserts in the modelID.

However, I do not know what to call this procedure, and therefore I cannot search for help on google.

Any help is appreciated. If I am unclear on my question, please let me know.

Thanks,
John Dombrowski
 
solution:
Code:
insert 
  into tbl_comp
     ( comp_mod_ID , comp_desc )
select mod_ID , 'computer description here'
  from tbl_model
 where mod_modelName = 'model name here'

advice: drop the unnecessary prefixes built into your names

instead of this --

tbl_comp: comp_ID (auto), comp_mod_ID (num), comp_desc (Char)
tbl_model: mod_ID (auto), mod_modelName (Char)

try this --

comp: ID (auto), mod_ID (num), descr (Char)
model: ID (auto), Name (Char)

r937.com | rudy.ca
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top