0% found this document useful (0 votes)
142 views29 pages

RDBMS - IMP Questions

This document contains sample questions and answers related to Relational Database Management Systems (RDBMS). The first question asks about advantages of DBMS over file-based systems and lists several advantages including program data independence, reduced data redundancy, data sharing, improved data integrity, data security, privacy, backup/recovery, and data consistency. The second question explains the role and functions of a Database Administrator (DBA), including software installation/maintenance, data extraction/transformation/loading, specialized data handling, backup/recovery, security, authentication, capacity planning, performance monitoring, database tuning, and troubleshooting. The third question provides an explanation of Entity-Relationship (ER) modeling with an example, noting that ER

Uploaded by

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

RDBMS - IMP Questions

This document contains sample questions and answers related to Relational Database Management Systems (RDBMS). The first question asks about advantages of DBMS over file-based systems and lists several advantages including program data independence, reduced data redundancy, data sharing, improved data integrity, data security, privacy, backup/recovery, and data consistency. The second question explains the role and functions of a Database Administrator (DBA), including software installation/maintenance, data extraction/transformation/loading, specialized data handling, backup/recovery, security, authentication, capacity planning, performance monitoring, database tuning, and troubleshooting. The third question provides an explanation of Entity-Relationship (ER) modeling with an example, noting that ER

Uploaded by

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

B.

Com Compute Applications


II year - III Semester
Subject: Relational Database Management System (RDBMS)
Paper Code – DSC 303
Unit Wise - Important Questions

Unit – 1

Q1. Explain advantages of DBMS over file based system.


Answer:
i. Program data independency
ii. Reducing Data Redundancy
iii. Sharing of Data
iv. Data Integrity (improved)
v. Data Security
vi. Privacy
vii. Backup and Recovery
viii. Data Consistency

i. Program data independency: In DBMS, data is stored in a central location called


repository. The process of database allows an enterprise’s data to change the database
without modifying the application programs which are able to process this data. This
allows the separation of database from the application programs.
ii. Reducing Data Redundancy: The file based data management systems contained
multiple files that were stored in many different locations in a system or even across
multiple systems. Because of this, there were sometimes multiple copies of the same file
which lead to data redundancy. This is prevented in a database as there is a single
database and any change in it is reflected immediately. Because of this, there is no
chance of encountering duplicate data.
iii. Sharing of Data: In a database, the users of the database can share the data among
themselves. There are various levels of authorisation to access the data, and consequently
the data can only be shared based on the correct authorisation protocols being followed.
Many remote users can also access the database simultaneously and share the data
between themselves.
iv. Data Integrity: Data integrity means that the data is accurate and consistent in the
database. Data Integrity is very important as there are multiple databases in a DBMS. All
of these databases contain data that is visible to multiple users. So it is necessary to
ensure that the data is correct and consistent in all the databases and for all the users.
v. Data Security: Data Security is vital concept in a database. Only authorised users should
be allowed to access the database and their identity should be authenticated using a
username and password. Unauthorised users should not be allowed to access the database
under any circumstances as it violates the integrity constraints.
vi. Privacy: The privacy rule in a database means only the authorized users can access a
database according to its privacy constraints. There are levels of database access and a
user can only view the data he is allowed to. For example - In social networking sites,
access constraints are different for different accounts a user may want to access.
vii. Backup and Recovery: Database Management System automatically takes care of
backup and recovery. The users don't need to backup data periodically because this is
taken care of by the DBMS. Moreover, it also restores the database after a crash or
system failure to its previous condition.
viii. Data Consistency: Data consistency is ensured in a database because there is no data
redundancy. All data appears consistently across the database and the data is same for all
the users viewing the database. Moreover, any changes made to the database are
immediately reflected to all the users and there is no data inconsistency.

Q2. Explain the DBA functions and Role.


Answer:
A person who has such control over the system is called a Database Administrator. In Other
words Database Administration is more of an operational or technical level function
responsible for physical database design, security enforcement, and database performance.
Tasks include maintaining the data dictionary, monitoring performance, and enforcing
organizational standards and security.
A database administrator's (DBA) primary job is to ensure that data is available, protected
from loss and corruption, and easily accessible as needed. Below are some of the chief
responsibilities that make up the day-to-day work of a DBA. The role of the DBA is not that
different.

a) Software installation and Maintenance


b) Data Extraction, Transformation, and Loading
c) Specialized Data Handling
d) Database Backup and Recovery
e) Security
f) Authentication
g) Capacity Planning
h) Performance Monitoring
i) Database Tuning
j) Troubleshooting

