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
1 answer

Composite primary key, Google app engine (django)

I use django nonrel/djangoappengine on google app engine. It is not possible to specify composite primary keys directly. However it should be possible to emulate this behaviour. I am wondering about what is the best approach. Problem Conside the…
4
votes
1 answer

Hibernate declare composite primary key in JoinTable (List<>)

Hibernate declare composite primary key in JoinTable (List<>) How do I declare the composite primary key in a side table using HQL (Hibernate query language)? Previously I got one jointable declared in my class and everything worked fine, it…
Ben
  • 6,107
  • 6
  • 29
  • 40
4
votes
1 answer

Hibernate and Composite Keys

I am lost on how to use composite keys with annotations and hibernate... So for instance I have this table that has: TABLE_A INIT, NUM, CNT, TYP TABLE_B INIT, NUM, V_CNT TABLE A and B primary keys are composite keys consisting of INIT and NUM I want…
JonH
  • 501
  • 7
  • 13
  • 25
3
votes
2 answers

Backbone.js with compound keys

Is it possible to make Backbone.js work with compound keys? Id est, instead of setting id or idAttributemodel to a specific value, I want to know Backbone.js that I will be using more than one property. In such a way, every RESTful call would be…
Alpha
  • 7,586
  • 8
  • 59
  • 92
3
votes
3 answers

Logically determine a composite key in SQL

I'm working with an MSSQL table that does not have a primary or unique key contstraint defined. There are two fields, lets call them xId and yId, that I believe together would be a composite key, but I want to confirm this by examining the…
Paul
  • 3,725
  • 12
  • 50
  • 86
3
votes
1 answer

Knex multiple primary key in a identify relationship where id is an auto increment column

I tried to use every single logic in my mind to resolve this problem, but this is the only solution that it worked. knex.schema.createTable('documents', (table) => { table.integer('id').unsigned().notNullable().unique() …
3
votes
1 answer

Elixir -- Ecto -- Composite Primary Keys and Relationships

Has anyone successfully created relationships to/from tables with composite primary keys? I'm trying to achieve the following: create table(:resources, primary_key: false) do add :id, :uuid, primary_key: true add :version, :id, primary_key: true…
Kyle V
  • 47
  • 3
3
votes
1 answer

Composite Primary Key/Foreign Key Headaches

I am working with SQL Server 2008 R2, C# and ASP.Net. I have a table that has a composite Primary key consisting of a ticket number, and the number of times that ticket appears in the table. The ticket frequency is calculated by the C#…
Will
  • 281
  • 1
  • 6
  • 18
3
votes
2 answers

Does a composite primary key also create an index for each column separately?

In Teradata, I create table with unique primary key out of two varchar columns A and B. I will write queries that need to filter on one or both of these columns. For best performance, should I submit a create index statement for each of the two…
Insu Q
  • 403
  • 6
  • 13
3
votes
2 answers

Flask-Sqlalchemy: Table with 3 primary keys that are also foreign keys

I am trying to translate a table from pure SQL to Flask-Sqlalchemy, but the documentation available is not clear about how to do this specific scenario - Primary keys that are also foreign keys. The SQL to build the table is the following and it…
3
votes
1 answer

How to ALTER TABLE in Amazon Redshift to set two columns as Primary Key?

I would like to alter table in Amazon Redshift, and put two columns as a composite Primary key? I tried this code snippet: ALTER TABLE tableNameHere ADD CONSTRAINT PK_1 PRIMARY KEY (col1); But it worked just to set just one single primary key.…
ZelelB
  • 1,836
  • 7
  • 45
  • 71
3
votes
1 answer

Is composite-primary key the best solution - Hibernate Spring

I am building a chat application with Spring, Hibernate and JPA and I want two tables - chats and messages. Chat will have many messages, also id and user_first and user_second. Right now I am doing it with a composite primary key where the…
user6534435
3
votes
3 answers

How to filter by one column when that column belongs to a composite primary key in Spring

Having a DAO like this: @Entity @Table(name="booking") public class BookingObject implements Serializable{ private static final long serialVersionUID = 1L; @EmbeddedId private CompositeId compositePK; private LocalDate init_date; private…
3
votes
2 answers

How to create a foreign key referencing one column in a composite primary key

I have two tables Catalog and CatalogIndex catalog has the following columns DN PID PURL Desc where the two columns DN, PID are part of the composite primary key for this table. CatalogIndex has the following columns PID PItem PVal PID and PItem…
Vamsi
  • 4,237
  • 7
  • 49
  • 74
3
votes
1 answer

Unable to fetch list using criteria

public static List getList(int userId) { Session session = HibernateUtil.openSession(); Transaction tx = null; List results = null; try { tx = session.beginTransaction(); Criteria crit =…
HMT
  • 2,093
  • 1
  • 19
  • 51