[web] SQL - avoid duplicates in a table

Started by
2 comments, last by unknownProdigy 17 years, 10 months ago
This is a SQL question. I'm using MySQL. I want to be able to insert two values (a, b) in one row in a table, but only if these two values do not already exists in the same row in the exact columns. How would I be able to create a stored function so that I don't create duplicates in the table? I do not want these two columns to be unique because they won't be. Thanks in advance.
Advertisement

Sounds to me like the 2 columns together are unique, so you can assign a primary key that spans the 2 columns (right?).

The other way is just to check manually using an other select statement..

Edo
Edo
Create

(a) a key comprised of those columns that need to be unique.

or

(b) an unique index comprised of the columns if there is already
a key defined.

!!! DO NOT MESS UP YOUR DATABASE WITH TRIGGERS OR MANUAL VERIFICATION !!!
Yeah, I forgot to mention that I already had another column as a primary key.
I looked up indexes and it was a good solution. Thanks for your help.

This topic is closed to new replies.

Advertisement