BeginnersBook

  • Home
  • Java
    • Java OOPs
    • Java Collections
    • Java Examples
  • C
    • C Examples
  • C++
    • C++ Examples
  • DBMS
  • Computer Network
  • Python
    • Python Examples
  • More…
    • jQuery
    • Kotlin
    • WordPress
    • SEO
    • JSON
    • JSP
    • JSTL
    • Servlet
    • MongoDB
    • XML
    • Perl

Composite key in DBMS

By Chaitanya Singh | Filed Under: DBMS

Definition of Composite key: A key that has more than one attributes is known as composite key. It is also known as compound key.

Note: Any key such as super key, primary key, candidate key etc. can be called composite key if it has more than one attributes.

Composite key Example

Lets consider a table Sales. This table has four columns (attributes) – cust_Id, order_Id, product_code & product_count.

Table – Sales

cust_Id    order_Id    product_code    product_count
--------   --------    ------------    -------------
C01	   O001         P007           23
C02	   O123	        P007           19
C02	   O123	        P230           82
C01	   O001	        P890           42

None of these columns alone can play a role of key in this table.

Column cust_Id alone cannot become a key as a same customer can place multiple orders, thus the same customer can have multiple entires.

Column order_Id alone cannot be a primary key as a same order can contain the order of multiple products, thus same order_Id can be present multiple times.

Column product_code cannot be a primary key as more than one customers can place order for the same product.

Column product_count alone cannot be a primary key because two orders can be placed for the same product count.

Based on this, it is safe to assume that the key should be having more than one attributes:
Key in above table: {cust_id, product_code}

This is a composite key as it is made up of more than one attributes.

❮ PreviousNext ❯

Comments

  1. Anonymous says

    April 6, 2016 at 8:56 PM

    “Key in above table: {cust_id, order_id}”. But this cannot be because 1st and 4th rows have the same key then and so does not uniquely identify the rows.. right?

    Reply
    • Himanshu says

      June 4, 2016 at 12:06 PM

      Agreed..
      Any one of the both. cust_id or order_id should be different here i think, to make {cust_id, order_id} key.

      Reply
  2. pooja says

    September 1, 2016 at 4:57 PM

    i think it should be {cust_id, product_code}

    Reply
  3. haritha says

    October 17, 2016 at 11:13 AM

    what is the difference between composite key and candidate key?

    Reply
    • Lee says

      May 14, 2017 at 8:22 PM

      The difference is that candidate key does not allow redundant attributes only unique attributes like ID and Item Code etc.

      Reply
    • Chaitanya Singh says

      December 11, 2018 at 12:36 PM

      A composite key must have more than one attributes while a candidate key can contain a single attribute.

      Reply

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

DBMS Tutorial

Basics

  • DBMS Tutorial
  • DBMS Introduction
  • Database Applications
  • DBMS vs File System
  • DBMS vs RDBMS
  • DBMS Architecture
  • Three-level DBMS architecture
  • View in DBMS
  • Abstraction
  • Instance & Schema
  • DBMS languages

Data Models

  • Data Models
  • ER Diagram
  • ER Design issues
  • Convert ER to table
  • DBMS Generalization
  • DBMS Specialization
  • DBMS Aggregration
  • Relational Model
  • Hierarchical Model
  • Constraints
  • Cardinality

Relational Database

  • RDBMS concepts
  • Relational Algebra
  • Relational Calculus
  • Keys Index
  • Primary Key
  • Super Key
  • Candidate Key
  • Foreign Key
  • Composite Key
  • Alternate Key

Normalization

  • Normalization
  • Functional dependency

Transaction Management

  • Transaction Management
  • ACID properties
  • Transaction States
  • DBMS Schedules
  • Serializability
  • Conflict Serializability
  • View Serializability
  • Recoverability Of Schedule
  • Failure Classification
  • Log based Recovery
  • DBMS Checkpoint
  • Deadlock

Concurrency Control

  • Concurrency Control
  • Lock based protocol
  • Timestamp based protocol
  • Validation based protocol

File Organization

  • File Organization
  • Sequential File Organization
  • Heap File Organization
  • Hash File Organization
  • DBMS ISAM
  • B+ File Organization
  • Cluster File Organization

SQL Introduction

  • SQL Introduction
  • SQL Characteristics
  • Advantages of SQL
  • SQL Commands
  • SQL Operators
  • SQL CREATE
  • SQL DROP
  • SQL SELECT
  • SQL INSERT

Copyright © 2012 – 2022 BeginnersBook . Privacy Policy . Sitemap