Jump to content
  • Advertisement
Sign in to follow this  
unknownProdigy

[web] SQL - avoid duplicates in a table

This topic is 4397 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
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

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
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!