Sign in to follow this  

[web] SQL - avoid duplicates in a table

This topic is 4205 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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.

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites
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 !!!

Share this post


Link to post
Share on other sites

This topic is 4205 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this