RDBMS - IMP Questions
RDBMS - IMP Questions
Unit – 1
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.
This external data is cleaned up and transformed to fit the desired format so that it can be
imported into a central repository.
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.
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
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.
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.
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.
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.
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.
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.
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
Note: An attribute that is not part of any candidate key is known as non-key attribute.
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:
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:
employee_zip table:
emp_zip emp_state emp_city emp_district
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_nationality table:
emp_i emp_nationality
d
emp_dept table:
emp_dept_mapping table:
emp_id emp_dept
Functional dependencies:
emp_id -> emp_nationality, emp_dept -> {dept_type, dept_no_of_emp}
This method is the easiest method for file organization. In this method, files are stored
sequentially. This method can be implemented in two ways:
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.
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.
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.
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.
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.
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.
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.
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;
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(+);
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);
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;
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
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