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

How can a table violate it's own primary key index?

I have a PostgreSQL database which has a table with the primary key applied to three columns. According to the database, there is an index on the key: Indexes: "full_log_pkey" PRIMARY KEY, btree (server_name, line_number, log_generation) Yet…
astine
  • 276
  • 2
  • 9
6
votes
1 answer

PostgreSQL: table referencing only part of a composite primary key

I am Creating a movie and tv show streaming service database(for school project) using Postgres 9.6.2. I am running into the following error: there is no unique constraint matching given keys for referenced table "watchedepisodes" The TVratings…
6
votes
3 answers

Composite Key in JPA / Hibernate with inherited class

i have a composite id defined on my class structure as below. Unfortunatly i always get a hibernate error that complains on the not found "part2": "Property of @IdClass not found in entity MoreClass : part2" Can anybody help me on fixing the…
6
votes
2 answers

Working with composite primary key in django project with legacy database

I have a legacy database, where some table contains composite primary key. The model I get by running manage.py inspectdb command looks like this. class MyTable(models.Model): field1_id = models.IntegerField(db_column='field1id',…
AmirM
  • 1,089
  • 1
  • 12
  • 26
6
votes
2 answers

Why is it necessary to indicate identifying or non-identifying relationships in an ERD?

In an ERD, a weak/non-identifying relationship is one that connects two strong entities, and is indicated with a dashed line. A strong/identifying relationship is one that connects a strong entity to a weak entity (a weak entity is one that contains…
Tripartio
  • 1,955
  • 1
  • 24
  • 29
6
votes
1 answer

Include foreign key in composite primary key in Code-First Entity Framework

I have an Entity named Member, for which I would like to set a primary key of MemberId and GroupId. In this case, GroupId is the primary key of the entity Group. With the code below, the foreign key is set correctly, but it is not included as part…
6
votes
2 answers

Using Hibernate Get with Multi-Column Primary Key

Say I have a class that looks like this: public class MyClass { @Id @Column(name = "ID") private long Id; } I can use a hibernate session to do a get or load on the class like this: MyClass a = (MyClass)session.get(MyClass.class, new…
Pete B.
  • 3,188
  • 6
  • 25
  • 38
6
votes
3 answers

Composite Primary key in JPA

The EmbeddedId or IdClass annotation is used to denote a composite primary key. How can i use composite primary key without ( EmbeddedId or IdClass ) ? If it is possible to use composite primary key without ( EmbeddedId or IdClass ) then how can i…
Gaurav Kumar
  • 323
  • 2
  • 4
  • 10
6
votes
2 answers

how to create a composite key in MySQL database

i am working on mysql server.where i have created a table, named question . column/attributes of this table are (course,subject,year,question) i want to create a primary key(or composite key) consists of (course+subject+year). i.e. for a particular…
RbG
  • 3,181
  • 3
  • 32
  • 43
6
votes
2 answers

EF 4.3 Code First: Table per Type (TPT) with Composite Primary Key and Foreign Key

So I'm trying to use Code First with Fluent to map a base class with one derived type where the tables schema is a Table-per-Type arrangement. Also, the derived type has a many-to-one relationship with another type that also has a composite foreign…
6
votes
2 answers

sql - check for uniqueness of COMPOSITE key

Can somebody please help me with this difficulty I am having? I would like to check some data whether it is valid, so a small part of the validation consists of entity integrity where I check that my primary key is unique SELECT order_id,…
test
  • 2,538
  • 4
  • 35
  • 52
5
votes
1 answer

How should I override equals/hashCode in entities with composite primary keys?

I have a table with a composite primary keys including it's own and a FK from other table. I decided not to use an @IdClass nor @EmbeddedId. class SomeEntity { @Id private String someId; @Id @ManyToOne(optional = false) …
Jin Kwon
  • 20,295
  • 14
  • 115
  • 184
5
votes
3 answers

How do I create a composite primary key using GORM?

I have three domain classes: Beer, Review, and Reviewer. I want the Review table to create a many to many relationship between Beer and Reviewer, so I want the primary key of Review to be a composite of the id fields from Beer and Reviewer. I'm…
haydenmuhl
  • 5,998
  • 7
  • 27
  • 32
5
votes
4 answers

Pros & Cons of Date Column as Part of Primary Key

I am currently working on a database, where a log is required to track a bunch of different changes of data. Stuff like price changes, project status changes, etc. To accomplish this I've made different 'log' tables that will be storing the data…
Skitzafreak
  • 1,797
  • 7
  • 32
  • 51
5
votes
3 answers

cassandra: delete all records that match one entry of composite primary key

I have a cassandra table who has a composite primary key: (school_id, student_id). Let's say that I want to delete all the records in this table that belong to one school. Using cassandra driver, I tried to bind only the school_id like: val query =…
breezymri
  • 3,975
  • 8
  • 31
  • 65