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', '[email protected], 123-456-7890'),
(2, 'Jane Smith', '[email protected], 456-789-0123'),
(3, 'Alice Johnson', '[email protected], 789-012-3456');
Employee Table
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
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
Multivalued Attributes in DBMS Attributes are significant in DBMS as it deals with the organization and formatting of data. Of all the attributes, multivalued attributes are somewhat different and they have to be understood properly. To help us understand the above idea in the subsequent sections of this article, we will also exp
6 min read
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
Cardinality in DBMS In database management, cardinality represents the number of times an entity of an entity set participates in a relationship set. Or we can say that the cardinality of a relationship is the number of tuples (rows) in a relationship. It is a fundamental concept that helps define how data in different
4 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