a. Software installation and Maintenance

A DBA often collaborates on the initial installation and configuration of a new Oracle, SQL
Server etc database. The system administrator sets up hardware and deploys the operating
system for the database server, then the DBA installs the database software and configures it
for use. As updates and patches are required, the DBA handles this on-going maintenance.

And if a new server is needed, the DBA handles the transfer of data from the existing system
to the new platform.

b. Data Extraction, Transformation, and Loading


Known as ETL, data extraction, transformation, and loading refers to efficiently importing
large volumes of data that have been extracted from multiple systems into a data warehouse
environment.

This external data is cleaned up and transformed to fit the desired format so that it can be
imported into a central repository.

c. Specialised Data Handling

Today’s databases can be massive and may contain unstructured data types such as images,
documents, or sound and video files. Managing a very large database (VLDB) may require
higher-level skills and additional monitoring and tuning to maintain efficiency.

d. Database Backup and Recovery

DBAs create backup and recovery plans and procedures based on industry best practices, then
make sure that the necessary steps are followed. Backups cost time and money, so the DBA
may have to persuade management to take necessary precautions to preserve data.

System admins or other personnel may actually create the backups, but it is the DBA’s
responsibility to make sure that everything is done on schedule.

In the case of a server failure or other form of data loss, the DBA will use existing backups to
restore lost information to the system. Different types of failures may require different
recovery strategies, and the DBA must be prepared for any eventuality. With technology
change, it is becoming ever more typical for a DBA to backup databases to the cloud, Oracle
Cloud for Oracle Databases and MS Azure for SQL Server.
e. Security

A DBA needs to know potential weaknesses of the database software and the company’s
overall system and work to minimise risks. No system is one hundred per cent immune to
attacks, but implementing best practices can minimise risks.

In the case of a security breach or irregularity, the DBA can consult audit logs to see who has
done what to the data. Audit trails are also important when working with regulated data.

f. Authentication

Setting up employee access is an important aspect of database security. DBAs control who
has access and what type of access they are allowed. For instance, a user may have
permission to see only certain pieces of information, or they may be denied the ability to
make changes to the system.

g. Capacity Planning

The DBA needs to know how large the database currently is and how fast it is growing in
order to make predictions about future needs. Storage refers to how much room the database
takes up in server and backup space. Capacity refers to usage level.
If the company is growing quickly and adding many new users, the DBA will have to create
the capacity to handle the extra workload.

h. Performance Monitoring

Monitoring databases for performance issues is part of the on-going system maintenance a
DBA performs. If some part of the system is slowing down processing, the DBA may need to
make configuration changes to the software or add additional hardware capacity. Many types
of monitoring tools are available, and part of the DBA’s job is to understand what they need
to track to improve the system. 3rd party organisations can be ideal for outsourcing this
aspect, but make sure they offer modern DBA support.
i. Database Tuning

Performance monitoring shows where the database should be tweaked to operate as


efficiently as possible. The physical configuration, the way the database is indexed, and how
queries are handled can all have a dramatic effect on database performance.

With effective monitoring, it is possible to proactively tune a system based on application and
usage instead of waiting until a problem develops.

j. Troubleshooting

DBAs are on call for troubleshooting in case of any problems. Whether they need to quickly
restore lost data or correct an issue to minimize damage, a DBA needs to quickly understand
and respond to problems when they occur.

Q3. Explain entity – Relationship (ER) Model with Example.


The ER or (Entity Relational Model) is a high-level conceptual data model diagram. Entity-
Relation model is based on the notion of real-world entities and the relationship between them.

ER modelling helps you to analyse data requirements systematically to produce a well-


designed database. So, it is considered a best practice to complete ER modelling before
implementing your database.

Entity: Entities are represented by means of rectangles. Rectangles are named with the entity set
they represent.

Attributes - Attributes are the properties of entities. Attributes are represented by means of ellipses.
Every ellipse represents one attribute and is directly connected to its entity (rectangle).
If the attributes are composite, they are further divided in a tree like structure. Every node is then
connected to its attribute. That is, composite attributes are represented by ellipses that are connected
with an ellipse.

Multivalued attributes are depicted by double ellipse.

Derived attributes are depicted by dashed ellipse.

Relationship
Relationships are represented by diamond-shaped box. Name of the relationship is written inside the
diamond-box. All the entities (rectangles) participating in a relationship, are connected to it by a line.

