unit-1 full
unit-1 full
SYLLABUS
UNIT I INTRODUCTION (9
Hrs)
Database System Application – Purpose of Database Systems – View of Data – Database Languages –
Relational Database – Database Design – System Structure – Database Architecture. Database Design and
E-R Model: Overview of the Design Process – The E-R Model – Constraints – E-R Diagrams – E-R
Design Issues –Extended E-R features – Reduction to Relational Schemas – Other aspects of Database
Design.
Text Books
1. Abraham Silberschatz, Henry F Korth, S Sudharshan, “Database System Concepts”, McGraw-Hill 7th
Edition, 2019.
2. RamezElmasri and ShamkantNavathe, Durvasula V L N Somayajulu, Shyam K Gupta, “Fundamentals of
Database Systems”, Pearson Education, United States of America, 2018.
3. AtulKahate, “Introduction to Database Management Systems”, Pearson Education, New Delhi, 2006.
Reference Books
Page 1
1. Date CJ, Kannan A, Swamynathan S, “An Introduction to Database System”, Pearson Education,
8th Edition, 2006.
2. Raghu Ramakrishna, Johannes Gehrke, “Database Management Systems”, McGraw Hill, 3rd
Edition, 2014.
3. G.K.Gupta, "Database Management Systems”, Tata McGraw Hill, 2011.
4. Jeffrey D. Ullman, “Principles of database systems”, Computer Science Press, 1982.
5. Paul Beynon-Davies, “Database Systems”, Palgrave Macmillan, 3rd Edition, 2003.
References:
1. Ramez Elmasri, Shamkant B. Navathe, “Fundamentals of Database
Systems”, FourthEdition , Pearson / Addision wesley, 2007.
2. Raghu Ramakrishnan, “Database Management Systems”, Third Edition,
McGraw Hill, 2003.
3. S.K.Singh, “Database Systems Concepts, Design and Applications”, First
Edition,
Web References
1. https://nptel.ac.in/courses/106/106/106106095/
2. https://docs.oracle.com/cd/E11882_01/server.112/e41084/toc.htm MySQL
Online Documentation
3. http://dev.mysql.com/doc/
4. http://www.rjspm.com/PDF/BCA-428%20Oracle.pdf
5. https://www.tutorialspoint.com/dbms/index.html
Pearson Education, 2006.
Page 2
UNIT I INTRODUCTION (9 Hrs)
Database System Application – Purpose of Database Systems – View of Data – Database Languages –
Relational Database – Database Design – System Structure – Database Architecture. Database Design
and E-R Model: Overview of the Design Process – The E-R Model – Constraints – E-R Diagrams –
E-R Design Issues –Extended E-R features – Reduction to Relational Schemas – Other aspects of
Database Design.
In the early days, database applications were built on top of file systems
Drawbacks of using file systems to store data:
Data redundancy and inconsistency
Multiple file formats, duplication of information in different files
Page 3
Atomicity of updates
Failures may leave database in an inconsistent state with partial updates carried out
E.g. transfer of funds from one account to another should either complete or not
happen at all
Concurrent access by multiple users
Concurrent accessed needed for performance
– E.g. two people reading a balance and updating it at the same time
Security problems
Database systems offer solutions to all the above problems
Page 4
Analogous to the value of a variable
Physical Data Independence – the ability to modify the physical schema without
Database languages are specialized languages used to interact with a database. They
allow users to perform different tasks such as defining, controlling,
and manipulating the data. There are several types of database languages in DBMS,
categorized into the following four main types:
1. DDL (Data Definition Language)
2. DCL (Data Control Language)
3. DML (Data Manipulation Language)
4. TCL (Transaction Control Language)
Each category serves a different purpose within the database management process. Let's
break down each one.
Page 5
TRUNCATE: Used to remove all rows from a table, without affecting the structure.
RENAME: Used to change the name of a database object.
Now we will explain each command with examples for better understanding of the concepts.
CREATE Command
The CREATE is a DDL command used to create databases, tables, triggers and other database
objects.
Syntax
CREATE TABLE Students (
column1 INT,
column2 VARCHAR(50),
column3 INT
);
Alter Command
ALTER is a DDL command which changes or modifies the existing structure of the database, and
it also changes the schema of database objects. We can also add and drop constraints of the table
using the ALTER command.
Syntax
ALTER TABLE Students ADD column_name;
Drop Command
DROP is a DDL command used to delete/remove the database objects from the SQL database. We
can easily remove the entire table, view, or index from the database using this DDL command.
Syntax
DROP Table Table_name;
Truncate Command
The TRUNCATE command is used to delete all the records from a table without removing the
structure. Unlike the DELETE command, which can remove specific rows and can be rolled
back, TRUNCATE is a more efficient way to delete all rows in a table without logging individual
row deletions.
Syntax
TRUNCATE TABLE table_name;
Rename Command
The RENAME command in a Database Management System (DBMS) is used to change the name of
a database object, such as a table, column, or index. This command is helpful when we want to give a
more meaningful or appropriate name to an object without needing to recreate it.
Syntax:
ALTER TABLE Old_Table_Name RENAME TO New_Table_Name;
Page 6
1.4.2 DCL (Data Control Language)
DCL stands for Data Control Language. It is used to control the access permissions of users to the
database. DCL commands help grant or revoke privileges to users, determining who can perform
actions like reading or modifying data. DCL commands are transactional, meaning they can be
rolled back if necessary.
The two main DCL commands are:
Grant: Gives user access to the database
Revoke: Removes access or permissions from the user
Now we will explain these commands with proper examples for better understanding
Grant Command
The GRANT command in a Database Management System (DBMS) is used to provide
specific permissions or privileges to users or roles. This command allows administrators to control
access to database objects, ensuring that only authorized users can perform certain actions, such as
selecting, inserting, updating, or deleting data.
Syntax
GRANT privileges
ON object
TO user_or_role [WITH GRANT OPTION];
Revoke Command
The REVOKE command in a Database Management System (DBMS) is used to remove previously
granted permissions or privileges from users or roles. This command is essential for managing
access control, ensuring that users do not have more privileges than necessary to perform their tasks.
Syntax
REVOKE privileges ON object FROM user_or_role;
Page 7
SELECT Command
The SELECT command in SQL (Structured Query Language) is used to retrieve data from one or
more tables in a database. It is the most commonly used commands in SQL, allowing users to specify
which columns and rows of data they want to retrieve and how they want that data organized.
The SELECT statement can be used in various ways, such as selecting all data from a table, filtering
records based on conditions, or sorting the results.
Syntax
SELECT * FROM Table_Name
Insert Command
The INSERT command in SQL (Structured Query Language) is used to add new records or rows to
a table in a database. It is a key operation in database management, essential for populating tables
with new data. This command can insert data into all columns or specific columns of a table.
Syntax
INSERT INTO Table_Name (Column 1, Column 2, Column 3, Column 4) VALUES (Value 1, Value
2,Value 3, Value 4);
Update Command
The UPDATE command in SQL (Structured Query Language) is used to modify existing records in
a table. This command enables users to change the values of one or more columns for specific rows
based on a condition (criteria). It is crucial for maintaining and adjusting data in a database when
necessary.
Syntax
UPDATE Table_Name SET Name = 'New_Value' WHERE Name = 'Ola_Value';
Delete Command
The DELETE command in SQL (Structured Query Language) is used to remove one or more
existing records from a table in a database. It is an essential operation for managing data, enabling
users to delete specific rows that meet certain conditions or criteria.
Syntax:
DELETE FROM Table_Name WHERE Column = Value;
Merge Command
The Merge command in SQL is used to perform an upsert operation, which combines
both UPDATE and INSERT actions. It allows you to insert new rows if they do not exist, or update
existing rows if they match a certain condition. This command is particularly useful for
synchronizing two tables by inserting new records and updating existing ones in a single operation.
Syntax:
MERGE INTO target_table AS target
USING source_table AS source
ON (target.id = source.id)
Page 8
WHEN MATCHED THEN
UPDATE SET target.name = source.name
WHEN NOT MATCHED THEN
INSERT (id, name) VALUES (source.id, source.name);
CALL Command
The Call command is used to invoke a stored procedure or user-defined function, which is a set of
precompiled SQL statements. It allows you to execute complex operations within a database as a
single unit.
Syntax:
CALL user_defined_function(parameter 1, parameter 2);
LOCK TABLE
The lock table command is used to lock the table for preventing access from others, ensuring no
other operations (like insertions, updates, or deletions) can be performed on the table while it's
locked. Useful for transactional operations where consistency is important.
Syntax:
LOCK TABLE your_table IN EXCLUSIVE MODE;
Commit Command
The COMMIT command is used to save all changes made during a transaction in the database.
This command ensures that modifications made by DML statements (such as INSERT, UPDATE,
or DELETE) become permanent in the database.
Syntax
Database Operation
Commit
ROLLBACK Command
The rollback command is used to restore the database to its state at the last COMMIT, effectively
undoing any changes made since that point. It helps ensure data consistency by allowing the reversal
of partial or erroneous operations.
Page 9
Syntax
ROLLBACK;
Data is typically structured across multiple tables, which can be joined together via a primary key or a
foreign key. These unique identifiers demonstrate the different relationships which exist between tables,
and these relationships are usually illustrated through different types of data models. Analysts use SQL
queries to combine different data points and summarize business performance, allowing organizations to
gain insights, optimize workflows, and identify new opportunities.
For example, imagine your company maintains a database table with customer information, which
contains company data at the account level. There may also be a different table, which describes all the
individual transactions that align to that account. Together, these tables can provide information about
the different industries that purchase a specific software product.
The columns (or fields) for the customer table might be Customer ID, Company Name, Company
Address, Industry etc.; the columns for a transaction table might be Transaction Date, Customer
ID, Transaction Amount, Payment Method, etc. The tables can be joined together with the
common Customer ID field. You can, therefore, query the table to produce valuable reports, such as a
sales reports by industry or company, which can inform messaging to prospective client
Page 10
1.6 DATABASE SYSTEM STRUCTURE
1. Query Processor:
It interprets the requests (queries) received from end user via an application program into
instructions. It also executes the user request which is received from the DML compiler.
Query Processor contains the following components –
DML Compiler: It processes the DML statements into low level instruction (machine
language), so that they can be executed.
DDL Interpreter: It processes the DDL statements into a set of table containing meta
data (data about data).
Embedded DML Pre-compiler: It processes DML statements embedded in an
application program into procedural calls.
Query Optimizer: It executes the instruction generated by DML Compiler.
Page 11
2. Storage Manager:
Storage Manager is a program that provides an interface between the data stored in the
database and the queries received. It is also known as Database Control System. It
maintains the consistency and integrity of the database by applying the constraints and
executing the DCL statements. It is responsible for updating, storing, deleting, and
retrieving data in the database.
It contains the following components –
Authorization Manager: It ensures role-based access control, i.e,. checks whether
the particular person is privileged to perform the requested operation or not.
Integrity Manager: It checks the integrity constraints when the database is modified.
Page 12
1.7.2 DATABASE USERS
Users are differentiated by the way they expect to interact with the system
• Application programmers – interact with system through DML calls
Page 14
Example:
Page 15
1.10.2 ATTRIBUTES
An entity is represented by a set of attributes, which are descriptive properties possessed by all
members of an entity set.
Domain – the set of permitted values for each attribute
Attribute types:
Simple and composite attributes.
Single-valued and multi-valued attributes
E.g. multivalued attribute: phone-numbers
Derived attributes
Can be computed from other attributes
Composite Attributes
Page 16
E-R Diagram with Composite, Multivalued, and Derived Attributes
Example:
Hayes depositor A-102
customer entity relationship set account entity
A relationship set is a mathematical relation among n 2 entities, each taken from entity
sets
Page 17
1.10.3.1 Degree of a Relationship Set
1.10.3.1.1 Refers to number of entity sets that participate in a relationship set.
1.10.3.1.2 Relationship sets that involve two entity sets are binary (or
degree two). Generally, most relationship sets in a database
system are binary.
1.10.3.1.3 Relationship sets may involve more than two entity sets.
1.10.3.1.4 Relationships between more than two entity sets are rare. Most relationships are binary.
Page 18
1.10.4 Relationship Sets with Attributes
Page 19
Many to One Many to Many
1.10.6 Roles
Entity sets of a relationship need not be distinct
The labels ―manager‖ and ―worker‖ are called roles; they specify how employee entities
interact via the works-for relationship set.
Roles are indicated in E-R diagrams by labeling the lines that connect diamonds to
rectangles.
Role labels are optional, and are used to clarify semantics of the relationship
Page 20
1.10.7 Cardinality Constraints
We express cardinality constraints by drawing either a directed line ( ), signifying
―one,‖ or an undirected line (—), signifying ―many,‖ between the relationship set and the
entity set.
In the one-to-many relationship a loan is associated with at most one customer via
borrower, a customer is associated with several (including 0) loans via borrower
Page 22
1.10.8.1 Alternative Notation for Cardinality Limits
Cardinality limits can also express participation constraints
1.11 Keys
Types of keys:
1. Primary key
o It is the first key used to identify one and only one instance of an entity uniquely. An entity can
contain multiple keys, as we saw in the PERSON table. The key which is most suitable from
those lists becomes a primary key.
Page 23
o In the EMPLOYEE table, ID can be the primary key since it is unique for each employee. In the
EMPLOYEE table, we can even select License_Number and Passport_Number as primary keys
since they are also unique.
o For each entity, the primary key selection is based on requirements and developers.
2. Candidate key
o A candidate key is an attribute or set of attributes that can uniquely identify a tuple.
o Except for the primary key, the remaining attributes are considered a candidate key. The candidate keys are as
strong as the primary key.
For example: In the EMPLOYEE table, id is best suited for the primary key. The rest of the attributes, like
SSN, Passport_Number, License_Number, etc., are considered a candidate key.
3. Super Key
Super key is an attribute set that can uniquely identify a tuple. A super key is a superset of a candidate key.
Page 24
For example: In the above EMPLOYEE table, for(EMPLOEE_ID, EMPLOYEE_NAME), the name
of two employees can be the same, but their EMPLYEE_ID can't be the same. Hence, this
combination can also be a key. The super key would be EMPLOYEE-ID (EMPLOYEE_ID,
EMPLOYEE-NAME), etc.
4. Foreign key
o Foreign keys are the column of the table used to point to the primary key of another table.
o Every employee works in a specific department in a company, and employee and department are
two different entities. So we can't store the department's information in the employee table. That's
why we link these two tables through the primary key of one table.
o We add the primary key of the DEPARTMENT table, Department_Id, as a new attribute in the
EMPLOYEE table.
o In the EMPLOYEE table, Department_Id is the foreign key, and both the tables are related.
5. Composite key
Whenever a primary key consists of more than one attribute, it is known as a composite key. This
key is also known as Concatenated Key.
Page 25
For example, in employee relations, we assume that an employee may be assigned multiple roles, and
an employee may work on multiple projects simultaneously. So the primary key will be composed of
all three attributes, namely Emp_ID, Emp_role, and Proj_ID in combination. So these attributes act as
a composite key since the primary key comprises more than one attribute.
Page 26
1.10.1 Specialization Example
1.11.2 Generalization
A bottom-up design process – combine a number of entity sets that share the same
features into a higher-level entity set.
Specialization and generalization are simple inversions of each other; they are
represented in an E-R diagram in the same way.
The terms specialization and generalization are used interchangeably.
Can have multiple specializations of an entity set based on different features.
E.g. permanent-employee vs. temporary-employee, in addition to officer vs. secretary vs.
teller
Each particular employee would be
a member of one of permanent-employee or temporary-employee,
and also a member of one of officer, secretary, or teller
The ISA relationship also referred to as superclass - subclass relationship
ISA person.
Page 27
user-defined
Constraint on whether or not entities may belong to more than one lower-level entity set
within a single generalization.
Disjoint
an entity can belong to only one lower-level entity set
Overlapping
an entity can belong to more than one lower-level entity set
Completeness constraint -- specifies whether or not an entity in the higher-level entity set must
belong to at least one of the lower-level entity sets within a generalization.
total : an entity must belong to one of the lower-level entity sets
partial: an entity need not belong to one of the lower-level entity sets
1.12 Aggregation
Page 28
1.13 E-R Design Decisions
The use of an attribute or entity set to represent an object.
Whether a real-world concept is best expressed by an entity set or a relationship set.
The use of a ternary relationship versus a pair of binary relationships.
The use of a strong or weak entity set.
The use of specialization/generalization – contributes to modularity in the design.
The use of aggregation – can treat the aggregate entity set as a single unit without
concern for the details of its internal structure.
Relation schema defines the design and structure of the relation or table in the database. It is the
way of representation of relation states in such a way that every relation database state fulfills the
integrity constraints set (Like Primary key, Foreign Key, Not null, Unique constraints) on a
relational schema.
It consists of the relation name, set of attributes/field names/column names. every attribute would
have an associated domain
Page 29