in reply to Checking for Dupes in MySQL

Many good suggestions concerning unique.

Another technique is available for checking whether a given value appears in a column, without any needing to fetch any data from your backend, and that is:

select 1 from mytable where mycol='foo'

You'll either get a row back, or nothing. In the general case, this is about as cheap as it gets.

--
g r i n d e r

Replies are listed 'Best First'.
Re: Re: Checking for Dupes in MySQL
by Ryszard (Priest) on Nov 30, 2001 at 03:42 UTC
    I agree with grinder here. I would think this is the best method of inserting unique rows into a database.

    The table should have the unique constraint enabled to enforce the integrity. Good application design would *not* have the integrity enforced externaly

    In my mind it would be better to make to graceful calls to the database, rather than making one and traping any errors.