Binary Relationship and Cardinality


A relationship where two entities are participating is called a binary relationship. Cardinality is the
number of instance of an entity from a relation that can be associated with the relation.
 One-to-one − When only one instance of an entity is associated with the relationship, it is
marked as '1:1'. The following image reflects that only one instance of each entity should be
associated with the relationship. It depicts one-to-one relationship.

 One-to-many − When more than one instance of an entity is associated with a relationship, it
is marked as '1:N'. The following image reflects that only one instance of entity on the left and
more than one instance of an entity on the right can be associated with the relationship. It
depicts one-to-many relationship.

 Many-to-one − When more than one instance of entity is associated with the relationship, it is
marked as 'N:1'. The following image reflects that more than one instance of an entity on the
left and only one instance of an entity on the right can be associated with the relationship. It
depicts many-to-one relationship.

 Many-to-many − The following image reflects that more than one instance of an entity on the
left and more than one instance of an entity on the right can be associated with the
relationship. It depicts many-to-many relationship.

Participation Constraints
 Total Participation − Each entity is involved in the relationship. Total participation is
represented by double lines.

 Partial participation − Not all entities are involved in the relationship. Partial participation is
represented by single lines.
Short Answer Questions

Q1. DBMS
Database Management System (DBMS) is software for storing and retrieving users' data
while considering appropriate security measures. It consists of a group of programs which
manipulate the database. The DBMS accepts the request for data from an application and
instructs the operating system to provide the specific data. In large systems, a DBMS helps
users and other third-party software to store and retrieve data.

DBMS allows users to create their own databases as per their requirement. The term
“DBMS” includes the user of the database and other application programs. It provides an
interface between the data and the software application.

DBMS also provides protection and security to the databases. It also maintains data
consistency in case of multiple users.

Here are some examples of popular DBMS used these days:

 MySql
 Oracle
 SQL Server
 IBM DB2
 PostgreSQL
 Amazon SimpleDB (cloud based) etc
Q2. Referential integrity
Ans: A referential integrity constraint is specified between two tables.
It specifies that all the values taken by the foreign key must either be available in the relation
of the primary key or be null.
In the Referential integrity constraints, if a foreign key in Table 1 refers to the Primary Key
of Table 2, then every value of the Foreign Key in Table 1 must be null or be available in
Table.
So referential integrity will prevent users from:
Adding rows to a related table if there is no associated row in the primary table.
Changing values in a primary table that result in orphaned records in a related table.
Deleting rows from a primary table if there are matching related rows.

Q3. Database
Ans:
Database: Database is a collection of inter-related data which helps in efficient retrieval,
insertion and deletion of data from database and organizes the data in the form of tables,
views, schemas, reports etc. For Example, university database organizes the data about
students, faculty, and admin staff etc. which helps in efficient retrieval, insertion and deletion
of data from it.

Q4. Database Approach


Ans:
The database approach is an improvement on the shared file solution as the use of a database
management system (DBMS) provides facilities for querying, data security and integrity, and
allows simultaneous access to data by a number of different users. At this point we should
explain some important terminology:
 Database: A database is a collection of related data.
 Database management system: The term 'database management system', often
abbreviated to DBMS, refers to a software system used to create and manage
databases. The software of such systems is complex, consisting of a number of
different components, which are described later in this chapter. The term database
system is usually an alternative term for database management system.
 System catalogue/Data dictionary: The description of the data in the database
management system.
 Database application: Database application refers to a program, or related set of
programs, which use the database management system to perform the computer-
related tasks of a particular business function, such as order processing.
Q5. Data Redundancy
Redundancy means having multiple copies of same data in the database. This problem arises
when a database is not normalized. Suppose a table of student details attributes are: student
Id, student name, college name, college rank and course opted.

Student_id Name Contact College Course Rank


100 Himanshu 7897897890 Aurora B.Com 1
101 Ankit 7897897891 Aurora B.Com 1
102 Aysuh 7897897892 Aurora B.Com 1
103 Ravi 7897897893 Aurora B.Com 1

As it can be observed that values of attribute college name, college rank, course is being
repeated which can lead to problems. Problems caused due to redundancy are: Insertion
anomaly, Deletion anomaly, and Updation anomaly.

Q6. Primary Key


Ans:
Primary Key is a column or group of columns in a table that uniquely identify every row in
that table. The Primary Key can't be a duplicate meaning the same value can't appear more
than once in the table. A table cannot have more than one primary key.
Rules for defining Primary key:

 Two rows can't have the same primary key value


 It must for every row to have a primary key value.
 The primary key field cannot be null.
 The value in a primary key column can never be modified or updated if any foreign
