mysql insert multiple rows, return rows that failed

Posted by Glenn on Stack Overflow See other posts from Stack Overflow or by Glenn
Published on 2010-04-09T13:14:41Z Indexed on 2010/04/09 13:23 UTC
Read the original article Hit count: 257

Filed under:
|

When I try to insert (lets say) 30 rows in my table.

For example

    INSERT INTO customers(cust_name,
   cust_address,
   cust_city,
   cust_state,
   cust_zip,
   cust_country)
VALUES(
        'Pep E. LaPew',
        '100 Main Street',
        'Los Angeles',
        'CA',
        '90046',
        'USA'
     ),
      (
        'M. Martian',
        '42 Galaxy Way',
        'New York',
        'NY',
        '11213',
        'USA'
   ), ... ;

And cust_name has to be unique. How can I then identify the records that failed to insert because their cust_name already exists?

Is it possible to return them?

© Stack Overflow or respective owner

Related posts about mysql

Related posts about mysql-query