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

hibernate query with composite key,count and netbeans

I have DLawUserMaster table which has UserID, LoginId and password field. Among them UserId and LoginId are composite key. When user try to login using userID and password, I want to validate user and get userID to store it in session for further…
mrugeshthaker
  • 657
  • 2
  • 8
  • 25
0
votes
1 answer

fluent nhibernate: compositeid() of same types, getting message no id mapped

I've scoured Google and SO but haven't come across anyone having the same problem. Here is my model: public class Hierarchy { public virtual Event Prerequisite { get; set; } public virtual Event Dependent { get; set; } public override…
0
votes
1 answer

Creating fields on the fly in django

I have two tables (say Parent and Child). I want parent and Child to link to each other using a foreign key. The child table has two fields, one among them being 'country_sig'. This country_sig is actually made from joining two fields in parent…
pranavk
  • 1,774
  • 3
  • 17
  • 25
0
votes
1 answer

Composite foreign key and DDL generation in JPA 2

I'm trying to create a class with a foreign composite key and everything works fine, except that the DDL generation doesn't create indeces as expected. I will explain better with some code; the part of the code I'm trying to implement is the ribbon…
satoshi
  • 3,963
  • 6
  • 46
  • 57
0
votes
3 answers

If I have two types of row in an SQL table, and I want to prefer one but accept the other

I have a directory table in a MySQL database that contains user ID's, user types, and assorted other directory information. There are two types of users: employee and student. The primary key is (userID, userType), so any given user can have an…
LeafStorm
  • 3,057
  • 4
  • 24
  • 28
0
votes
1 answer

Hibernate: optional attribute in composite natural primary key

I'm experiencing an issue with Hibernate. I have an Entity mapped to a table with a natural composite primary key. The primary key consists of a mandatory code and either an optional Date or Period ID, so date and period_id are mutual exclusive. I…
dr jerry
  • 9,768
  • 24
  • 79
  • 122
0
votes
3 answers

How can I show a 2 column mysql composite primary key value as a default value in a 3rd column?

I can not find this any where (I am probably not asking the right questions). Would someone please point me in the right direction. I am using a 2 column composite primary key in MySQL. I would like to display that value as a default value in a 3rd…
0
votes
1 answer

how to use two columns as primary key in hibernate

I have a table with five columns. The two columns, together, make up the primary key of my table. I'm trying to instantiate an Entity class that corresponds to that table using hibernate. The problem is how do I tell hiberante that the primary key…
Abraham Guchi
  • 181
  • 1
  • 2
  • 11
0
votes
1 answer

SQL Server - foreign key reference error

I have two tables, Table_1 with 4 columns (3 primary key) and Table_2 with 2 column. When I try to create a foreign key constraint in Table_2, I am getting this error: Here are the definitions of my tables: Table_1 CREATE TABLE [dbo].[Table_1] ( …
neztreh
  • 3,971
  • 3
  • 19
  • 17
-1
votes
0 answers

Composite Primary Key (Foreign Key Column and a Number Column starting always from 0 for new records)

So, I have three tables Company(id), Person(id) and Review(comp_id, person_id, id). A person can leave multiple reviews for a company, so there is a one-to-many relationship. The Review table has comp_id and person_id columns, which are foreign keys…
-1
votes
2 answers

Composite keys and unique constrains performances and alternatives

I'm creating a database using MySQL for a music streaming application for my school project. It has a table "song_discoveries" which has these columns: user_id, song_id and discovery_date. It has no primary key. The "user_id" and "song_id" are…
-1
votes
1 answer

Creating a foreign key against a composite key in MS SQL Server

I'm trying to create a foreign key between two tables. Problem is one of those tables has a composite primary key.. My tables are products (one row per product) and product_price_history (many rows per product). I have a composite key in…
Nick
  • 9
  • 3
-1
votes
1 answer

Auto incrementing composite key

I have a relatively simple need -- I have a table with a composite primary key that includes an integer index to be autoincremented. However, I cannot figure out how to do this. I have read the documentation which suggests the…
zagaroo
  • 31
  • 4
-1
votes
2 answers

Is there a way to generate composite key efficiently in a PostgreSQL database?

Suppose I have a student table with id as primary key, which holds information about all students. id | name ---+------ 1 | aaron 2 | bob In addition there is a table where id and tid form a composite key, which holds the scores for each test. id…
progquester
  • 1,228
  • 14
  • 23
-1
votes
1 answer

Postgres FK referencing composite PK INSERT VIOLATION

I am trying to insert into a table (mdata) which has a compost foreign key referencing to a primary keys in another table (measurement), unfortunately I have this error ERROR: insert or update on table "mdata" violates foreign key constraint…
Raziel
  • 444
  • 6
  • 22