List:General Discussion« Previous MessageNext Message »
From:Mike Tuller Date:October 16 2003 7:00pm
Subject:Re: Check for data before inserting
View as plain text  
Unless I am mistaken on REPLACE's use, I don't think that will work. The
example I have in the O'Reilly MySql book that I have shows this.

REPLACE(string, old, new)
Returns a string that has all occurances of the substring old replaced with
new(e.g., REPLACE('black jack', 'ack', 'oke') returns "bloke joke").

I will explain what I am wanting to do.

I have a database that stores information about computers, and the
identifier is the ethernet address. I have a script that pulls the data from
a text file, and I want it so that if the ethernet address does not exist,
then it will insert the information into all columns. os_version,
ip_address, etc. If the ethernet address is not present, then it will update
the information in the fields.

I think I have to do a SELECT * from hardware_assets where ethernet_address
= $ethernet_address and then if there is a match, that row is updated, if
there is no match, then the data is inserted into a new row.


Mike

> From: Brent Baisley <brent@stripped>
> Date: Thu, 16 Oct 2003 14:29:21 -0400
> To: Mike Tuller <mtuller@stripped>
> Cc: MySql List <mysql@stripped>
> Subject: Re: Check for data before inserting
> 
> It sound like you want to use REPLACE instead of the SELECT and
> INSERT/UPDATE combo. Replace will insert if the record doesn't exist
> and update if it does.
> 
> 
> On Thursday, October 16, 2003, at 01:27 PM, Mike Tuller wrote:
> 
>> I have a shell script that I have data entered into a database, and
>> instead
>> of just entering in the data blindly, I want it to check to see if the
>> item
>> it is entering exists already, and if it does, update the information
>> rather
>> than inserting it. So I want to run a select statement, and if results
>> come
>> back, have the data updated, and if not have it inserted.
>> 
>> I know how to do this in PHP with $query_total_rows. Is there some way
>> in
>> SQL to do this, or do I need to figure out a way to do it in the shell
>> script?
>> 
>> Thanks,
>> Mike
>> 
> -- 
> Brent Baisley
> Systems Architect
> Landover Associates, Inc.
> Search & Advisory Services for Advanced Technology Environments
> p: 212.759.6400/800.759.0577
> 
> 
> -- 
> MySQL General Mailing List
> For list archives: http://lists.mysql.com/mysql
> To unsubscribe:  
> http://lists.mysql.com/mysql?unsub=1
> 

Thread
Check for data before insertingMike Tuller16 Oct
  • Re: Check for data before insertingBrent Baisley16 Oct
    • Re: Check for data before insertingMike Tuller16 Oct
      • Re: Check for data before insertinggerald_clark16 Oct
    • Re: Check for data before insertingRay16 Oct
RE: Check for data before insertingMike Knox17 Oct
  • Re: Check for data before insertingDirector General: NEFACOMP17 Oct
    • Re: Check for data before insertingGabriel Ricard17 Oct
  • Re: Check for data before insertinggerald_clark17 Oct
    • Autoincrement in MYISAM vs INNODBGordon17 Oct
RE: Check for data before insertingSimon Green17 Oct
  • Re: Check for data before insertinggerald_clark17 Oct
  • Re: Check for data before insertingDirector General: NEFACOMP17 Oct