key refers to that primary key.

Q7. Relational Model


Ans:
In relational model, the data and relationships are represented by collection of inter-related
tables. Each table is a group of column and rows, where column represents attribute of an
entity and rows represents records. The Relational Model was proposed by E.F. Codd to
model data in the form of relations or tables.
Benefits of Relational Model: A Relational Database system has multiple other advantages
over any other type of database. Below are the few significant advantages
 Ease of use
 Accuracy
 Simple Mode
 Data Accuracy
 Easy Access to Data
 Normalization
 High Security
 Data Integrity
 Flexibility
 Feasible for Future Modifications

Unit-2
Q1: Explain 1NF, 2NF, 3NF and BCNF. (Or) Explain the types of Normal Forms.
Ans:
The Normal Forms
The stage of a relation which is organized by removing redundant data is known as its normal
form (or a state of normalization).
Types of Normal Forms.
 First Normal form (1NF)
 Second Normal Form (2NF)
 Third Normal Form (3NF)
 BCNF Normal Form
First Normal Form (or 1NF)
Table is said to be in 1NF if the following rules hold:
1. Columns must have single values
2. Columns must have unique names
3. Values of a given attribute must be of the same data type
4. No two records (or rows) can be identical

The following table not in 1NF. (Un-normalized form)

ClientID ClientName ClientNo


256-2568
015 John
524-4589
487-5485
016 Princess
451-copy
027 Tom 458-4587
478-2689
028 Claire
265-1486
485-5584
029 Robert
254-visa
The above reformed into 1NF as follows

ClientID ClientName ClientNo


015 John 256-2568
015 John 524-4589
016 Princess 487-5485
016 Princess 451-2679
027 Tom 458-4587
028 Claire 478-2689
028 Claire 265-1486
029 Robert 485-5584
029 Robert 254-8472

Second normal form (2NF)


A table is said to be in 2NF if both the following conditions hold:
 Table is in 1NF (First normal form)
 every non-key attribute fully depends on the primary key of the relation
 No non-prime attribute is dependent on the proper subset of any candidate key of table.

Note: An attribute that is not part of any candidate key is known as non-key attribute.

teacher_id Subject teacher_age


111 Maths 38
111 Physics 38
222 Biology 38
333 Physics 40
333 Chemistry 40

Candidate Keys: {teacher_id, subject}


Non prime attribute: teacher_age

The above table in 1NF but not in 2NF. Because, non-prime attribute TEACHER_AGE is
dependent on TEACHER_ID which is a proper subset of a candidate key.Then the table can
be decomposed as follows
Teacher_details table: Teacher_subject table:
teacher_id teacher_age teacher_id Subject
111 38 111 Maths
222 38 111 Physics
333 40 222 Biology
333 Physics
333 Chemistry
3. Third Normal Form

A table design is said to be in A table design is said to be in 3NF if both the following A table
design is said to be in 3NF if both the following conditions hold:

 Table must be in 2NF


 Transitive functional dependency of non-prime attribute on any super key should be
removed.

An attribute that is not part of any candidate key is known as non-prime attribute.

Example: Suppose a company wants to store the complete address of each employee, they
create a table named employee_details that looks like this:

emp_id emp_name emp_zip emp_state emp_city emp_district

Super keys: {emp_id}, {emp_id, emp_name}, {emp_id, emp_name, emp_zip}…so on


Candidate Keys: {emp_id}
Non-prime attributes: all attributes except emp_id are non-prime as they are not part of any
candidate keys.
To make this table complies with 3NF we have to break the table into two tables to remove
the transitive dependency:
employee table:
emp_id emp_name emp_zip

employee_zip table:
emp_zip emp_state emp_city emp_district

Boyce-Codd Normal Form (BCNF)

It is an advance version of 3NF that’s why it is also referred as 3.5NF. BCNF is stricter than
3NF. A table complies with BCNF if it is in 3NF and for every functional dependency X->Y,
X should be the super key of the table. Example: Suppose there is a company wherein
employees work in more than one department. They store the data like this:

emp_id emp_nationality emp_dept dept_type dept_no

Functional dependencies in the table above:


emp_id -> emp_nationality emp_dept -> {dept_type, dept_no_of_emp}

Candidate key: {emp_id, emp_dept}


