Results 1 to 3 of 3
  1. #1
    Join Date
    Mar 2004

    Best SQL practice on UNIQUE field

    Hi all,

    I have a batch script that a CSV file to a Mysql database.

    I have a unique row named CODE in my mysql table, and I was wondering what was the best thing to do:
    Parse the entier csv file and:
    • Issue a COUNT(*) to know if the CODE is already in the database. If not, issue the insert command.
    • Just issue the INSERT command. Since it is unique, no duplicates will be made.

    We are talking about 500 lines, every hour. I was wondering if it was easier to issue the count(*) and insert, or just insert and let mysql return an error if the code is already in the table ...

    Thanks in advance,
    Last edited by oldunis; 10-02-2009 at 02:43 PM.

  2. #2
    Join Date
    May 2009

  3. #3
    Join Date
    Mar 2005
    Athens, Greece
    You could also use REPLACE.
    Antonis Adamakos @ FuzzFree :: Fully Managed Web Hosting, Development, Online Marketing

Similar Threads

  1. What is the best way to count SQL rows in PHP?
    By Goldfiles in forum Programming Discussion
    Replies: 14
    Last Post: 02-11-2008, 05:13 PM
  2. counting rows
    By ti_nhatrang in forum Programming Discussion
    Replies: 3
    Last Post: 07-20-2007, 10:22 AM
  3. [SQL] Cant Think... Limit to 5 rows?
    By Myriad in forum Programming Discussion
    Replies: 3
    Last Post: 01-26-2006, 01:26 PM
  4. How can I make 3 rows?
    By deet in forum Web Design and Content
    Replies: 8
    Last Post: 08-15-2004, 08:10 AM
  5. PHP mySQL rows
    By kneuf in forum Programming Discussion
    Replies: 8
    Last Post: 03-26-2003, 12:39 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts