Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
22 views3 pages

Attributes

In MySQL, attributes are columns in a table characterized by types such as simple, composite, single-valued, multi-valued, derived, key, and stored attributes. Each type has specific roles and constraints, influencing how data is organized and accessed in database design. The document provides SQL examples illustrating the implementation of these attribute types in table creation and management.

Uploaded by

sathiya
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
22 views3 pages

Attributes

In MySQL, attributes are columns in a table characterized by types such as simple, composite, single-valued, multi-valued, derived, key, and stored attributes. Each type has specific roles and constraints, influencing how data is organized and accessed in database design. The document provides SQL examples illustrating the implementation of these attribute types in table creation and management.

Uploaded by

sathiya
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

In MySQL, an attribute refers to a column in a table.

Attributes are characterised by


different types, roles, and constraints in database design.

🔷 Types of Attributes with Examples

Attribute Type Explanation Example Scenario


Simple Attribute Cannot be divided further age INT
Composite address → street, city,
Can be divided into sub-parts
Attribute pin
Single-Valued
Holds only one value per entity email VARCHAR(50)
Attribute
Multi-Valued Can have multiple values per entity (not directly
Multiple phone numbers
Attribute supported; requires separate table)
Derived
Calculated from other attributes age derived from DOB
Attribute
Primary key or part of key identifying records student_id INT
Key Attribute PRIMARY KEY
uniquely
salary
Stored Attribute Value physically stored in database DECIMAL(10,2)

🔷 SQL Examples

1. Simple Attribute

CREATE TABLE Student (


student_id INT PRIMARY KEY,
name VARCHAR(50),
age INT
);

✔️Here, age is a simple attribute.

2. Composite Attribute

MySQL does not support composite attributes directly, but implemented as multiple
columns.

CREATE TABLE Address (


address_id INT PRIMARY KEY,
street VARCHAR(50),
city VARCHAR(50),
pin_code INT
);

✔️Address entity is represented using multiple simple attributes.


3. Single-Valued Attribute

Every normal attribute in MySQL is single-valued per record.

CREATE TABLE Employee (


emp_id INT PRIMARY KEY,
email VARCHAR(100)
);

✔️Each employee has only one email stored here.

4. Multi-Valued Attribute

Not directly allowed. Requires a separate table for normalization.

CREATE TABLE EmployeePhone (


emp_id INT,
phone_number VARCHAR(15),
PRIMARY KEY (emp_id, phone_number),
FOREIGN KEY (emp_id) REFERENCES Employee(emp_id)
);

✔️An employee can have multiple phone numbers.

5. Derived Attribute

Stored as a computed column or calculated during query.

SELECT name, YEAR(CURDATE()) - YEAR(dob) AS age FROM Student;

✔️age is derived from dob.

6. Key Attribute

Used to uniquely identify records.

CREATE TABLE Course (


course_id VARCHAR(10) PRIMARY KEY,
course_name VARCHAR(50)
);

✔️course_id is a key attribute.


7. Stored Attribute

Directly saved value in database.

CREATE TABLE Orders (


order_id INT PRIMARY KEY,
order_amount DECIMAL(10,2)
);

✔️order_amount is stored, not derived.

In ER modeling, attributes are classified to design optimal tables before normalization:

MySQL Implementation ER Model Attribute Type


Column with data type Simple / single-valued
Multiple columns for one logical attribute Composite
Foreign key tables Multi-valued
Computed columns or query-based Derived
PRIMARY KEY / UNIQUE Key attribute

You might also like