0% found this document useful (0 votes)
33 views130 pages

DBMS60

The document outlines the advantages and disadvantages of physical data storage and spreadsheet files, emphasizing durability, scalability, security, retrieval, and consistency. It discusses levels of abstraction in database management, data models, and SQL, including DDL and DML. Additionally, it covers database design, keys, joins, views, triggers, and the structure of entity sets.

Uploaded by

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

DBMS60

The document outlines the advantages and disadvantages of physical data storage and spreadsheet files, emphasizing durability, scalability, security, retrieval, and consistency. It discusses levels of abstraction in database management, data models, and SQL, including DDL and DML. Additionally, it covers database design, keys, joins, views, triggers, and the structure of entity sets.

Uploaded by

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

Week 1 DBMS

Disadvantages of Physical data storage

• Durability: Physical damage to these registers is a possibility due to


rodents, humidity, wear and tear
• Scalability: Very difficult to maintain for many years, some shops have
numerous registers spanning over years
• Security: Susceptible to tampering by outsiders
• Retrieval: Time consuming process to search for a previous entry
• Consistency: Prone to human errors
Advantages of spreadsheet files

• Durability: These are computer applications and hence data is less prone
to physical damage.
• Scalability: Easier to search, insert and modify records as compared to
book ledgers
• Security: Can be password-protected
• Ease of Use: Computer applications are used to search and manipulate
records in the spreadsheets leading to reduction in manpower
• Consistency: Not guaranteed but spreadsheets are less prone to
mistakes than registers.
Level of abstraction

View level
NOTE
▪ Physical Data Independence – the
ability to modify the physical schema
without changing the logical schema
Logical level
▪ Logical Data Independence- the ability
to modify the logical level without
changing the view level.

Physical level
Schema
Instance
Data Models
• Relational model (data stored in various tables)
• A collection of tools for describing
• Entity-Relationship data model
◦ Data • Object-based data models (flat, atomic values)
◦ Data relationships • Network model
◦ Data semantics • Hierarchical model
• Recent models for Semi-structured or
◦ Data constraints
Unstructured data

Relational algebra

Pure Tuple relational calculus

Language Domain relational calculus

Commercial SQL
DDL(data definition language) DML (data manipulation language)
• Specification notation to define the • Language to manipulate and access data
database schema
• Ex- create table, drop table, alter table • Ex- insert, update, delete
• It generates a set of table templates
stored in a data dictionary • It is also known as query language

SQL(Structured query language)


• Most widely used commercial language
• It is not a turning machine equivalent language ( it means all C programs
cannot run in SQL but vice versa is true.)
Database design

Logical design Physical design

• What attributes to record? • Decides the physical layout of


• What relation schemas should we have? the database
• How should the attributes be
distributes?

XML(Extensible Markup Language):


• defined by www consortium(W3C).
• Has ability to specify new tags and create nested tag structures.
Database engine

Storage management Query processing Transaction management

• interface between the • Parsing and translation A transaction is a collection of operations that
low-level data stored in • Optimization performs a single logical function in a
the database and the • Evaluation database application
application programs and
• Transaction-management component:
queries submitted to the It helps in estimating the cost
ensures that the database remains in a
system. of operation.
consistent state despite system failures
and transaction failures.
• Interacts with OS file
• Concurrency-control manager: controls
manager.
the interaction among the concurrent
transactions, to ensure the consistency
• Stores, retrieves and
of the database.
updates data.
WEEK 2 DBMS
Super key

Candidate key Compound key

Primary key Surrogate


key

Any key which has more than one attribute. Example-


Composite
{orderId, productId} is a primary composite key. *two
key primary keys needed to uniquely identify*

Secondary
Any key which identifies a tuple
simple key uniquely with just a single attribute. key
Super key: set of one or more attributes which can uniquely identify a
tuple. It should have the primary key and then it can include the keys
which doesn’t determine uniqueness. Example: {empID},
{empID,empName},{empID,empName,empPhone}

Candidate key: minimal super key. Example: if {empID} and {empEmail}


is individually a candidate key, then {empID, empEmail} can’t be
candidate key.

Primary key: a candidate key which isn’t null. {empID}

Secondary key: non unique key which forms indices.


ex: empName

Compound key: set of multiple attributes which can individually be a


candidate key of other tables.

Surrogate key: any key which can be system generated. Example:


{rollno}
Selects rows
where A=B and D
is greater than 5
Selects only A
and C
columns and
removes
duplicates
UNION- takes all the values of both the tables

SET DIFFERENCE- example r-s takes the tuples of r which are not present in s

SET INTERSECTION- takes the common tuples


Note: r ∩ s = r − (r − s)

