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

JPA entity with composite primary that is also foreign key to same table

I have two tables A and B. There are two columns in table A, col1 and col2(both the columns are primary key, i.e. composite with col1 and col2). There is one column in table B, to which both the columns from table A are pointing to, i.e. col1 and…
-1
votes
1 answer

How to map @EmbeddedId in Ebean with Scala

In Custom bridge table in playframework ebean there is an example how to map model using @EmbeddedId with Ebean in Java. But there is no such example for Scala language. Lets assume we have a following 3-class model in Scala: Student class: class…
rtruszk
  • 3,902
  • 13
  • 36
  • 53
-1
votes
1 answer

Delete Composite unique key [ applied on 3 fields combinely ]

In MySQL, I've create a unique composite key, based on 3 columns. How can I delete this unique key constraint without deleting the entire table?
-1
votes
3 answers

Arrays as parameter in enum constructor in java

I have 5 data sets of predefined values in double[]: A = {1.5, 1.8, 1.9, 2.3, 2.7, 3.0} B = {1.2, 1.8, 1.9, 2.4, 2.9, 3.1} . . E = {1.4, 1.7, 1.8, 1.9, 2.3, 2.9} how can I represent it in enum? I am trying to coded it like: private enum…
Eng. Samer T
  • 6,465
  • 6
  • 36
  • 43
-1
votes
1 answer

SQL Composite Primary Keys

I am using Sql Server for Visual Studio. I Have two columns, 1 is auto-incremented and the other is not but I want make the both primary keys and the unincremented key can be used as a foreign key in another table. thanks
Chris
  • 243
  • 3
  • 10
-1
votes
1 answer

Adding Composite Foreign Key

I am having a problem adding a foreign key constraint to SQL 2008 that is based on a composite primary key in another table. I have followed some directions based on a few posts on here, but haven't been able to get it to work. I have two tables:…
James Smith
  • 1,072
  • 1
  • 11
  • 14
-1
votes
1 answer

composite primary key of a foreign key

This is a sample of my code. I'm using sql server 2008 R2 create table Entidade( NIF numeric(9,0) primary key, nome varchar(250) not null, tipoEnt varchar(4) check (tipoEnt in ('CE','EC','CEEC',null)) ) create table Curso( cod int…
-1
votes
1 answer

Which .NET ORMs have good support for composite keys

We have a large existing database that uses composite primary and foreign keys almost exclusively. We are tasked with writing a large-ish C# application that talks to this database (on SQL Server 2012). We are considering using an ORM, but most ORMs…
Eyvind
  • 5,221
  • 5
  • 40
  • 59
-2
votes
2 answers

Using composite key of Latitude and longitude vs auto increment as Primary Key in case of area under city Relational DB

Suppose we need to save following data in database County latdecdeg londecdeg State --------------------------------------------------- Allegheny 40.5254 -80.07213889 PA Allegheny 40.5526 -80.1159 …
-2
votes
1 answer

MySql composite foreign key ON DELETE set null

Please refer to this SQLFiddle CREATE TABLE `parent` ( `id` varchar(64) NOT NULL, `master_id` varchar(64) NOT NULL, `c1_id` varchar(64) DEFAULT NULL, `c2_id` varchar(64) DEFAULT NULL, PRIMARY KEY (`master_id`, `id`) ) ENGINE=InnoDB…
Justinas
  • 41,402
  • 5
  • 66
  • 96
-3
votes
0 answers

Creating Composite key for real estate data: best practices

I want to create a new id column for a real estate dataset. The data is about land ownership titles in the UK. Each observations is a property "unit" that has its own postbox. I only collect units that are owned by companies. I want the new id…
-3
votes
1 answer

Code First Entity Model.. Joined Table without Primary Key

im using Code First Entity Model with Web API Asp.Net i need 3 tables in total The First table(Table1) contains some information with a unique Id lets say it is like string id string model The second Table (Table2)contains some information about…
Parv Sharma
  • 12,581
  • 4
  • 48
  • 80
1 2 3
49
50