CREATE TABLE Permission (
permissionID INTEGER PRIMARY KEY UNIQUE,
user INTEGER
location INTEGER
);
I don't want to have user or location to be UNIQUE
because I can have multiple rows with user containing the same data, or multiple rows with location containing the same data. I just want to avoid having both user and location having some value, with that row repeating any number of times.
Ex: this is okay
permissionID user location
--------------------------
1 1 2
2 2 2
3 2 1
but this is not okay:
permissionID user location
--------------------------
1 1 2
2 1 2
because a row already exists in which user = 1 and location = 2.
How can I avoid duplicates?
Declare a unique constraint on (user, location).
First option is creating a
unique constraint
onuser
andlocation
columns which will avoid duplicates.Else if you already have duplicate rows in table you need to delete the duplicate rows and create
unique constraint
To remove duplicate rows use this query