The table is not in BCNF as neither emp_id nor emp_dept alone are keys. To make the table
comply with BCNF we can break the table in three tables like this:

emp_nationality table:

emp_i emp_nationality
d

emp_dept table:

emp_dept dept_type dept_no_of_emp

emp_dept_mapping table:

emp_id emp_dept

Functional dependencies:
emp_id -> emp_nationality, emp_dept -> {dept_type, dept_no_of_emp}

Q2: Explain types of file Organization.


Types of file organization are as follows:

1. Sequential File Organization

This method is the easiest method for file organization. In this method, files are stored
sequentially. This method can be implemented in two ways:

1. Pile File Method:


o It is a quite simple method. In this method, we store the record in a sequence, i.e., one
after another. Here, the record will be inserted in the order in which they are inserted
into tables.
o In case of updating or deleting of any record, the record will be searched in the
memory blocks. When it is found, then it will be marked for deleting, and the new
record is inserted.
Insertion of the new record:

Suppose we have four records R1, R3 and so on upto R9 and R8 in a sequence. Hence,
records are nothing but a row in the table. Suppose we want to insert a new record R2 in the
sequence, then it will be placed at the end of the file. Here, records are nothing but a row in
any table.

2. Sorted File Method:


o In this method, the new record is always inserted at the file's end, and then it will sort
the sequence in ascending or descending order. Sorting of records is based on any
primary key or any other key.
o In the case of modification of any record, it will update the record and then sort the
file, and lastly, the updated record is placed in the right place.

Insertion of the new record:

Suppose there is a preexisting sorted sequence of four records R1, R3 and so on upto R6 and
R7. Suppose a new record R2 has to be inserted in the sequence, then it will be inserted at the
end of the file, and then it will sort the sequence.

2. Heap file organization

o It is the simplest and most basic type of organization. It works with data blocks. In
heap file organization, the records are inserted at the file's end. When the records are
inserted, it doesn't require the sorting and ordering of records.
o When the data block is full, the new record is stored in some other block. This new
data block need not to be the very next data block, but it can select any data block in
the memory to store new records. The heap file is also known as an unordered file.
o In the file, every record has a unique id, and every page in a file is of the same size. It
is the DBMS responsibility to store and manage the new records.

Insertion of a new record

Suppose we have five records R1, R3, R6, R4 and R5 in a heap and suppose we want to insert
a new record R2 in a heap. If the data block 3 is full then it will be inserted in any of the
database selected by the DBMS, let's say data block 1.

If we want to search, update or delete the data in heap file organization, then we need to
traverse the data from staring of the file till we get the requested record.

If the database is very large then searching, updating or deleting of record will be time-
consuming because there is no sorting or ordering of records. In the heap file organization,
we need to check all the data until we get the requested record.

3. Hash File Organization

Hash File Organization uses the computation of hash function on some fields of the records.
The hash function's output determines the location of disk block where the records are to be
placed.
When a record has to be received using the hash key columns, then the address is generated,
and the whole record is retrieved using that address. In the same way, when a new record has
to be inserted, then the address is generated using the hash key and record is directly inserted.
The same process is applied in the case of delete and update.

In this method, there is no effort for searching and sorting the entire file. In this method, each
record will be stored randomly in the memory.

4. Indexed Sequential Access Method (ISAM)

ISAM method is an advanced sequential file organization. In this method, records are stored
in the file using the primary key. An index value is generated for each primary key and
mapped with the record. This index contains the address of the record in the file.
If any record has to be retrieved based on its index value, then the address of the data block is
fetched and the record is retrieved from the memory.

Q3: Storage of Database on Hard Disks.

Short Answer Questions


Q1: Normalization
Normalization is the process of minimizing or eliminates redundancy and undesirable
characteristics like Insertion, Update and Deletion Anamolies from a relation or set of
relations. It is a multi-step process that puts data into tabular form by removing duplicated
data from the relation tables.
Normalization is used for mainly two purposes,
 Eliminating redundant (useless) data.
 Ensuring data dependencies make sense i.e. data is logically stored.

Q2: Functional dependency


A functional dependency (FD) is a relationship between two attributes, typically between the
PK and other non-key attributes within a table. For any relation R, attribute Y is functionally
dependent on attribute X (usually the PK), if for every valid instance of X, that value of X
uniquely determines the value of Y. This relationship is indicated by the representation
below:

X Y

The left side of the above FD diagram is called the determinant, and the right side is the
dependent. Here are a few examples

