What I have is a shell script that gathers information from a computer, and I want the script to check to see if there is currently a record that already exists that has a certain Ethernet(MAC) address. I would also like to have an ID number for the record that auto-increments so that I can have an asset number to display on a web page. (Some assets I enter may not have an Ethernet address because I am creating a database for hardware assets. Computers, printers, etc., so I need to have an asset ID)
I have ethernet_address set as a Unique Key, and asset_id set as Primary_Key and to auto-increment. If I just use replace like below, every time the record is updated, the asset number that is set to auto-increment is updated. So if it was 5 before, it is now 6. I don't what the asset_id to change of course. /usr/local/mysql/bin/mysql --user=$username --password=$password --host=$server cetechnology -e \ "REPLACE INTO hardware_assets (ethernet_address, operating_system)\ VALUES \ ('$ethernet_address', '$operating_system')"; I don't currently have MySql 4.1 running on my server, I have the 3.23.53 that comes with OS X Server 10.2, so if the suggestion you gave me is the only way (or the best) I will have to upgrade the server. If there is another way to do the same thing, please let me know. Mike > From: Egor Egorov <[EMAIL PROTECTED]> > Date: Mon, 26 Jan 2004 15:40:54 +0200 > To: [EMAIL PROTECTED] > Subject: Re: If Else statement > > Mike Tuller <[EMAIL PROTECTED]> wrote: >> I am trying write a shell script to check to see if a record exists and if >> it does, update information, and if it doesn't insert information. Is there >> a way to do an if else statement in MySql? >> > > If you have PRIMARY KEY or UNIQUE index, take a look at REPLACE and INSERT .. > ON DUPLICATE KEY UPDATE statements: > http://www.mysql.com/doc/en/REPLACE.html > http://www.mysql.com/doc/en/INSERT.html > > INSERT .. ON DUPLICATE KEY UPDATE is supported since v4.1.0. > > > > -- > For technical support contracts, goto https://order.mysql.com/?ref=ensita > This email is sponsored by Ensita.net http://www.ensita.net/ > __ ___ ___ ____ __ > / |/ /_ __/ __/ __ \/ / Egor Egorov > / /|_/ / // /\ \/ /_/ / /__ [EMAIL PROTECTED] > /_/ /_/\_, /___/\___\_\___/ MySQL AB / Ensita.net > <___/ www.mysql.com > > > > > -- > MySQL General Mailing List > For list archives: http://lists.mysql.com/mysql > To unsubscribe: > http://lists.mysql.com/[EMAIL PROTECTED] > -- MySQL General Mailing List For list archives: http://lists.mysql.com/mysql To unsubscribe: http://lists.mysql.com/[EMAIL PROTECTED]