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
4
votes
2 answers

How to create composite-primary-key in rails 4

Please help me to convert this PostgreSQL table to rails migration file and model CREATE DATABASE ip2location WITH ENCODING 'UTF8'; \c ip2location CREATE TABLE ip2location_db1( ip_from integer(10) NOT NULL, ip_to integer(10) NOT NULL, …
4
votes
2 answers

Is primary key also index?

Does primary key constraint on a mysql database table column automatically mean there is an index created on given column? If it does, could we generalize it for any database or it just depends on database implementation? If it does and also if…
sharpener
  • 1,383
  • 11
  • 22
4
votes
0 answers

Rails - composite primary key as foreign key - relation doesn't work

I have some problem with models with composite primary key. Look at my code Migrations class CreateDataSets < ActiveRecord::Migration def change create_table :data_sets do |t| t.integer :synchronization_report_id, null: true …
4
votes
2 answers

Performance comparison of surrogate & composite key

If a database has attributes A1, A2, A3...An and A1, A2 & A3 can form composite key together, is it better to use a surrogate key instead of a composite key? Using a surrogate key will improve the Insertion execution speed of records (this supports…
Adithya Upadhya
  • 2,239
  • 20
  • 28
4
votes
1 answer

Change composite primary key column order, avoid exposing table without primary key

Short of dropping the primary key index and re-creating it, how can I alter a composite primary key on a table? I would love to be able to change the primary key column order and have it re-index and apply immediately in a single statement (so that…
ADTC
  • 8,999
  • 5
  • 68
  • 93
4
votes
1 answer

Composite primary key vs single primary key and unique index

I'm modeling a voting system which has the following entities: category nominee phase As the name suggest, I'll be storing categories and nominees in the respective tables. The voting will have two phases. In the first phase there'll be 8 nominees…
4
votes
2 answers

Symfony2 Doctrine2 ManyToMany Composite key Column name referenced does not exist

I have a ManyToMany relation with a composite key on the reverse side. When I use the console command doctrine:schema:update I have the following error: [Doctrine\ORM\ORMException] Column name `keyword` referenced for relation from…
4
votes
1 answer

JPA @EmbeddedId: How to update part of a composite primary key?

I have a many-to-many relationship where the link table has an additional property. Hence the link table is represented by an entity class too and called Composition. The primary key of Composition is an @Embeddable linking to the according…
beginner_
  • 7,230
  • 18
  • 70
  • 127
4
votes
3 answers

MYSQL- Best design to store multiple emails/addresses for one user

I checked this question here but unfortunately the link to the diagram in not working so I'm stuck. I am trying to have multiple emails for one user (work, business, personal, etc) and I'm not sure how to best approach this situation. I am thinking…
Cristian
  • 2,390
  • 6
  • 27
  • 40
4
votes
2 answers

MySQL index not being used as expected

What can I do to make mysql use the expected indices? I've got 4 tables, two containing resources, and the others containing historical changes. One pair uses indexes correctly, the other doesn't, but both are structured almost identically. I've…
4
votes
1 answer

JPA Repository / Service design with composite primary keys

I designed the following database tables: "article" with "materialID" as primary key. "supplier" with "supplierID" as primary key. "procurement" with "materialID" and "supplierID" as composite primary key (including foreign key relationships to…
PWillms
  • 211
  • 1
  • 3
  • 10
4
votes
1 answer

Cassandra Hector Client: Is a RangeSlicesQuery on Composite Row Keys possible when using Random Partitioning?

Is there any way to range query rows with a composite row key when using random partitioning? Im workling with column families created via CQL v3 like this: CREATE TABLE products ( rowkey CompositeType(UTF8Type,UTF8Type,UTF8Type,UTF8Type) PRIMARY…
4
votes
3 answers

SQL Server four column composite key of various data types

I have just been reviewing a vendors database schema when I can upon a table that has a composite primary key on four columns, three of which are floating point data types. I am not sure why but this really shocked me. What are the implications /…
Phil Murray
  • 6,396
  • 9
  • 45
  • 95
4
votes
1 answer

JPA/Hibernate and composite keys

I have come across some SO discussions and others posts (e.g. here, here and here) where using composite primary keys with JPA is described either as something to be avoided if possible, or as a necessity due to legacy databases or as having "hairy"…
Marcus Junius Brutus
  • 26,087
  • 41
  • 189
  • 331
4
votes
2 answers

Reference to composite primary key in Access 2007

I have looked around and found some questions similar but they were for SQL Server instead. Here is a small database structured I have create just to show you the relationships I want to model. Basically it's quite simple, each year has 12 periods…