Questions tagged [unique-key]

A key is a set of attributes that is irreducibly unique and non-nullable within a table.

A key is a set of attributes that is irreducibly unique and non-nullable within a table. Irreducible means that all the attributes of the key are necessary to guarantee uniqueness - remove any one attribute and the uniqueness property would be lost. A key may consist of zero, one or more attributes and a relational table (relation variable) must have at least one key and may have more than one.

Keys are unique by definition so the commonly used term "unique key" is actually a tautology.

515 questions
3
votes
1 answer

Apache Solr - Document is missing mandatory uniqueKey field: id

I'm using Solr7.1 (SolrCloud mode) and I don't have requirement to enforce document uniqueness. Hence I marked id field (designated as unique key) in schema as required="false".
3
votes
3 answers

Unique constraint on tables for particular values of a field

I have an invoice table. It has many fields, but the problem is around 2 main fields InvoiceNo - alphanumeric values Deleted - boolean 1 or 0 ,to represent a record is deleted or not. Our business requires InvoiceNo to be unique. However if a row…
Mohan
  • 172
  • 1
  • 11
3
votes
2 answers

need to create indexes for multi-column unique key columns?

For example, table FOO id name type --------------------------------------------- bigint(20) varchar(30) smallint(4) unique key name_type (name, type). index will be created for (name, type). But if many…
Dave
  • 759
  • 2
  • 9
  • 31
3
votes
1 answer

sql server unique key for each partition

I have a table that contain 3 columns: ID int [primary key] BranchRef int [foreign key] Code int I need to [Code] be unique in each [BranchRef] like: ID BranchRef Code 1 1 1 2 1 2 3 2 …
3
votes
4 answers

What should be the unique ID of a machine? Its motherboard ID? Windows Product ID?

I want to retrieve the unique ID of a machine. Like others I also did a lot of research, and found none of the process of Unique ID generation works perfectly. For Motherboard Serial Number (ID): It is Unique; it can't be changed. However, it may…
Rick2047
  • 1,565
  • 7
  • 24
  • 35
3
votes
1 answer

Can a Foreign key reference a combined Unique key?

Is there a way to reference a foreign key to a 2row-unique key? CREATE TABLE factura( num_factura varchar(10), ID varchar(10), UNIQUE (num_factura,ID) ); CREATE TABLE detalle_factura( clave_factura varchar(30), FOREIGN KEY(clave_factura)…
3
votes
1 answer

sql server: Unique constraint generates unique key and unique index

I’ve got 2 tables: attCatAppSet, attCatAppSet_translation On both tables I’ve applied a unique constraint on 2 columns (that are not Primary Keys), so that column-pair values can't be duplicated. GO ALTER TABLE attCatAppSet ADD CONSTRAINT…
Carlo Luther
  • 2,402
  • 7
  • 46
  • 75
3
votes
1 answer

Primary Key Identity Value Increments On Unique Key Constraint Violation

I have a SqlServer 2008 table which has a Primary Key (IsIdentity=Yes) and three other fields that make up a Unique Key constraint. In addition I have a store procedure that inserts a record into the table and I call the sproc via C# using a…
Jed
  • 10,649
  • 19
  • 81
  • 125
3
votes
5 answers

how can i have a unique column in many tables

I have ten or more(i don't know) tables that have a column named foo with same datatype. how can i tell sql that values in all the tables should be unique. I mean If(i have value "1" in table1) I should NOT be able to have value "1" in table2
Behrooz
  • 1,696
  • 2
  • 32
  • 54
3
votes
2 answers

How to use only the year of a DateTime column in a SQL Unique Constrain?

Im creating a Unique constraint, that only allows to use the a Registry number per year, with this i mean that can exist more that one number 2, in the registry but only if this were created on different years. I have heard that it is possible to do…
M.Lopez
  • 67
  • 6
3
votes
3 answers

Should android resource id's be used for non-layout code?

The android resource ID is often used as a way to get/modify an XML-defined layout component. Is it acceptable to use them purely as unique identifiers for any Java code in your Android application? For example: Using Android Resource…
codepringle
  • 343
  • 2
  • 14
3
votes
2 answers

Unique key can use as primary key then why we keep another primary key?

CREATE TABLE IF NOT EXISTS `tbl_users` ( `id` int(11) NOT NULL AUTO_INCREMENT, `username` varchar(50) COLLATE latin1_general_ci NOT NULL, `passd` varchar(50) COLLATE latin1_general_ci NOT NULL, PRIMARY KEY (`id`), UNIQUE KEY `username`…
Pravin Kumar
  • 31
  • 1
  • 2
3
votes
3 answers

Is a 64 bit random ID good enough for about 10 million entries?

I was inspired by this unique id code to generate a random 64 bit identifier. My question: will this be good enough for about 10 million entries? def self.generateId (0..15).collect{(rand*16).to_i.to_s(16)}.join end
Mark
  • 6,647
  • 1
  • 45
  • 88
3
votes
1 answer

How would you skip vulgar words using base 36 against an Id column in sql server 08?

I need the shortest possible Ids so I figure base-36 would work wonderful for this. The thought is I'll just use an auto-incrementing Id field as the primary key and then create a base-36 userid. Unfortunately I'll inevitably run into a lot of…
Chance
  • 11,043
  • 8
  • 61
  • 84
3
votes
1 answer

How to create a Mysql unique case insensitive index with accentuation - (or use NO collation)

I am fighting with collations. I want to build a table with a unique index on word that is case insensitive but that differenciate "a" from "à". It means that "de" and "dé" should be 2 distinct entries but de, De, DE,dE should be the same. Is there…
Sunny
  • 11
  • 1
  • 4