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

Mysql Innodb: Combining 3 Tables Into Single Table for Quick Search... Conditional Joins

BACKGROUND: I am developing a search feature that enables users to search three entities at once: classes, student organizations, and events by name. MySQL 5.6 and Innodb will be utilized on a relatively small server. TABLES: Search entity_id …
ProfileTwist
  • 1,524
  • 1
  • 13
  • 18
0
votes
0 answers

Error when creating an MVC controller using composite key and EF 5

Using the Entity Framework tools I reverse engineered code first the POCO classes for a MySQL database into a class library. I created an MVC project that references this class library and I am trying to create a controller with read/write actions…
CTBrewski
  • 313
  • 4
  • 7
0
votes
1 answer

Why is MySQL not using composite key in range query?

I've checked numerous other SO posts and MySQL docs but can't seem to get an answer on why an index isn't being used, and how to force it to be used - I can see many others are having similar problems, but can't find a solution. The table looks like…
spooky
  • 421
  • 5
  • 20
0
votes
2 answers

Oracle: Trouble creating two composite keys

One of my tables has a composite key comprised of three foreign keys (order_no, product_code and product_size). In the table where Product_size is the primary key I want to have a composite key consisting of Product_size and product_code. If I do…
0
votes
1 answer

SQL query dynamic row generation with composite key

My question is made of 3 parts. First part: Is there a way to generate rows based on a value? E.g: I want to give each family a number of vouchers based on their family_members_count. Each voucher should have a unique id: Base table: id name…
Ali
  • 448
  • 6
  • 25
0
votes
1 answer

composite foreign key referencing one or more columns

I have a table (tableA) that joins 3 other tables with primary keys 'vehicle','engine','transmission' I would like to be able to assign parts to one or more of these eg 'only this vehicle' or 'only this vehicle with this engine' or 'any vehicle with…
Kelly Larsen
  • 963
  • 1
  • 14
  • 30
0
votes
1 answer

Composite Key Not Loading All Related Entities

I've been trying various solutions to this for a couple of hours now and I just cannot figure it out. I'm using a custom membership provider in a system so have a roles table defined using code first like this: public class UsersInRole { [Key] …
Jammer
  • 9,969
  • 11
  • 68
  • 115
0
votes
1 answer

LightSwitch 2012 - Working with Composite Keys

The project I am working on currently is connecting to and OData service to retrieve data from an Oracle database. Using LINQPad I can execute the query, and return the data that I'm expecting. The problem I am running into with LightSwitch is…
Jason
  • 333
  • 1
  • 6
  • 17
0
votes
1 answer

Yii composite key in relatins with custom params

I want to use composite key in ActiveRecord. I got two tables. Quotes and Comments. Quotes contains pk - id; Comments pk is composite - module, section, cid module - module name, where comments come from. section - section of this module cid -…
Ken Shiro
  • 712
  • 10
  • 18
0
votes
2 answers

Create a table with student ID starting with a letter - mysql

I need to create a table for students with ID's starting either M or I and then followed by 7 digits. I thought about creating a table one field being choosing the letter M or I and the second field be the 7 digits. Then I would use those to create…
Student J
  • 203
  • 1
  • 5
  • 13
0
votes
1 answer

Composite Foreign Key

I'm trying to create a table with a composite foreign key. I don't know what's the problem with this creation: CREATE TABLE Album( Name VARCHAR(30), Bandname VARCHAR(30), PRIMARY KEY(Name, Bandname), Erscheinungsjahr…
10ff
  • 813
  • 4
  • 16
  • 31
0
votes
1 answer

Ruby Nested Hash with Composite Unique Keys

Given a comma separated CSV file in the following format: Day,User,Requests,Page Views,Browse Time,Total Bytes,Bytes Received,Bytes Sent "Jul 25, 2012","abc123",3,0,0,13855,3287,10568 "Jul 25, 2012","abc230",1,0,0,1192,331,861 "Jul 25,…
Neobane
  • 3
  • 1
  • 6
0
votes
1 answer

JPA Composite Key with Extra Columns Mapping

I have been trying for a few days now to get the composite key to work looking at the many example on the web, but still am missing something since it isn't working. With the code posted below I am currently experiencing the follow error: Could…
MikeR
  • 633
  • 8
  • 21
0
votes
4 answers

AUTO_INCREMENT in composite key

I have table as below personalInfo CREATE TABLE personalInfo(userid BIGINT AUTO_INCREMENT PRIMARY KEY) patentInfo CREATE TABLE patentInfo ( userid BIGINT, patentId BIGINT AUTO_INCREMENT, FOREIGN KEY (userid) REFERENCES personalInfo(userid), …
Fahim Parkar
  • 30,974
  • 45
  • 160
  • 276
0
votes
1 answer

Entity Framework 4.3 Modify T4 Template for generating classes

I have a database-first model generated with full primary keys. Database first model works fine. However now I have upgraded my Entity Framework 4.3. I have modified the standard T4 template that comes with EF. Now when I use Add-Migration initial…
Sanj
  • 3,770
  • 6
  • 26
  • 31