Unit – 3
Q1: Explain Data Definition Language (DDL) commands with Examples.
Ans:
 DDL or Data Definition Language actually consists of the SQL commands that can be used
to define the database schema. It simply deals with descriptions of the database schema and
is used to create and modify the structure of database objects in the database. These
commands can be used to add, remove or modify tables within a database. DDL has pre-
defined syntax for describing the data.

DDL commands are as follows,


1. CREATE
2. DROP
3. ALTER
4. RENAME
5. TRUNCATE

1. CREATE
CREATE statements is used to define the database structure schema:
Syntax:
CREATE TABLE TABLE_NAME (COLUMN_NAME DATATYPES[,....]);
For example:
Create database university;
Create table students;
Create view for_students;
2. DROP: Drops commands remove tables and databases from RDBMS.
Syntax: DROP TABLE ;

For example:
Drop object_type object_name;
Drop database university;
Drop table student;
3. ALTER: Alters command allows you to alter the structure of the database.
Syntax:
To add a new column in the table
ALTER TABLE table_name ADD column_name COLUMN-definition;
To modify an existing column in the table:
ALTER TABLE MODIFY (COLUMN DEFINITION....);
For example:
Alter table guru99 add subject varchar;
4. RENAME command is used to rename an object.
Syntax:
RENAME TABLE <old_name> TO <new_name>;
Example:
RENAME TABLE emp TO employee;

5. TRUNCATE:
This command used to delete all the rows from the table and free the space containing the
table.
Syntax:
TRUNCATE TABLE table_name;
Example:
TRUNCATE table students;

Q2: Explain Data Manipulation Language (DML).


Ans:
Data Manipulation Language (DML) allows you to modify the database instance by inserting,
modifying, and deleting its data. It is responsible for performing all types of data
modification in a database.
There are three basic constructs which allow database program and user to enter data and
information are:
Here are some important DML commands in SQL:
 INSERT
 UPDATE
 DELETE
INSERT:
This is a statement is a SQL query. This command 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 students (RollNo, FIrstName, LastName) VALUES ('60', 'Tom', Erichsen');
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] [WHERE CONDITION]
For example:
UPDATE students
SET FirstName = 'Jhon', LastName= 'Wick' WHERE StudID = 3;
DELETE:
This command is used to remove one or more rows from a table.
Syntax:
DELETE FROM table_name [WHERE condition];
For example:
DELETE FROM students WHERE FirstName = 'Jhon';

Q3: Explain Joins concept in Structure Query Language


JOINS in SQL are commands which are used to combine rows from two or more
tables, based on a related column between those tables. There are predominantly used when
a user is trying to extract data from tables which have one-to-many or many-to-many
relationships between them.
Employee table Dept table

Equijoins
An equijoin is a join with a join condition containing an equality operator. This is
represented by (=) sign. This join retrieves information by using equality condition.

Query:
SELECT emp_no, emp_name, job_name, dept_name
FROM employee e,dept d
WHERE e.dept_no=d.dept_no;

Non-Equi Join
An nonequi join is an inner join statement that uses an unequal operation (i.e.: <>, >, <, !=,
BETWEEN, etc.) to match rows from different tables.
Query:
SELECT emp_no,emp_name,job_name,dept_name
FROM employee e,dept d
WHERE e.dept_no>d.dept_no;
Self Joins
A self join is such a join in which a table is joined with itself. For example, when you require
details about an employee and his manager (also an employee)
Query:
SELECT a1.emp_no,a2.emp_name,a1.job_name,a2.dept_no
FROM employee a1,employee a2
WHERE a1.emp_no=a2.mgr_id;

Cross Joins
A Cross Join or Cartesian join or Cartesian product is a join of every row of one table to
every row of another table.
Query:

SELECT emp_no,emp_name,job_name,dept_name,location
FROM employee CROSS JOIN dept;

Inner Joins
An inner join is a join that returns rows of the tables that satisfy the join condition.
Query:
SELECT emp_no, emp_name, job_name, dept_name, location
FROM employee INNER JOIN dept USING(dept_no);

Outer Joins
1. Left Outer Join
This left outer join displays all matching records of both table along with the records in left
hand side table of join clause which are not in right hand side table of join clause.
Query:
SELECT emp_no, emp_name, job_name, dept_name, location
FROM employee e LEFT OUTER JOIN dept d
ON(e.dept_no=d.dept_no);
---------------OR ------------
SELECT emp_no,emp_name,job_name,dept_name,location
FROM employee e, dept d
WHERE e.dept_no=d.dept_no(+);

