Questions tagged [composite-primary-key]

Composite primary key is a primary key, which consists of more than one column. The column combination guarantees the uniqueness of the PK.

A Composite Primary Key is a Composite Key, which is assigned as Primary.

Primary key is a single field or the least combination of fields that uniquely identifies each record in table. When the primary key consists of more than one field, when we are talking about composite primary key. Composite or not, is the most appropriate key to be main key of reference for the table.

The primary key must not be null and must contain only unique values.

Primary keys are mandatory for every table. When choosing a primary key from the pool of candidate keys, always choose a single simple key over a composite key.

Links

984 questions
3
votes
1 answer

SELECT with OR using two columns with index is very slow

There is a table with the following definition in my Cockroach database: CREATE TABLE foo_value ( foo_id_a INT NOT NULL, foo_id_b INT NOT NULL, value FLOAT NULL, create_date_time TIMESTAMP NULL, update_date_time TIMESTAMP NULL, …
3
votes
1 answer

Composite Primary Keys in Rails still being ignored

I've set up a database that has composite primary keys for Ruby on Rails. Creating the migration works, but when I start to seed the database, I still get a warning that "Active Record does not support primary keys." and that the "Composite primary…
limciana
  • 331
  • 1
  • 3
  • 17
3
votes
1 answer

Does doctrine support composite keys in many-to-many join tables?

I have entities Channel and Post. Channel has simple integer id. Post has composite key made of its own id and channel_id. I would like to have many-to-many relationship between those entities(mention), so that one Post might have many mentioned…
svgrafov
  • 1,970
  • 4
  • 16
  • 32
3
votes
1 answer

Entity Framework 6 Database First Doesn't Generate Entity on Table With Composite Key

Suppose I have the following table definition with a composite primary key: create table [dbo].[CustomerRequests] ( [CustomerId] int not null, [RequestId] int not null, constraint [PK_CustomerRequests] primary key clustered ([CustomerId]…
3
votes
1 answer

Spring CrudRepository cannot share generated id in composite primary key

I'm trying use spring CRUDRepository for inserting new object into database using JPA database model (User.java, UserInfo.java). Database model are related with composite primary key (UserPK.java), where one of them is automatic generated (field…
3
votes
2 answers

Why does SQLite insert duplicate composite primary keys?

Code: import sqlite3 c = sqlite3.Connection(':memory:') c.execute('CREATE TABLE foo(a INTEGER, b VARCHAR(8), PRIMARY KEY(a, b))') c.execute('INSERT INTO foo(a) VALUES (1)') c.execute('INSERT INTO foo(a) VALUES (1)') print(c.execute('SELECT * FROM…
user541686
  • 205,094
  • 128
  • 528
  • 886
3
votes
2 answers

composite primary key not updating after save

Here is a minimal test case that forms the basis of my question. Why is it that even though user is properly saved, the attribute user.id isn't updated? Attempting to re-find the record in the database fetches it without issue and the id attribute…
3
votes
1 answer

No partitioning defined in Many to Many conjugation table

I have Many to Many relation between jobs and eqtypes so I have made a third table named eqtype_jobs. However, in this relation conjugation, normalization, table I did not make an independent primary key id for example, I just set both job_id and…
3
votes
1 answer

Syntax to alter and create composite foreign key in postgres

I have a table in Postgres with a composite primary key. What's the syntax to alter another existing table to add a composite foreign key to the composite primary key of the first table?
3
votes
1 answer

metaData.getPrimaryKeys() returns a single row when the key is composite

I have an issue with a compound primary key in JDBC using SQLite driver. The getPrimaryKeys() method from a DatabaseMetaData object returns a single row when I have verified the key is actually a compound key consisting of two columns. Does any one…
Loveen Dyall
  • 824
  • 2
  • 8
  • 20
3
votes
1 answer

Update infragistics igGrid with composite primaryKeys in jQuery

I am using Infragistics igGrid where I have multiple primary keys: $("#grid_selector").igGrid({ autoCommit: true, width: "100%", height: '500px', autoGenerateColumns: false, primaryKey:…
sarojanand
  • 607
  • 1
  • 11
  • 30
3
votes
2 answers

Interchangeable, composite primary keys

I have a table foo that has only two fields: fooIdA and fooIdB (both of the same type). Those are composite primary keys, so: primary key (fooIdA, fooIdB)... Considering this, how can I make all permutations of the keys to be the same? That is,…
ptkato
  • 668
  • 1
  • 7
  • 14
3
votes
1 answer

How to add composite primary keys in db using Rails?

I'm using Rails 5.0 with Postgresql 9.5 I'm in need to add composite primary keys to my model 'User_achievement' (to link 'User' and 'Achievement' models as you may guess). So I tried using the "composite_primary_keys" gem. I followed all the…
3
votes
1 answer

How should I define a composite primary key for an existing database table?

I'm working on a Core MVC project that reads data (no writing required) from a pre-existing database. Unfortunately this database is a total mess, but I cannot change anything in it (and even if I could, I wouldn't touch it with a 10-foot…
3
votes
1 answer

Using JPA Entity Inheritance with IdClass Composite Primary Key involving Object references

I am trying to use IdClass composite primary keys giving the following scenarios: Primary keys involve object reference (entity objects) Entity object in primary key are foreign keys to other entities (has OneToOne or ManyToOne mapping) The entity…
Ayemi
  • 43
  • 1
  • 4