unit -4 dbms
unit -4 dbms
For example:
One table might hold information about students (with columns like ID,
name, age).
Another table might store courses (with columns like course ID, course
name, credits).
Advantages
Easy to understand and manage structured data.
Ensures data accuracy and reduces redundancy.
Supports complex queries with SQL.
Disadvantages
Slows down with very large datasets.
Requires detailed setup and planning.
Less suitable for unstructured data.
I
Relational Constraints are rules applied to a relational database to maintain
data accuracy, consistency, and integrity.
These constraints ensure that the data stored in the database adheres to certain
standards, preventing errors and invalid data.
For example, a column for "age" must contain only integer values within a valid
range.
This is achieved through Primary Keys, which must have unique values and
cannot be null.
Foreign Keys enforce this by referencing a primary key from another table. If a
foreign key is used, the referenced value must exist in the primary table.
Relational Algebra
In DBMS is a procedural query language that defines operations to retrieve data
from relational databases.
A B C
1 2 4
2 2 3
3 2 3
4 3 4
For the above relation, σ(c>3) R will select the tuples which have c more than 3.
A B C
1 2 4
4 3 4
1 2 4
2 2 3
3 2 3
4 3 4
B C
2 4
2 3
3 4
Union (∪): Combines rows from two tables with the same structure, removing
duplicates.
Ram 01
Mohan 02
Vivek 13
Geeta 17
GERMAN
student Name Roll Number
Vivek 13
Geeta 17
Shyam 21
student Name Roll Number
Rohan 25
Consider the following table of Students having different optional subjects
in their course.
π(Student_Name)FRENCH U π(Student_Name)GERMAN
Student_Name
Ram
Mohan
Vivek
Geeta
Shyam
Rohan
Set Difference (-): Returns rows present in one table but not in another.
Example: From the above table of FRENCH and GERMAN, Set Difference is
used as follows
π(Student_Name)FRENCH - π(Student_Name)GERMAN
Student_Name
Ram
Mohan
Cartesian Product (×): Combines each row of one table with each row of another
table.
Example: Table1 × Table2, pairs every row in "Table1" with every row in
"Table2."
Ram 14 M
Sona 15 F
Kim 20 M
B
ID Course
1 DS
2 DBMS
Ax
B
Name Age Sex ID Course
Ram 14 M 1 DS
Ram 14 M 2 DBMS
Sona 15 F 1 DS
Sona 15 F 2 DBMS
Kim 20 M 1 DS
Name Age Sex ID Course
Kim 20 M 2 DBMS
Derived Operators:
Natural Join (⨝): Automatically joins tables on columns with the same name and
values.
Example:
EMP
Name ID Dept_Name
A 120 IT
B 125 HR
C 110 Sales
D 111 IT
DEPT
Dept_Name Manager
Sales Y
Production Z
IT A
Natural join between EMP and DEPT with condition:
EMP ⋈ DEPT
EMP.Dept_Name = DEPT.Dept_Name
Name ID Dept_Name Manager
A 120 IT A
C 110 Sales Y
D 111 IT A
SQL enables users to create, manage, and manipulate databases by defining and
accessing data efficiently.
Overview of SQL:
IBM developed the original version of SQL, originally called Sequel (Structured
English Query Language), as part of the System R project in the early 1970s.
The Sequel language has evolved since then, and its name has changed to SQL
(Structure Query Language) (some other company has trademark on the word
sequel). SQL has clearly as the standard relational database language.
In 1986, the American National Standards Institute (ANSI) and the International
Organization Standardization (ISO) published an SQL standard, called SQL-86.
The next version of the standard was SQL-89, SQL-92, SQL: 1999, SQL:2003,
SQL:200 SQL:2011, SQL: 2016, SQL: 2019and most recently SQL:2023.
Characteristics of SQL
Examples:
Examples:
SELECT: Retrieves data from tables, allowing filtering, sorting, and grouping.
Examples:
SQL Commands
SQL commands are instructions. It is used to communicate with the database. It is
also used to perform specific tasks, functions, and queries of data.
UPDATE table_name
SET column1 = value1, column2 = value2, ...
WHERE condition;
COMMIT;
SAVEPOINT: Set a point in a transaction to which you can later roll back.
SAVEPOINT savepoint_name;