2. Right Outer Join


This right outer join displays all matching records of both tables along with the records in left
hand side table of join clause which are not in right hand side table of join clause.
Query:
ELECT emp_no,emp_name,job_name,dept_name,location
FROM employee e RIGHT OUTER JOIN dept d
ON(e.dept_no=d.dept_no);
-----------OR-------------
SELECT emp_no,emp_name,job_name,dept_name,location
FROM employee e, dept d
WHERE e.dept_no(+)=d.dept_no;

Full Outer Join


A full outer join returns all rows from both the tables left and right side of the join clause,
extended with nulls if they do not satisfy the join condition.
Query:
SELECT emp_no,emp_name,job_name,dept_name,location
FROM employee e
FULL OUTER JOIN dept d ON(e.dept_no=d.dept_no);
Natural Join
A natural join is such a join that compares the common columns of both tables with each
other. It is same as equijoin but the difference is that in natural join, the common attribute
appears only once.

Query:
SELECT emp_no,emp_name,job_name,dept_name,location
FROM employee
NATURAL JOIN dept;

Semijoins
A semi-join is such a join where the EXISTS clause is used with a subquery. It can be called
a semi-join because even if duplicate rows are returned in the subquery, only one set of
matching values in the outer query is returned.

Query:
SELECT * FROM dept a
WHERE EXISTS
(SELECT * FROM employee b
WHERE a.dept_no = b.dept_no);

Q4: Explain views with example.


The dynamic result of one or more relational operations operating on the base relations to
produce another relation. A view is a virtual relation that does not necessarily exist in the
database but can be produced upon request by a particular user, at the time of request.
Create VIEW
Syntax
CREATE VIEW view_name AS
SELECT columns
FROM tables
[WHERE conditions];
Here: view_name - The name of the Oracle VIEW that you wish to create.
WHERE conditions Optional. The conditions that must be met for the records to be included
in the VIEW.
Example
CREATE VIEW sup_orders AS
SELECT suppliers.supplier_id, orders.quantity, orders.price
FROM suppliers INNER JOIN orders ON suppliers.supplier_id = orders.supplier_id
WHERE suppliers.supplier_name = 'Microsoft';

Update VIEW
You can modify the definition of an Oracle VIEW without dropping it by using the Oracle
CREATE OR REPLACE VIEW Statement.
Syntax
The syntax for the CREATE OR REPLACE VIEW Statement in Oracle/PLSQL is:
CREATE OR REPLACE VIEW view_name AS
SELECT columns FROM table WHERE conditions;
Example
CREATE or REPLACE VIEW sup_orders AS
SELECT suppliers.supplier_id, orders.quantity, orders.price
FROM suppliers INNER JOIN orders ON suppliers.supplier_id = orders.supplier_id
WHERE suppliers.supplier_name = 'Apple';

Drop VIEW
Once an Oracle VIEW has been created, you can drop it with the Oracle DROP VIEW
Statement.
Syntax
DROP VIEW view_name;
Example
DROP VIEW sup_orders;

Q5: Explain Nested Queries.


A Sub query or Inner query or a Nested query is a query within another SQL query and
embedded within the WHERE clause.
A sub query is used to return data that will be used in the main query as a condition to further
restrict the data to be retrieved.
Sub queries can be used with the SELECT, INSERT, UPDATE, and DELETE statements
along with the operators like =, <, >, >=, <=, IN, BETWEEN, etc.
There are a few rules that sub queries must follow −

 Sub queries must be enclosed within parentheses.


 A sub query can have only one column in the SELECT clause, unless multiple columns
are in the main query for the sub query to compare its selected columns.
 An ORDER BY command cannot be used in a subquery, although the main query can use
an ORDER BY. The GROUP BY command can be used to perform the same function as
the ORDER BY in a subquery.
 Sub queries that return more than one row can only be used with multiple value operators
such as the IN operator.
 The SELECT list cannot include any references to values that evaluate to a BLOB,
ARRAY, CLOB, or NCLOB.
 A sub query cannot be immediately enclosed in a set function.
 The BETWEEN operator cannot be used with a subquery. However, the BETWEEN
operator can be used within the sub query.

Sub queries with the SELECT Statement


Sub queries are most frequently used with the SELECT statement. The basic syntax is as
follows −
SELECT column_name [, column_name ]
FROM table1 [, table2 ]
WHERE column_name OPERATOR
(SELECT column_name , [column_name ]
FROM table1, [ table2 ]
[WHERE]);
Example
Consider the CUSTOMERS table having the following records −

