Dbms Final Notes
Dbms Final Notes
Database Model
Ques. What is Database Model?
Sol.
• A database model is a type of data model that determines the logical structure of
a database and fundamentally determines in which manner data can be stored,
organized, and manipulated.
• The most popular example of a database model is the relational model, which
uses a table-based format.
Ques. What is Data Model?
Sol.
• A collection of conceptual tools for describing data, data relationships, data
semantics, and consistency constraints.
• A data model provides a way to describe the design of a database at the physical,
logical, and view levels.
• A data model organizes data elements and standardizes how the data elements
relate to one another.
Ques. Categories of Data Model?
Sol.
The data models can be classified into three different categories:
1. Object based logical model: Object-based logical models describe data at the
conceptual and view levels. Various types of object based logical models are as
follows: Entity-Relationship Model, Object-Oriented Database Management
System Model.
Sol.
• Select
• Project
• Union
• Set different
• Cartesian product
• Rename
Besides fundamental operations other relational algebra as follows:
• Namely
• Set intersection
• Natural join
• Division
• Assignment
Output: Selects tuples from books where subject is 'database' and 'price' is 450.
[3] Equation: σsubject = "database" and price = "450" or year > "2010"(Books)
Output: Selects tuples from books where subject is 'database' and 'price' is 450 or
those books published after 2010.
• The “select, project, rename” operations are called unary operations. Because
they operate on one relation.
• The “union, set difference, Cartesian product” operations are called binary
operations. Because they operate on pairs relation.
Ques. Select those tuples of the loan relation where the branch is “Perryridge”
Sol. σbranch-name= "Perryridge" (loan)
Ques. Find all tuples in which the amount is more than $1200?
Output: Yields a relation, which shows all the books and articles written by
tutorialspoint.
Output: Provides the name of authors who have written books but not articles.
Ques. Find the names of all bank customers who have either an account or a loan or
both?
Sol.
• The result of set difference operation is tuples, which are present in one relation
but are not in the second relation.
• Notation : r − s
• Finds all the tuples that are present in r but not in s.
• r and s must have the same number of attributes.
• Attribute domains must be compatible.
• Example: ∏ author (Books) − ∏ author (Articles)
Output − Provides the name of authors who have written books but not articles.
Ques: Find the names of all customers who have a loan at the Perryridge branch.
Ques. Find all loan numbers for loans made at the Perryridge branch with loan
amounts greater that $1200.
Sol.
• select loan_number
• from loan
• where branch_name = ’Perryridge’ and amount> 1200
Ques. Find the loan number of those loans with loan amounts between $90,000 and
$100,000.
Sol.
• select loan_number
• from loan
• where amount between 90000 and 100000
Sol.
• To remove a relation from an SQL database, we use the drop table command.
• The drop table command deletes all information about the dropped relation
from the database.
• alter table relation_name drop Attribute_name;
Ques. Find instructor names and course identifiers for instructors in the Computer
Science department.
Sol.
Sol.
Natural Join:
• The natural join operation operates on two relations and produces a relation as
the result.
• Natural join considers only those pairs of tuples with the same value on those
attributes that appear in the schemas of both relations.
• Example:
SELECT *
FROM table1
NATURAL JOIN table2;
Cartesian Product:
• A Cartesian product is the result of joining every row in one table with every row
in another table.
• Cartesian product of two relations, which concatenates each tuple of the first
relation with every tuple of the second
• Example:
SELECT ID, NAME, AMOUNT, DATE
FROM CUSTOMERS, ORDERS;
Lecture 9
Ques. Find the names of all instructors whose salary is greater than at least one
instructor in the Biology department.
Sol.
Ques. Find the names of all departments whose building name includes the substring
‘Watson’.
Sol.
• select dept_name
• from department
• where building like ’%Watson%’;
Sol.
• select name
• from instructor
• where dept_name= ’Physics’
• order by name;
By default, the order by clause lists items in ascending order.
Ques. Find the set of all courses taught either in Fall 2009 or in Spring 2010, or both.
Sol.
• (select course id
• from section
• where semester = ’Fall’ and year = 2009)
union
• (select course id
• from section
• where semester = ’Spring’ and year = 2010);
Ques. Find all courses taught in the Fall 2009 semester but not in the Spring 2010
semester.
Sol.
• (select course_id
• from section
• where semester = ’Fall’ and year = 2009)
intersect
• (select course id
• from section
• where semester = ’Spring’ and year = 2010);
Sol.
Sol.
Sol.
• COUNT function is used to Count the number of rows in a database table. It can
work on both numeric and non-numeric data types.
• COUNT function uses the COUNT(*) that returns the count of all the rows in a
specified table. COUNT(*) considers duplicate and Null.
• Count() Syntax:
SELECT COUNT(column_name)
FROM table_name
WHERE condition;
Ques: Find all the courses taught in the both the Fall 2009 and Spring 2010 semesters.
Sol.
• select distinct course_id
• from section
• where semester = ’Fall’ and year = 2009 and
Course_id in (select course_id
from section
where semester = ’Spring’ and year
= 2010);
Ques. Find all the courses taught in the Fall 2009 semester but not in the Spring 2010
semester.
Sol.
• select distinct course_id
• from section
• where semester = ’Fall’ and year = 2009 and
course_id not in (select course_id
from section
where semester = ’Spring’ and
year = 2010);
Ques. Find the names of all instructors whose salary is greater than at least one
instructor in the Biology department.
Sol.
Ques: Delete all tuples in the instructor relation for those instructors associated with a
department located in the Watson building.
Sol.
• delete from instructor
• where dept_name in (select dept_name
from department
where building = ’Watson’);