[web] SQL - avoid duplicates in a table
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.
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
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 !!!
(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 !!!
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement