|
Neohapsis is currently accepting applications for employment. For more information, please visit our website www.neohapsis.com or email hr@neohapsis.com |
From: Rodrigo Ferreira (rodrigof_silva
yahoo.com)
Date: Wed Mar 24 2010 - 08:26:35 CDT
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
First, if you want no duplicate parent_id, make it unique key (as JW saids). Look at INSERT ... ON DUPLICATE KEY UPDATE, I think this will solve the problem with one statement.
Rodrigo Ferreira
--- On Wed, 3/24/10, Johnny Withers <johnny
pixelated.net> wrote:
From: Johnny Withers <johnny
pixelated.net>
Subject: Re: SELECT and INSERT if no row is returned
To: "Kyong Kim" <kykimdba
gmail.com>
Cc: "mysql" <mysql
lists.mysql.com>
Date: Wednesday, March 24, 2010, 9:32 AM
Make parent_id a unique key. Doing a select first and inserting if no
result will work 99.9% of the time; however, consider 2 rows being
inserted at the same
time.
JW
On Tuesday, March 23, 2010, Kyong Kim <kykimdba
gmail.com> wrote:
> I need to INSERT a row into a table only if it does not exist to
> insure that there won't be duplicate rows.
> Due to the the usage case and the design of the primary key,
> non-unique id + auto increment, I don't think insert ignore is an
> option.
>
> What would be simplest and cheapest way to make sure that given the
> following schema
>
> create table some_table
> ( parent_id int //non-unique
> seq_id int auto_increment ) ENGINE=INNODB
>
> that no row with the same parent_id can be inserted?
>
> Kyong
>
> --
> MySQL General Mailing List
> For list archives: http://lists.mysql.com/mysql
> To unsubscribe: http://lists.mysql.com/mysql?unsub=johnny
pixelated.net
>
>
--
-----------------------------
Johnny Withers
601.209.4985
johnny
pixelated.net
--
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe: http://lists.mysql.com/mysql?unsub=rodrigof_silva
yahoo.com
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]