DBMS End Term
DBMS End Term
Note: Q. No. 1is compusory and attempt any two more questions from the remaining.
Q.1 (a) Difierentiate between primary key, candidate key and supcr key. (5x2)=10
List two reasons why null values might be introduccd into the
database.
(P.T.O)
Issuc (Roll No., ISBN, Date of issue)
Wrile the following queries cither in relaioalalyebra or SQ1.
()List roll no. and nane of all students of the branch CSE. (2)
k2) l'ind the name of students who have issucd a book published (2)
by `ABC" publisher.
a) List title of all books issued on or before Jan 1, 2016. (2)
Let R-(A.B,C) and let r and r; both be relations on schema R. Give (2+1)
an expression in SQL. that is equivalent to cach of the following
queries:
1. lAR (r) AIhc (r2)
2. r U2
What is a stored procedure? Why it is useful? Give an example. (3)
-XX
Topic. Date.
Bomatdsnt
Baamha Cse
Boe Tse
Bok TOBN oue, TSBN
Arleet A, e B B g e
unin
First Term Examination
Fourth Senmester (B.Tech.J-Jan-May 2016
|Paper Code: ETCS-208 Subject: Database Management System
Note: Q. No. Iis compulsory and attempt any two morequestions from the remaining
a) Give the relation obrained by Natural Join, Outer Join, Left Outer Join and Right Outer Join, Equi-Join
and Theta-Join. (6)
b) Give the Relation Algebra for the following Query (4)
i) Find the Customer name having loan in ICICÍ branch./Ctran/o
ii) Find the Branch Name and Loan No. with the Loan Amount greater then 10,800.TCICEn
='ABc( Tahe
Jcnlreme
Ta))
Q4. (a) Explain the following joins :
(i) Theta join
(ii) Lefn Outer join (212)
(b) Write down the following queries in SQL. (6)
Supplicrs (sno, sname, pincode, city)
Parts (pno, pname, color, weight)
Projects (projno, projname, city)
Shipments (sno, pno. projno)
() Get supplier name and city for suppliers who supply to any projcct with a 'red'
colored part.
(ii) Get part name, color and project name supplied by supplier with sno 'sl' to a
project located in London'.
(iii) Get the project names which are supplicd by supplier 'Manoj' with the part 'Bolt'.
awd
condon
Ci) les jrame
ad
and yrane Bset
Roll.No.
IV Semester |B.Tech)
Paper Code: ETCS-208
Time: 1 Hr.
First-Term Examination February-2015
Sub: Database Management System
Note: Attempt Q. Iwhich is Max. Marks: 30
compulsory and any two more Questions from
Q.1 Fill in the blanks remaining.
a
RDBMS stands for.
b
DCL stands for....DAta Catsl (10)
check any function in Oracle oppe
C. A special table to
d. An association between two or
is.
e. The command to more entities is...
f.. Database level is eliminate a table from adatabase 2elatiashp
recursive relationship is athe users is....ien)..is,c3p..
closest to table <table name>,
g. A
h. In a 1:N relationship
relationship, the foreign between an entity and.
key is placed
hierarchy is one in whichin.CJ.table.
i. A
superclass/subclass
.Entity related to two or more subclass has/have..A. Superlass.
attributès that apply to somé but not all of the associated entities that each
instances of the entity. contains specialized
Q.2
Describe briefly with an example:
attribute, descriptiveattributes. derivedattribute, multivalued attribute, composite attributes, complex
b. What is Data
Independence? Explain logical and physical data independence. (5)
Q.3 (5)
a.
Consider the two tables Ti (P, Q, R), T2 (S, T, U) as shown in fig I.
Show the results of the following .(5)
Table TI Table T2
PO R STIU
a
C 2 10 d3 10
2 3 10
a -
i Gp-(Tl) fg1
i. Ip, R(TI)
ii. TIu T2
iv. TIO T2
V. TI-T2
b. Define the concept of aggregation. Give two examples of where this
concept isuseful. (5)
Q. 4
employee(employee-name, street, city)
works(employee-name, company-name, salary))
companycompany-name, city)
(5X2)
manages(employee-name, manager-name)
Consider the employee database
and give an expression in SQL or Relational Algebra for each of the following
queries
a. Find the names of all employees who work for SBI
b. Find the names and cities of residence of all employees who work for SBI
C. Find all employees in the database who do not work for SBI
d. Modify the database so that Hari now lives in Pune
e. Delete all tuples in the works relation for employees of SBI
Copanynamne
sBT' chee
ame emplgee Jelect
except
ermployeama selat
alis
emplyeramea enplye.
SRz'ar
conpa-naQ> whe
ma, select (6)
emplyee
Company-names are
ad SBr -me Company
eme select (a) AN
narro.
Aonplenema
oih&ohy
ley oolote laom hs
whe ConpanyamSBr'
Mid- Term Examination
Fourth Semester, May 2023
Database Management System
CIC-210
Q 1 (a) What are the characteristics of database system?
Answer:
A database management system (DBMS) is a collection of programs that enables users
to create and maintain a database. The DBMS is hence a general-purpose software
system that facilitates the processes of defining, constructing, and manipulating
databases for various applications.
Traditionally, data was organized in file formats. DBMS was a new concept then, and
all the research was done to make it overcome the deficiencies in traditional style of
data management.
A modern DBMS has the following characteristics −
1. Real-world entity − A modern DBMS is more realistic and uses real-world entities
to design its architecture. It uses the behavior and attributes too. For example, a
school database may use students as an entity and their age as an attribute.
2. Relation-based tables − DBMS allows entities and relations among them to form
tables. A user can understand the architecture of a database just by looking at the
table names.
3. Isolation of data and application − A database system is entirely different than its
data. A database is an active entity, whereas data is said to be passive, on which the
database works and organizes. DBMS also stores metadata, which is data about
data, to ease its own process.
4. Less redundancy − DBMS follows the rules of normalization, which splits a
relation when any of its attributes is having redundancy in values. Normalization is
a mathematically rich and scientific process that reduces data redundancy.
5. Consistency − Consistency is a state where every relation in a database remains
consistent. There exist methods and techniques, which can detect attempt of leaving
database in inconsistent state. A DBMS can provide greater consistency as
compared to earlier forms of data storing applications like file-processing systems.
6. Query Language − DBMS is equipped with query language, which makes it more
efficient to retrieve and manipulate data. A user can apply as many and as different
filtering options as required to retrieve a set of data. Traditionally it was not possible
where file-processing system was used.
7. ACID Properties − DBMS follows the concepts of Atomicity,Consistency,
Isolation, and Durability (normally shortened as ACID). These concepts are applied
on transactions, whichmanipulate data in a database. ACID properties help the
database stay healthy in multi-transactional environments and in case of failure.
8. Multiuser and Concurrent Access − DBMS supports multi-user environment and
allows them to access and manipulate data in parallel. Though there are restrictions
on transactions when users attempt to handle the same data item, but users are
always unaware of them.
9. Multiple views − DBMS offers multiple views for different users. A user who is in
the Sales department will have a different view of database than a person working
in the Production department. This feature enables the users to have a concentrate
view of the database according to their requirements.
10. Security − Features like multiple views offer security to some extent where users
are unable to access data of other users and departments. DBMS offers methods to
impose constraints while entering data into the database and retrieving the same at
a later stage. DBMS offers many different levels of security features, which enables
multiple users to have different views with different features. For example, a user
in the Sales department cannot see the data that belongs to the Purchase department.
Additionally, it can also be managed how much data of the Sales department should
be displayed to the user. Since a DBMS is not saved on the disk as traditional file
systems, it is very hard for miscreants to break the code.
Answer:
The three-schema architecture can be used to explain the concept of data independence,
which can be defined as the capacity to change the schema at one level of a database
system without having to change the schema at the next higher level.
1. Logical data independence :Itis the capacity to change the conceptual schema
without having to change external schemas or application programs. We may
change the conceptual schema to expand the database (by adding a record type or
data item), or to reduce the database (by removing a record type or data item). In
the latter case, external schemas that refer only to the remaining data should not be
affected. Only the view definition and the mappings need be changed in a DBMS
that supports logical data independence. Application programs that reference the
external schema constructs must work as before, after the conceptual schema
undergoes a logical reorganization. Changes to constraints can be applied also to
the conceptual schema without affecting the external schemas or application
programs.
2. Physical data independence : It is the capacity to change the internal schema
without having to change the conceptual (or external) schemas. Changes to the
internal schema may be needed because some physical files had to be reorganized
- for example, by creating additional access structures - to improve the performance
of retrieval or update. If the same data as before remains in the database, we should
not have to change the conceptual schema.
`
(c) Compare and Contrast between relational algebra and relational calculus.
Answer:
Answer:
Join in DBMS is a binary operation which allows you to combine join product and selection in
one single statement. The goal of creating a join condition is that it helps you to combine the
data from two or more DBMS tables. The tables in DBMS are associated using the primary key
and foreign keys.
Types of Join
There are mainly two types of joins in DBMS:
I. Inner Join
Inner Join is used to return rows from both tables which satisfy the given condition. It is the
most widely used join operation and can be considered as a default join-type.An Inner join or
equijoin is a comparator-based join which uses equality comparisons in the join-predicate.
However, if you use other comparison operators like “>” it can’t be called equijoin.
1. Theta join
2. Natural join
3. EQUI join
1. Theta Join
Theta Join allows you to merge two tables based on the condition represented by theta. Theta
joins work for all comparison operators. It is denoted by symbol θ. The general case of JOIN
operation is called a Theta join.
Syntax:
A ⋈θ B
Table A Table B
column 1 column 2 column 1 column 2
1 1 1 1
1 2 1 3
For example:
2. EQUI Join
EQUI Join is done when a Theta join uses only the equivalence condition. EQUI join is the
most difficult operation to implement efficiently in an RDBMS, and one reason why RDBMS
have essential performance problems.
For example:
Natural Join does not utilize any of the comparison operators. In this type of join, the attributes
should have the same name and domain. In Natural Join, there should be at least one common
attribute between two relations.It performs selection forming equality on those attributes which
appear in both relations and eliminates the duplicate attributes.
Example:
C
Num Square
2 4
3 9
D
Num Cube
2 8
3 18
C⋈D
An Outer Join doesn’t require each record in the two join tables to have a matching record. In this
type of join, the table retains each record even if no other matching record exists.
A
Num Square
2 4
3 9
4 16
B
Num Cube
2 8
3 18
5 75
(A B)
Right Outer Join returns all the columns from the table on the right even if no matching rows
have been found in the table on the left. Where no matches have been found in the table on the
left, NULL is returned. RIGHT outer JOIN is the opposite of LEFT JOIN.
For e.g., let’s assume that you need to get the names of members and movies rented by them.
Now we have a new member who has not rented any movie yet.
A B
In a Full Outer Join , all tuples from both relations are included in the result, irrespective of the
matching condition.
Example:
(A B)
Answer:
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.
SQL can perform various tasks like create a table, add data to tables, drop the
table, modify the table, set permission for users.
There are five types of SQL commands: DDL, DML, DCL, TCL, and DQL.
DDL changes the structure of the table like creating a table, deleting a table,
altering a table, etc.
All the command of DDL are auto-committed that means it permanently save
all the changes in the database.
CREATE
ALTER
DROP
TRUNCATE
b. DROP: It is used to delete both the structure and record stored in the table.
Syntax
DROP TABLE table_name;
Example
DROP TABLE EMPLOYEE;
c. ALTER: It is used to alter the structure of the database. This change could be either
to modify the characteristics of an existing attribute or probably to add a new
attribute.
Syntax:
To add a new column in the table
ALTER TABLE table_name ADD column_name COLUMN-definition;
To modify existing column in the table:
ALTER TABLE table_name MODIFY(column_definitions....);
EXAMPLE
ALTER TABLE STU_DETAILS ADD(ADDRESS VARCHAR2(20)); ALTER TAB
LE STU_DETAILS MODIFY (NAME VARCHAR2(20));
d. TRUNCATE: It is used to delete all the rows from the table and free the space
containing the table.
Syntax:
TRUNCATE TABLE table_name;
Example:
TRUNCATE TABLE EMPLOYEE;
DML commands are used to modify the database. It is responsible for all form of
changes in the database.
The command of DML is not auto-committed that means it can't permanently save
all the changes in the database. They can be rollback.
INSERT
UPDATE
DELETE
a. INSERT: The INSERT statement is a SQL query. It is used to insert data into the
row of a table.
Syntax:
INSERT INTO TABLE_NAME (col1, col2, col3,.... col N) VALUES (value1, value2
, value3, .... valueN);
Or
INSERT INTO TABLE_NAME VALUES (value1, value2, value3, .... valueN);
For example:
INSERT INTO javatpoint (Author, Subject) VALUES ("Sonoo", "DBMS");
b. UPDATE: This command is used to update or modify the value of a column in the
table.
Syntax:
UPDATE table_name SET [column_name1= value1,...column_nameN = valueN] [W
HERE CONDITION]
For example:
UPDATE students SET User_Name = 'Sonoo' WHERE Student_Id = '3'
Q2 (a) Consider a university which has several schools. Each school is headed by a
teacher and offers one or more courses. A course can be offered by only one school. A
course can be offered by only one school. A course may be full time course or part time
course. Each course consists of a set of subjects. Each school may have one or more
teachers. A teacher can teach one or more subjects. The student can get admission in
only one course. You may assume appropriate attributes of each entity type and
relationship type. State assumptions clearly, if any.
Relational Algebra
Relational Algebra
c) List all booking for hotel ITC Maurya by the guest 'G010' using subquery.
SQL Command
Relational Algebra
Answer:
1. Physical Level:
2. Conceptual Level:
Conceptual level describes the structure of the whole database for a group of users.It is
also called as the data model.
Conceptual schema is a representation of the entire content of the database.
These schema contains all the information to build relevant external records.
It hides the internal details of physical storage.
3. External Level:
External level is related to the data which is viewed by individual end users.
This level includes a no. of user views or external schemas. This level is closest to the
user.
External view describes the segment of the database that is required for a particular user
group and hides the rest of the database from that user group.
(4) (b) What are integrity constraints? Explain different integrity constraints with the
help of examples.
Answer:
In DBMS, Integrity constraints can be defined as a set of rules that are used to maintain
the information’s quality. This ensures that the data integration is not affected at all by
data insertion, updation or other processes. Hence integrity constraints are like
insurance to guard the database if there is any accidental damage.
1. Domain constraint
2. Entity integrity constraint
3. Referential integrity constraint
4. Key constraint
1. Domain constraint
In DBMS, Domain constraints can be defined as a set of values that are valid for an
attribute. The domain’s data type includes string, character, integer, time etc. The value
must be in the corresponding domain of the attribute.
Example
Now in the table above, we can observe in the column Age, the data type of the domainis
an integer but the attributes data type is a character.
This constraint states that in DBMS we can not make the primary key with the value
NULL. Now, this is because if the primary key is NULL, then we won’t be able to
determine or identify the tuple in the relation.
But in a relation, there can be NULL values but they must be not the primary key.
Example
In the above example, S_No column and last tuple, the attribute is null, so it can not be
assigned as the primary key.
3. Referential integrity constraint
This constraint is defined between two tables. Let us consider tables A and B, so in this
constraint, if a foreign key is referred to as a primary key of another table then the
contents of the foreign key of table A must be null or available to table B.
Example
TABLE 1
TABLE 2
Code City
4178 Patna
2451 Delhi
9654 Mumbai
1258 Pune
Now in the example above, we can see that in table 1, Code 5758 is not valid, as this
attribute is not defined in table 2 and also the attribute is assigned as the primary key,
and also Code in table 1 is assigned the foreign key.
4. Key constraint
In DBMS, a key is used to uniquely identify an entity in an entity set. An entity set can
have multiple keys but out only one can be a primary key. This primary key should not
be null and must be unique. Although it can contain a null and a non-null unique value.
Example
In the example above, S_Nocan not be defined as a primary key because it contains a
duplicate value. All the rows must be unique.