Questions tagged [composite-key]

A composite key is a database key whose value is made up of multiple typed values

A Composite Key is a Key that is made up of multiple columns

Any column(s) that can guarantee uniqueness is called a candidate key; however a composite key is a special type of candidate key that is only formed by a combination of two or more columns. Sometimes the candidate key is just a single column, and sometimes it's formed by joining multiple columns.

A composite key can be defined as the primary key. This is done using SQL statements at the time of table creation. It means that data in the entire table is defined and indexed on the set of columns defined as the primary key.

Dr E F Codd's Relational Model demands that:

  1. Data is organised into table and columns

  2. Rows (as distinct from records) are unique

  3. A Key is made up from the data (ID, GUID, etc. columns are not data).

In any given table, this naturally leads to multiple columns being used to provide row uniqueness, and to identify each row. That is a composite Key.

Composite Keys are the hallmark of a Relational database (those that conform to Relational Model), without them the database does not comply, and is therefore non-relational.

SQL-compliant platforms provide complete support for composite Keys.

Non-compliant platforms have partial support for composite keys, and usually necessitate single column keys.

Further reading

747 questions
0
votes
1 answer

Composite key in table manupulation in Entity Framework

I use Entity Framework 5 Code First and have some problem with composite keys. I have those tables And this is how i map the entities public class Product : EntityBase { public Product() { this.ProductArticles =…
Nils Anders
  • 4,212
  • 5
  • 25
  • 38
0
votes
1 answer

NHibernate - Deleting objects with composite PK, when one of the PK columns is NULL

Hey, i'm trying to delete an entity of the following structure from an Oracle 10g tables: class Record { string id; string name; DateTime dateTime; } with the following mapping:
Harel Moshe
  • 444
  • 7
  • 21
0
votes
1 answer

i try to create composite primary key with @UniqueConstraint

i try to create composite primary key in table from 2 foreign key using hibernate.but i do not now the way how to set it. @UniqueConstraint can some body help me..
Niraj Thakar
  • 168
  • 1
  • 2
  • 13
0
votes
1 answer

Dual use of composite foreign keys

I'm modelling a hierarchy of three entities for a therapy planning software. A therapy is basically understood as a number of medications that are given to a patient on a number of days. I want to be able to cancel therapy on any given day, in a…
room2web
  • 1,179
  • 1
  • 8
  • 14
0
votes
2 answers

Batch Insert - Foreign Key Not Working

I'm trying to do a batch insert and it's not working. I thought I had this working but something seems to have broken and I'd appreciate it if someone could show me what. Edit - Here's the database schema: CREATE TABLE [dbo].[Categories]( [Id]…
nfplee
  • 7,643
  • 12
  • 63
  • 124
0
votes
1 answer

Trying to do a SQL Merge statement, but it errors

I've got a stored procedure that accepts batches of product info. For each product, either insert it into the DB or Update it, if it already exists. A product is defined by a composite key -> ProductCompanyId (where the product came from) and a…
Pure.Krome
  • 84,693
  • 113
  • 396
  • 647
0
votes
1 answer

Error when setting Composite Primary Key in SQLite3

Id like to set the Primary key of a tabe Im building as the composite key of 3 integers. Im doing this within a Ruby script like so: ...Ruby Script ............. ............. #Begin database operations begin db = SQLite3::Database.new…
banditKing
  • 9,405
  • 28
  • 100
  • 157
0
votes
1 answer

LINQ Composite Key GroupJoin with keys unknown at compile time

I'm trying to get a GroupJoin to work with multiple unknown keys using LINQ. I've seen solutions with anonymous types, but the keys were always pre-defined. In my case, they're user-defined, so I wouldn't know that information at compile time. I…
Gustavo Azevedo
  • 113
  • 1
  • 7
0
votes
2 answers

Entity Framework: Entity with composite key as PK/FK throws exception

On escalado, throws the exception. It throws with or wihtout Include. static void Main(string[] args) { try { using (var context = new CKContext()) { var servReprosWithIncludes…
0
votes
1 answer

Symfony2 ORM FK Composite

I'm new with Symfony2 and Doctrine 2 ORM, then i got a problem with composite FK association. While the association OneToMany-ManyToOne by a single auto-increment ID works good, i got many troubles with the same kind of association but through a…
0
votes
0 answers

Entity Framework Code First Composite Keys using Fluent API

I'm learning Entity Framework and decided to re-implement a knowledge base application which I had written using ADO.NET a few years back. I have three entities: Article, UserAccount and Rating. Article and UserAccount are pretty self-explanatory. …
0
votes
1 answer

Insert composite incremental key

I've searched and searched and can't find an answer on this. If I have a composite key in mssql and want it to look like such: k2 k3 1 1 1 9 2 1 2 9 2 3 3 1 3 8 Registries are inserted 1 or more at a time and for each round of inserts, the…
simple-thomas
  • 671
  • 7
  • 20
0
votes
1 answer

Query composite index with Hibernate for many entities

I am using Hibernate and want to query multiple entities using a composite index (a,b,c,d). The SQL statement could look like this: SELECT * FROM my_table WHERE a = 2 AND b = '2001' AND c = 'xx' AND d = 23 OR a = 2 AND b = '2002' AND c = 'xx' AND d…
Matthias
  • 7,432
  • 6
  • 55
  • 88
0
votes
1 answer

Entity framework 5 many to many when an entity is using composite key

im having some problems with EF 5 when i want to map many to many relationships using code first. This is my scenario: public class SegFunction { public virtual string Idaplication {get;set;} public virtual string Idfunction {get;set;} …
0
votes
1 answer

how to insert data into db table with 3 distinct values but insert additional columns that are not distinct

how to insert data into db table with 3 distinct values but also insert additional columns that are not distinct? So I have table data user __________________________________ user_id user_id train_code …
Angelina
  • 2,175
  • 10
  • 42
  • 82