My. SQL Stored Procedures IF NOT EXISTSI have been using MSSQL with ASP. NET alot lately, and I really wanted to get some of the benefits of stored procedures into a PHP application Im writing. Ive known My. SQL has supported them for a while but I guess I was always a bit too lazy to go through old code and convert it. I used the tool Heidi. SQL to make the process a bit more painless. The first stored procedure I attempted to write accepted 3 parameters and based on one of them checks a lookup table, and creates a new value in it if the same value does not already exist. Mysql Update If Exists Insert If Not' title='Mysql Update If Exists Insert If Not' />MySQL has been criticized in the past for not supporting all the features of other popular and more expensive DataBase Management Systems. However, MySQL continues to. Here Mudassar Ahmed Khan has explained how to perform Bulk Insert records and Update existing rows if record exists using C and VB. Net. SqlBulkCopy as the name. Normally I would use an IF NOT EXISTS clause, which in Microsoft SQL would look like this. CREATE PROCEDURE some. Proc. Some. Param varchar5. DECLARE Some. Id int. IF NOT EXISTSSELECT 1 FROM lookuptable WHERE some. Field Some. Param. INSERT INTO lookuptable some. I started by googling, and found this article which talks about mutex tables. I have a table with 14 million records. If I want to add more data in the same format. Field VALUESsome. Param. SELECT Some. Id identity. SELECT Some. Id id FROM lookuptable WHERE some. Free Download Nature Animation Pictures Powerpoint Presentation. Field Some. Param. Do some other stuff here with the id you just received and other data. If you insert a data row by using the ON DUPLICATE KEY UPDATE clause in an INSERTstatement, the mysqlinsertid function will return not the same results as if you. I want to add a row to a database table, but if a row exists with the same unique key I want to update the row. For example, insert into table id, name, age values. The above snippet would take a value, check a table for it, get its id, and if the record doesnt exist in the database create it and return the id. Then you could continue on and insert that id into another table or what have you. Accomplishing the same thing with a My. SQL stored procedure is a bit different. The code below shows how you would accomplish the same task. CREATE PROCEDURE some. Proc IN inSome. Param INT. NOT DETERMINISTIC. SQL SECURITY DEFINER. DECLARE Some. Id int. DECLARE Check. Exists int. SET Check. Exists 0. SELECT count INTO Check. Exists from lookuptable WHERE some. Field inSome. Param. IF Check. Exists 0 THEN. SELECT id INTO Some. Id FROM lookuptable WHERE some. Field inSome. Param. INSERT INTO lookuptable some. Field VALUESinSome. Param. SELECT Some. Id LASTINSERTID. Do some other stuff here with the id you just received and other data. Im sure I will find some more differences in things I am used to doing with stored procedures using T SQL, and when I do Ill post them here.