CARTESIAN PRODUCT- example r x s NATURAL JOIN


DDL
A language which is used design the schema of the database and also modifies it.
• It is a part of SQL

• Integrity constraints: are rules that maintains


the consistency of the data by enforcing some
conditions on data values.

• DDL enforces or specifies the integrity


constraints while defining or modifying the
schema

• Data dictionary: contains data about


data(metadata) stored in the database. It
stores the data generated by DDL commands
along with the integrity constraints.
SELECT Clause
FROM Clause
• DISTINCT - Selects all the distinct
Specifies the table
values
name.
• * - Selects all the attributes
• as - Renames the attribute
From instructor, course
• TOP <n> - selects top n tuples
will result in a cross-
join between two
tables

WHERE Clause
Specifies conditions to retrieve data
WHERE i.course_id=c.course_id and i.dept_name='Biology' and
salary>40000
STRING OPERATION

• LIKE - Uses the pattern that are described in like condition and matches with the
attribute
• % - matches any substring %abc%
%abc
abc%

• '_ _ _' matches any string of exactly three characters


• '_ _ _%' matches any string of at least three characters
DBMS WEEK 3
Select distinct Select all

Select all and select will give the same


result
AS operation

Renames student relation as S and


relation department as D
Nested Subquery

A subquery is a select-from-where expression that is nested within another query.

Some Clause

• 5 > some(0, 5, 6) - True


• 5 = some(0, 5, 6) - True

All Clause

• 7 > all(0, 5, 6) - True


• 5 = all(0, 5, 6) - False
IN operator

IN also acts like or


operator
Except
AVG aggregate function
MIN aggregate function
MAX aggregate function
COUNT aggregate function
SUM aggregate function
EXISTS clause

This should
exist(be true) for
the above query
to execute
Will show all courses which were taught in
2009 and 2010 in fall and spring semester.
NOT EXISTS clause
WITH clause

WITH AvgSalary AS ( SELECT AVG(salary) AS


avg_salary Shows the names of employees
and their salaries if they get more
FROM Salaries )
than average salary.

SELECT e.employee_name, s.salary


FROM Employees e JOIN Salaries s ON
e.employee_id = s.employee_id WHERE s.salary >
(SELECT avg_salary FROM AvgSalary);
INSERTION
UPDATES

Updates the salary by 3%


or 5% based on given
condition
JOINS

cross join: cartesian product of rows.


Inner join: intersection (the duplicate column is present)
Natural join: intersection (the duplicate column is not present)
Full outer join: union (uses null values) (keys are explicitly defined)
Left outer join: set A + intersection of set A and B
Right outer join: set B + intersection of set A and B
Natural full outer join: union (keys are not explicitly defined)
SELECT Students.Name, Courses.CourseName FROM Students
INNER JOIN Courses ON Students.StudentID = Courses.StudentID;

Select Students.Name, Courses.CourseName from Students LEFT


JOIN Courses ON Students.StudentID = Courses.StudentID;

SELECT Students.Name, Courses.CourseName FROM Students RIGHT JOIN Courses ON


Students.StudentID = Courses.StudentID;
SELECT Students.Name, Courses.CourseName FROM Students FULL
OUTER JOIN Courses ON Students.StudentID = Courses.StudentID;

SELECT Students.StudentID, Students.Name, Courses.CourseID,


Courses.CourseName FROM Students NATURAL JOIN Courses;
VIEWS
• A view provides a mechanism to hide certain data from the view of certain users
• Any relation that is not of the conceptual model but is made visible to a user as a “virtual relation” is called a
view.

A view relation v1 is said to depend directly on a view


relation v2 if v2 is used in the expression defining v1.

A view relation v is said to be recursive if it depends on


itself.

A view relation v1 is said to depend on view relation v2


if either v1 depends directly to v2 or there is a path of
dependencies from v1 to v2.
TRIGGERS

• Automatic execution of specific action


• Executed before or after an action

• Row level trigger: executed for each row


• Statement level trigger: executes for all
rows only once.
Table level

Row level Statement


level
DBMS Week 4
Students table
Strong entity set with composite key

Students table
Strong entity set with composite key and multivalued attribute

It is better to
decompose these
kinds of tables
into multiple
tables to avoid
redundancy and
inconsistency
Strong entity set with composite key, multivalued attribute and derived
attribute
The primary key of
one becomes a
attribute of many.

Course_num(primary
key of one) becomes
attribute of
student(many)
Ternary relationship
DBMS Week 5
Extraneous attribute
DBMS Week 6
Week 8 DBMS
The root node is said to be at Level 0 and
the children of the root node are at
Level 1 until and unless root is specified to
exist at level 1

You might also like