Composite Attribute in DBMS
Last Updated :
11 Jun, 2024
In DBMS (Database Management System), keys are fundamental to maintaining the integrity and efficiency of the data. Among various types of keys, composite keys play an important role mainly when a single attribute is not sufficient to answer or identify a record. In this article, we will discuss in detail about Composite key attributes in DBMS.
What are composite Key attributes?
Composite key attributes are combinations of two or more attributes that uniquely identify a record in a table together. Unlike simple key attributes which use a single key to identify a record. a composite key uses multiple attributes. These are useful in cases where no single attribute can uniquely identify a record.
Example: The different examples of composite key attributes are
- Student address will contain house number, street name, and pin code in it.
- Student name will contain first_name, middle_name, and last_name in it.
- Employee contact information can contain his email id, mobile number and other contact information it.

In this figure Composite attribute is address and name and its component attributes are state, street, zip and first name, middle name, last name respectively.
SQL Code Example
Example 1: Creating Employee table with Composite ContactInfo Attribute
Here we will create a employee table in which out contact info is the composite key which contains email id and contact number in it.
CREATE TABLE Employee (
EmployeeID INT PRIMARY KEY,
Name VARCHAR(50),
-- Composite Attribute Contactnfo
ContactInfo VARCHAR(100)
);
INSERT INTO Employee (EmployeeID, Name, ContactInfo)
VALUES
(1, 'John Doe', 'john@example.com, 123-456-7890'),
(2, 'Jane Smith', 'jane@example.com, 456-789-0123'),
(3, 'Alice Johnson', 'alice@example.com, 789-012-3456');
Employee Table
EMPLOYEEID
| NAME
| CONTACTINFO
|
---|
1
| John Doe
| john@example.com, 123-456-7890
|
---|
2
| Jane Smith
| jane@example.com, 456-789-0123
|
---|
3
| Alice Johnson
| alice@example.com, 789-012-3456
|
---|
Query to select Email and Phone number of employee separately
SELECT
SUBSTR(ContactInfo, 1, INSTR(ContactInfo, ',') - 1) AS Email,
TRIM(SUBSTR(ContactInfo, INSTR(ContactInfo, ',') + 1)) AS PhoneNumber
FROM
Employee;
Output
EMAIL
| PHONENUMBER
|
---|
john@example.com
|
123-456-7890
|
jane@example.com
|
456-789-0123
|
alice@example.com
|
789-012-3456
|
Example 2: Creating Student Table where Address is composite attribute
Here we will create a Student table where student address is the composite key and it contains Street, City and Pin number in it.
CREATE TABLE Student (
StudentID INT PRIMARY KEY,
Name VARCHAR(50),
Address VARCHAR(100) -- Composite Attribute
);
INSERT INTO Student (StudentID, Name, Address)
VALUES
(1, 'John Doe', '123 Main Street, Apt 2, 10001'),
(2, 'Jane Smith', '456 Elm Street, Suite 3B, 20002'),
(3, 'Alice Johnson', '789 Oak Avenue, 30003');
Student Table
STUDENTID
| NAME
| ADDRESS
|
---|
1
| John Doe
| 123 Main Street, Apt 2, 10001
|
2
| Jane Smith
| 456 Elm Street, Suite 3B, 20002
|
3
| Alice Johnson
| 789 Oak Avenue, 30003
|
Query to select Street City and Pin from Student's address Separately
SELECT
Name,
substr(Address, 1, instr(Address, ',') - 1) AS Street,
substr(Address, instr(Address, ',') + 2, instr(substr(Address, instr(Address, ',') + 2), ',') - 1) AS City,
TRIM(substr(Address, LENGTH(Address) - instr(REVERSE(Address), ',') + 2)) AS PIN
FROM
Student;
Output
NAME
| STREET
| CITY
| PIN
|
---|
John Doe
| 123 Main Street
| Apt 2
|
10001
|
Jane Smith
| 456 Elm Street
| Suite 3B
|
20002
|
Alice Johnson
| 789 Oak Avenue
|
-
|
30003
|
Conclusion
Composite attributes allows us to store and manage complex data in efficient manner. These are essential in cases where single attribute is not sufficient to uniquely identify the records. By combining various attributes, composite key attribute ensures the uniqueness and integrity of data in a table. Understanding and implementing composite key can enhance the efficiency and reliability of database systems.
Similar Reads
Composite Key in Database
A database is a structured collection of data organized and stored electronically in a computer system. It is designed to efficiently manage, retrieve, and manipulate large volumes of data according to specific requirements and criteria. In a relational database, the key plays an important role. The
6 min read
RDBMS Architecture
RDBMS stands for Relational Database Management System and it implements SQL. In the real-world scenario, people use the Relational Database Management System to collect information and process it, to provide service. E.g. In a ticket processing system, details about us (e.g. age, gender) and our jo
3 min read
Decomposition In DBMS
Decomposition refers to the division of tables into multiple tables to produce consistency in the data. In this article, we will learn about the Database concept. This article is related to the concept of Decomposition in DBMS. It explains the definition of Decomposition, types of Decomposition in D
4 min read
Aggregation in DBMS
In Database Management Systems (DBMS), aggregation is like mathematically setting collectively a jigsaw puzzle of health. Itâs about placing all of the pieces together to create an entire photograph. In this article, we are going to discuss What is aggregation in a Database, its applications, etc. W
4 min read
Concurrency Control in DBMS
In a database management system (DBMS), allowing transactions to run concurrently has significant advantages, such as better system resource utilization and higher throughput. However, it is crucial that these transactions do not conflict with each other. The ultimate goal is to ensure that the data
7 min read
MySQL COMPOSITE KEY
In MySQL, a composite key is a combination of two or more columns in a table that uniquely identifies each entry. It is a candidate key made up of many columns. MySQL guarantees column uniqueness only when they are concatenated. If they are extracted separately, the uniqueness cannot be maintained.
4 min read
Composite Key in SQL
A composite key is a primary key that is made up of more than one column to uniquely identify records in a table. Unlike a single-column primary key, a composite key combines two or more columns to ensure uniqueness. While any of the individual columns in a composite key might not be unique on their
2 min read
Data Objects, Attributes and Relationships in DBMS
Data Model is an abstract model that represents the data objects, data flow between these data objects, and the interrelationship between these data objects. It is a way of storing data on a computer so that it can be used in a more efficient manner for further purposes. Data model or data structure
3 min read
Database Languages in DBMS
Databases are essential for efficiently storing, managing, and retrieving large volumes of data. They utilize both software and hardware components. The software provides an interface that enables users or applications to interact with the database, while the hardware consists of servers and storage
10 min read
Cascadeless in DBMS
In a Database Management System (DBMS), maintaining data consistency and avoiding unnecessary complications during transaction execution are critical. A cascadeless schedule is a type of transaction schedule that ensures reliability by preventing cascading rollbacks. Cascading rollbacks occur when t
5 min read