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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Updating a database

Status
Not open for further replies.

johno77

Technical User
Nov 1, 2003
40
0
0
GB
Could someone please inform me if it is possible to code the following statement so if there is no record with name equal to bni the statement inserts the details as a new record.

Many thanks

UPDATE tab SET eng="50" seq="30" where name="bni"
 
something like that is best left to a perl,c,or php script
 
syntax:

INSERT [LOW_PRIORITY | DELAYED] [IGNORE]
[INTO] tbl_name [(col_name,...)]
VALUES ((expression | DEFAULT),...),(...),...
[ ON DUPLICATE KEY UPDATE col_name=expression, ... ]
example:

insert into tab ( eng, seq, name )
values ( 50, 30, 'bni' )
on duplicate key update eng=50,seq=30


assumes primary or unique key declared on name

works in mysql 4.1.0

rudy
SQL Consulting
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top