Now, let us check the following subquery with a SELECT statement.


SQL> SELECT * FROM CUSTOMERS WHERE ID IN (SELECT ID FROM
CUSTOMERS WHERE SALARY > 4500) ;

This would produce the following result.


Short Answer Questions:
Q1.SQL
SQL (pronounced "ess-que-el") stands for Structured Query Language. SQL is used to
communicate with a database. According to ANSI (American National Standards Institute), it
is the standard language for relational database management systems. SQL statements are
used to perform tasks such as update data on a database, or retrieve data from a database.
Some common relational database management systems that use SQL are: Oracle, Sybase,
Microsoft SQL Server, Access, Ingres, etc. Although most database systems use SQL, most
of them also have their own additional proprietary extensions that are usually only used on
their system. However, the standard SQL commands such as "Select", "Insert", "Update",
"Delete", "Create", and "Drop" can be used to accomplish almost everything that one needs to
do with a database. This tutorial will provide you with the instruction on the basics of each of
these commands as well as allow you to put them to practice using the SQL Interpreter.

Q2.Nested Query
A Sub query or Inner query or a Nested query is a query within another SQL query and
embedded within the WHERE clause.
A sub query is used to return data that will be used in the main query as a condition to further
restrict the data to be retrieved.
Sub queries can be used with the SELECT, INSERT, UPDATE, and DELETE statements
along with the operators like =, <, >, >=, <=, IN, BETWEEN, etc.

Q3.Join
JOINS in SQL are commands which are used to combine rows from two or more tables,
based on a related column between those tables. There are predominantly used when a user
is trying to extract data from tables which have one-to-many or many-to-many relationships
between them.
Unit – 4

Q1: Explain two phase locking protocol


The two-phase locking protocol is used to ensure the serializability in database.
There are two phases of 2PL:
Growing phase: In the growing phase, a new lock on the data item may be acquired by the
transaction, but none can be released.
Shrinking phase: In the shrinking phase, existing lock held by the transaction may be
released, but no new locks can be acquired.

In the below example, if lock conversion is allowed then the following phase can happen:
1. Upgrading of lock (from S(a) to X (a)) is allowed in growing phase.
2. Downgrading of lock (from X(a) to S(a)) must be done in shrinking phase.

Example:
The following way shows how unlocking and locking work with 2-PL.
Transaction T1:
o Growing phase: from step 1-3
o Shrinking phase: from step 5-7
o Lock point: at 3
Transaction T2:
o Growing phase: from step 2-6
o Shrinking phase: from step 8-9
o Lock point: at 6

Q2: Explain Optimistic Concurrency Control.


• Concurrency control is a concept that is used to address conflicts with the
simultaneous accessing or altering of data that can occur with a multi-user system.
• Optimistic concurrency control (OCC) is a concurrency control method applied to
transactional systems. OCC assumes that multiple transactions can frequently
complete without interfering with each other. While running, transactions use data
resources without acquiring locks on those resources.
• Before committing, each transaction verifies that no other transaction has R/W the
data it has R/W. If the check reveals conflicting modifications, the committing
transaction rolls back and can be restarted.
Transactions consist of three phases:
• Read Phase: Resources can be read freely. All writes take place on local copies of the
object to be modified i.e. a local updated copy is created.
• Validations Phase: The step in which it is determined that the transaction will not
cause a loss of integrity. i.e. if any R-W or W-R anomaly occurs
• Write Phase: Copies are made global, if the data is consistent the file is updated.
Validation Rules:
Advantages:
• The waiting time to Read a resource is very low.
• Deadlocks can be very easily recovered(by validation phase).
• Read-only transactions can run concurrently with updating transactions without loss
of database consistency.
• Never lead to cascaded aborts.
Disadvantages
• Can lead to starvation of process that want to alter the contents of a resource.
• Aborting the long transactions in validation phase wastes a lot of system resources.
• Since one transaction cant access resource of other ones, it limits concurrency when
write function is involved.

Q3: Explain database security and Authentication.

Q4: Explain backup and recovery techniques.


Q5: Explain deadlock and its prevention

Short Answer Questions:


Q1:Dead Lock
Q2:Database Error
Q3:Database Recovery
Q4:Concurrent Transaction
Unit – 5
Explain the advantages and disadvantages of DDBMS.
Explain need for Client Server Computing.
Explain the structure of Client Server System and its Advantages and Disadvantages.
Client Server System. (Short)

You might also like