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
5 answers

Primary key on 2 tables

i have two tables, one 'master' and one 'child' table. Each table has a field named 'ProductNo', which is defined as PRIMARY KEY and UNIQUE. Is it possible to define the field 'ProductNo' in the table 'child' and the same field in table 'master' as…
frgtv10
  • 5,300
  • 4
  • 30
  • 46
2
votes
1 answer

How to find which column throws unique key constraint exception when there are more than one unique key columns in table?

I am new to C# .NET. I have been trying since 2 days, but I couldn't succeed. I have created windows application. I have table which has two unique columns email,phone. I want to find the column name which throws the unique key constraint exception…
Aniket Kulkarni
  • 12,825
  • 9
  • 67
  • 90
2
votes
4 answers

How to add to a MySQL table only if the record doesn't already exist?

I'm getting an array of strings from a JSON object. I want to save these strings in a DB, but only if they're not already in there. What's the best way to compare what's already in the DB with what I'm about to enter, and exclude matches? I'm using…
Alex Mcp
  • 19,037
  • 12
  • 60
  • 93
2
votes
2 answers

Validate unique keys with asp.net mvc and linq to sql?

I have a sql server table with 2 fields, ID (primary key) and Name (unique key). I'm using linq to sql to produce model objects for asp.net MVC from this table. To perform the model validation I've implemented IDateErrorInfo in a partial…
Cephas
  • 794
  • 8
  • 14
2
votes
2 answers

mysql update with ON DUPLICATE KEY UPDATE

I have a table of foreign key and I am trying to merge duplicate records. My table looks like this: user_id | object_id The table is a two column unique key, so there cannot be duplicates. My query looks like this: UPDATE user_object SET object_id…
busbina
  • 549
  • 1
  • 7
  • 19
2
votes
3 answers

Create hexadecimal number in SQL

I want to generate unique hexadecimal numbers in SQL. How can I do this? If you know how to generate in c# please also include that.
Waheed
  • 10,086
  • 20
  • 53
  • 66
2
votes
1 answer

NHibernate caching on unique indexes?

I have a few classes which have a property which is unique to that object, for example for the User class the property Username should never be duplicated. NHibernate doesn't seem to support loading of an object by unique key which is then cached in…
John_
  • 2,931
  • 3
  • 32
  • 49
2
votes
2 answers

MySQL dilemma: composite unique key across tables

I am attempting to implement an "extension" table structure for some stats that I am gathering from multiple sources. My "parent" table looks something like this: `test_parent` ( `id` int(11) unsigned NOT NULL AUTO_INCREMENT, `date` date NOT…
smp7d
  • 4,947
  • 2
  • 26
  • 48
2
votes
0 answers

Unable to print unique items based on variant_id in jinja template

I am trying to print the unique items based on their variant ids. Only unique items are to be printed. {% set unique_items = [] %} {% for item in items %} {% if item.variant_id not in unique_items %} {% set unique_items = unique_items +…
2
votes
1 answer

Foreign key referencing unique composite key or single primary key

I am creating a database for an app that helps learn a language. I need to create tests that vary by section (test for grammar, about text, etc), topic and level. USER id (pk, autoincrement) name last_name email (unique) level_id password LEVEL id…
2
votes
0 answers

Verifying Userprofile "Uniqueness" of Meta Value at the time of creation for wordpress user custom field meta-key "association_id"

I have a custom user profile field "association_id". I can see the field the underlying wordpess db table (usermeta) with the 'meta_key' as "association_id" and the 'meta_value' whatever that I maintain for each user. add_action(…
2
votes
7 answers

Is there a programmatic way to get a mobile device's unique identifier?

I need a way to know the uniqueness per user, whether it be for iPhone, Android, or Windows Phone devices. If there is no universal way, i was wondering if saving the phone number would be legitimate (i.e. legal). Anybody have any experience in…
AlvinfromDiaspar
  • 6,611
  • 13
  • 75
  • 140
2
votes
1 answer

PostgreSQL - Duplicate Unique Key

On my table I have a secondary unique key labeled md5. Before inserting, I check to see if the MD5 exists, and if not, insert it, as shown below: -- Attempt to find this item SELECT INTO oResults (SELECT domain_id FROM db.domains WHERE…
Anthony Greco
  • 2,885
  • 4
  • 27
  • 39
2
votes
2 answers

Faster way to convert three uint32_t to generate a unique key in C

I have three uint32_t that when combined, they will generate a unique key. I have to do this about 100M or more & potentially several times a day and store that in a key-value database. I'd like to keep the key to the least amount of bytes possible.…
Peter D
  • 47
  • 5
2
votes
1 answer

CosmosDB unique key issue

I am facing issue with CosmosDB unique key constraint. After setting up the unique key, I am able to insert duplicate documents withing same partition key. Please help me to understand if I am doing anything wrong. Created a container with the…
Balaji A
  • 43
  • 6