Questions tagged [unique-constraint]

Unique-constraint is an index that sets one or multiple fields to be unique in a data entity

1353 questions
80
votes
10 answers

A Queue that ensure uniqueness of the elements?

I'm looking for a implementation of java.util.Queue or something in the Google collection who behave like a Queue, but also ensure that each element of the queue is unique. (all further insertion will have no effect) It's that possible, or will I…
Antoine Claval
  • 4,923
  • 7
  • 40
  • 68
79
votes
3 answers

Unique Key Violation in SQL Server - Is it safe to assume Error 2627?

I need to catch violation of UNIQUE constraints in a special way by a C# application I am developing. Is it safe to assume that Error 2627 will always correspond to a violation of this kind, so that I can use if (ThisSqlException.Number == 2627) { …
User
  • 3,244
  • 8
  • 27
  • 48
79
votes
3 answers

MySQL delete multiple rows in one query conditions unique to each row

So I know in MySQL it's possible to insert multiple rows in one query like so: INSERT INTO table (col1,col2) VALUES (1,2),(3,4),(5,6) I would like to delete multiple rows in a similar way. I know it's possible to delete multiple rows based on the…
srchulo
  • 5,143
  • 4
  • 43
  • 72
78
votes
4 answers

SQL unique varchar case sensitivity question

I'm trying to populate a SQL table with a list of words. The table itself it pretty simple: CREATE TABLE WORDS( ID BIGINT AUTO_INCREMENT, WORD VARCHAR(128) NOT NULL UNIQUE, PRIMARY KEY(ID) ); The problem I'm running into is this: when I do…
Seth
  • 5,596
  • 8
  • 42
  • 56
78
votes
6 answers

Allow null in unique column

I've created the following table: CREATE TABLE MMCompany ( CompanyUniqueID BIGSERIAL PRIMARY KEY NOT NULL, Name VARCHAR (150) NOT NULL, PhoneNumber VARCHAR(20) NOT NULL UNIQUE, Email VARCHAR(75) UNIQUE, CompanyLogo BYTEA ); The…
liv a
  • 3,232
  • 6
  • 35
  • 76
77
votes
7 answers

Django Unique Together (with foreign keys)

I have a situation where I want to use the Meta options of unique_together to enforce a certain rule, here's the intermediary model: class UserProfileExtension(models.Model): extension = models.ForeignKey(Extension, unique=False) userprofile…
chiurox
  • 1,549
  • 3
  • 18
  • 28
67
votes
5 answers

How can I create a SQL unique constraint based on 2 columns?

I have a Table like this one: |UserId | ContactID | ContactName --------------------------------------- | 12456 | Ax759 | Joe Smith | 12456 | Ax760 | Mary Smith | 12458 | Ax739 | Carl Lewis | 12460 | Ax759 | …
63
votes
5 answers

Is there a way to enforce unique constraint on a property (field) other than the primary key in dynamodb

In dynamodb, if you want to enforce uniqueness in a field other than the primary key (like were you have a users table and want unique email addresses for users while primary key is a userid which is a number) is there a way other thans scanning the…
Ali
  • 18,665
  • 21
  • 103
  • 138
61
votes
13 answers

UNIQUE constraint failed: sqlite database : android

I am trying to insert values in table. But there is only one value inserted. I am getting an error in log cat when I am trying to insert new values. Log cat shows : abort at 13 in [INSERT INTO…
user5669913
57
votes
6 answers

How do you validate uniqueness of a pair of ids in Ruby on Rails?

Suppose the following DB migration in Ruby: create_table :question_votes do |t| t.integer :user_id t.integer :question_id t.integer :vote t.timestamps end Suppose further that I wish the rows in the DB contain…
dfrankow
  • 20,191
  • 41
  • 152
  • 214
53
votes
1 answer

Grails domain class: unique constraint for multiple columns

Suppose a simple Grails domain class: class Account { String countryId; String userName; String password; static constraints = { ...???... } } It is required that user names are unique for a particular countryId, thus…
53
votes
7 answers

Unique index or unique key?

What is the diffrence between a unique index and a unique key?
fariba
  • 665
  • 1
  • 8
  • 7
50
votes
3 answers

MySQL: ALTER IGNORE TABLE gives "Integrity constraint violation"

I'm trying to remove duplicates from a MySQL table using ALTER IGNORE TABLE + an UNIQUE KEY. The MySQL documentation says: IGNORE is a MySQL extension to standard SQL. It controls how ALTER TABLE works if there are duplicates on unique keys in the…
Philippe Gerber
  • 17,457
  • 6
  • 45
  • 40
50
votes
3 answers

Creating UNIQUE constraint on multiple columns in MySQL Workbench EER diagram

In MySQL Workbench's EER diagram, there is a checkbox to make each column in a table unique, not null, primary key etc. However, I would like to have a UNIQUE constraint on multiple columns. Is it possible to add it in in MySQL Workbench's EER…
46
votes
4 answers

Unique Constraint vs Unique Index

I’m interested in learning which technique developers prefer to use to enforce uniqueness in SQL Server: UNIQUE CONSTRAINT or UNIQUE INDEX. Given that there is little difference in the physical implementation of each, how do you decide which is…
bobs
  • 21,844
  • 12
  • 67
  • 78
1
2
3
90 91