Questions tagged [unique-index]

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

A unique index on a table guarantees that the index key contains no duplicate values and therefore ensures that every row in the table is in some way unique. Specifying a unique index makes sense only when uniqueness is a essential for the data in a table.

A unique index on a field (or set of fields) prevents two records from existing in the table with the same value in the indexed field(s). ServiceNow uses several unique indexes out-of-box to protect certain tables from duplicate record confusion.

333 questions
0
votes
3 answers

Unique index key in multiple columns

I need to define unique index key in my table using SQL Server. For example: ID Contact1 Contact2 RelationType ------------------------------------------------------------------- 1 1 2 sister // 1 is the 2nd…
-1
votes
0 answers

SQL Unique Index on Multiple Columns. Did the index work then for where?

If I have a UNIQUE index over multiple columns like this: CREATE UNIQUE INDEX idx_name ON Tablename(column1, column2, column3) When I run this SQL statement: SELECT * FROM Tablename WHERE column1 = 'example' My question: does the index for WHERE…
Sametcey
  • 141
  • 1
  • 6
-1
votes
2 answers

Why does Oracle not allow DML for null valued referencing columns?

Why is DML not allowed for null valued referencing columns when the using index of the key referenced by the foreign key R constraint is unusable? Below contains the setup, an insert example, two update examples, and two delete examples. All of…
-1
votes
1 answer

Find unique values in python list of dictionaries

I have a list with the following sample key value pairs: results : {'ROI_0':[{'obj_id':1,'obj_name':'truck', 'obj_confi':93.55, 'bb_box': ['x','y','w','h']}, {'obj_id':2,'obj_name':'truck', 'obj_confi':91.35, 'bb_box':…
Chay
  • 3
  • 1
-1
votes
1 answer

Why does MySQL take unique index over primary index?

I have 2 very simple tables created as below: create table company( company_id int auto_increment, company_no varchar(20), company_name varchar(20), primary key(company_id), unique index uni_company_no(company_no) ); create…
Milo Zou
  • 1
  • 1
-1
votes
1 answer

Create a row which does not violate a unique index

I have a table with Id, AccountId, PeriodId, and Comment. I have a unique index for (AccountId, PeriodId). I want to create such a row which does not violate the unique index. AccountId and PeriodId cannot be null, they are foreign keys. My only…
Istvan Heckl
  • 864
  • 10
  • 22
-1
votes
1 answer

I want to add records to the table but there is a duplicate

I have a table named Car and I want to add this records; insert into Car values ('a', 'a'), ('a', 'b'), ('a', 'c'),('b', 'b'), ('b', 'c'), ('c', 'd'), ('d', 'd'); I got this massage: ( ERROR 1062 (23000): Duplicate entry 'a' for key a) so how I…
Stack
  • 17
  • 4
-1
votes
2 answers

Unique table constraint

I have a table as follows: CREATE TABLE `b` ( `b1` int(11) DEFAULT NULL, `b2` int(11) DEFAULT NULL, UNIQUE KEY `b1` (`b1`,`b2`) ) ENGINE=InnoDB DEFAULT CHARSET=latin1 Here, the unique table constraint is given for 2 fields. But, in the show…
user14151025
-1
votes
1 answer

Can a UNIQUE 'WHERE' index which allows multiple NULLS be used as the primary key for a foreign key relationship?

Using SQL Server on Azure: 12.0.2000.8 I've defined the following unique index for TablePrimary: CREATE UNIQUE NONCLUSTERED INDEX [IX_TablePrimary_Id] ON [dbo].[TablePrimary] ([PrimaryId] ASC) WHERE [PrimaryId] IS NOT NULL The WHERE clause allows…
Yossi G.
  • 939
  • 1
  • 8
  • 22
-1
votes
1 answer

Suggestion for sql scenario

I am having two columns in table InventoryId | RevisionId ------------------------- 1 | 1 2 | 1 2 | 2 2 | 2 3 | 1 3 | 2 3 | 3 3 | 3 but from now on I want to prevent following records 2 | 2 2 | 2 3 | 3 3 …
-1
votes
2 answers

Duplicate Error when inserting unique non duplicate values T-SQL

Here is my other mistake I can't fight: I am trying to add (INSERT INTO sql statement) a unique records from the WHID field (ClientEpisode table) into WHID field (EHREpisode table): INSERT INTO [WH].[Fact].EHREpisode…
Hell-1931
  • 489
  • 1
  • 6
  • 24
-1
votes
1 answer

Unique constraint violated when I have a non-unique index

In my data warehouse I have table with unique key TABLE_UK on columns (ID,IDATE,NAME,GENERATION,O_ID,NODE_ID) and a non-unique index PER_INDEX on columns (ID,NAME,GENERATION,STRUCTURE_AREA,O_ID). While loading data from a source table I am receiving…
priya77
  • 175
  • 2
  • 10
  • 24
-1
votes
1 answer

Cannot create Unique Partial Indexes - Sqlite3

Consider the following table. CREATE TABLE IF NOT EXISTS wsfiles ( id INTEGER PRIMARY KEY AUTOINCREMENT, website_id integer NOT NULL, parent_id integer, archive_id integer, path character varying, path_sha character varying NOT NULL, …
Yasitha
  • 2,233
  • 4
  • 24
  • 36
-1
votes
3 answers

Can I use a subquery to complete a where clause?

I have 2 tables joined by the membership.ID and memberDues.memberID. The membership table has a column, firstLast, which is unique for each row. If I have a value for firstLast, i should be able to then find the membership.ID and compare it to the…
parboy
  • 67
  • 8
-1
votes
1 answer

Mysql UNIQUE INDEX on 3 fields when one field equals a value

I want to add a UNIQUE INDEX on 3 fields when one of the fields is True. ie equal to 1 UNIQUE INDEX pkg_box_delivered (package_id, box_id, delivered) WHERE delivered = 1; I need a Alter statement and how add it to a Create Table statement.
Avril
  • 25
  • 4
1 2 3
22
23