0% found this document useful (0 votes)
41 views8 pages

BICTE Dbms Solution

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)
41 views8 pages

BICTE Dbms Solution

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/ 8

BICTE:DBMS:4rth Semester

Sample questions Solution


1. What is transaction? Explain the desirable properties of transaction.
A transaction is a set of logically related operations.
In order to maintain consistency in a database, before and after the transaction, certain
properties are followed, called ACID properties. The desirable properties of transaction
are:

Atomicity:
• By this, we mean that either the entire transaction takes place at once or doesn’t happen at
all. Or It states that all operations of the transaction take place at once if not, the
transaction is aborted.
• Atomicity involves the following two operations:
Abort: If a transaction aborts then all the changes made are not visible.
Commit: If a transaction commits then all the changes made are visible.

Consistency:
• This means that integrity constraints must be maintained so that the database is consistent
before and after the transaction. It refers to the correctness of a database.
Or
Before the transaction starts and after a transaction ends, the sum of money must be equal in both
states.
Isolation:
• This property ensures that multiple transactions can occur simultaneously without causing
any inconsistency. Or
• It shows that the data which is used at the time of execution of a transaction cannot be used
by the second transaction until the first one is completed.
• Durability:
• It means once the transaction is done, and updated in the database it is not going to change
except the user changes or deletes the transaction. Durable means here the transaction is
once done and saved in a database in a hardware form as a permanent change. Committed
data would never be lost, even in hardware failure. It is actually a backup of the database
2. What is Normalization? What are the importance of Normalization? Explain 1NF, 2NF and
3NF with example.
Normalization is the process of organizing the data in the database. Or Normalization is
used to minimize the redundancy from a relation or set of relations. It is also used to
eliminate the undesirable characteristics like Insertion, Update and Deletion Anomalies.
The importance of Normalization are:
✓ It eliminates redundant data.
✓ It reduces chances of data error.
✓ It allows database to take up less disk space.
✓ It also help in increasing the performance.
✓ It improves the data integrity and consistency.
1NF:
A relation will be 1NF if it contains an atomic value. It states that an attribute of a table
cannot hold multiple values. It must hold only single-valued attribute.
For example: Consider relation Employee
Eid Ename Ephone Ecity

101 Pop 9852022222, Brt


9842033333
102 Bob 9842029390 Brt

103 Rose 9842021212 Ktm


Here, Relation EMPLOYEE is not in 1NF because of multi-valued attribute Ephone
The decomposition of the EMPLOYEE table into 1NF has been shown below:
Eid Ename Ephone Ecity

101 Pop 9852022222 Brt

101 Pop 9842033333 Brt

102 Parwat 9842029390 Brt

103 Rose 9842021212 Ktm

Fig: Employee Table in 1NF

2NF:

In the 2NF, relational must be in 1NF. In the second normal form, all non-key attributes are
fully functional dependent on the primary key
Example: Let's assume, MMAM College can store the data of teachers and the subjects
they teach. In a college, a teacher can teach more than one subject

Teacher_Id Subject Age

101 C-programming 35

101 Networking 35

102 English 34

103 DBMS 45

103 FIT 45
To convert the given table into 2NF, we decompose it into two tables:

Teacher detail table


Teacher_Id Subject

101 C-programming

101 Networking

102 English

103 DBMS

103 FIT

Teacher Subject table


Teacher_Id Age

101 35

102 34

103 45

✓ 3NF
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. Or No non-prime attribute is transitively dependent on the
primary key
Example: Suppose a company wants to store the complete address of each employee,
they create a table named employee_details that looks like this
eid ename ezip estate ecity edistrict
1001 Jhon 121 UP Agra D1
1002 Adam 122 UP Agra D2
1003 Alex 123 TN Chennai C1
1004 Peter 345 UK Pauri P1
1005 Pop 567 P1 Brt M1

Here, estate, ecity & edistrict dependent on ezip. And, ezip is dependent on eid that makes
non-prime attributes (estate, ecity & edistrict) transitively dependent on super key
(eid). This violates the rule of 3NF.
Now, to make this table complies with 3NF we have to break the table into two tables to
remove the transitive dependency
Fig: Employee table

Eid ename ezip


1001 Jhon 121
1002 Adam 122
1003 Alex 123
1004 Peter 345
1005 Pop 567

ezip estate ecity Edistrict


121 UP Agra D1
122 UP Agra D2
123 TN Chennai C1
345 UK Pauri P1
567 P1 Brt M1

Fig: Employee Zip table


3. Define DDL and DML language. Explain the Insert , update and delete statement with
suitable example.
SQL commands are instructions that are used to communicate with the database. SQL
statements are divided into two major categories:
▪ Data definition language (DDL) and
▪ Data manipulation language (DML).
▪ DDL:
▪ DDL statements are used to build and modify the structure of your tables and other
objects in the database. When you execute a DDL statement, it takes effect
immediately.
▪ DDL statements are used to define the database structure or schema. Some
examples:
▪ CREATE - to create objects in the database
▪ ALTER - alters the structure of the database
▪ DROP - delete objects from the database
▪ RENAME - rename an object
▪ DML:
▪ DML statements are used to work with the data in tables. The Data Manipulation
Language (DML) is used to retrieve, insert and modify database information. DML
statements are used for managing data within schema objects. Some examples:
▪ SELECT - retrieve data from the database
▪ INSERT - insert data into a table
▪ UPDATE - updates existing data within a table
▪ DELETE - deletes all records from a table

INSERT Statement: This command is used to insert the data in a table.


Syntax:
✓ Example:
INSERT INTO tablename
INSERT INTO employee
values (value1, value2…….);
values(‘ram’, ‘rai’, ‘Brt’, ‘Nepal’);
▪ UPDATE Statement: The UPDATE statement is used to update existing records in a table.
Syntax:

UPDATE table-name
SET column-name = value where condition;
✓ UPDATE emp
✓ Example: set salary=salary+(salary*10/100);
UPDATE student
set Sname='Abhi',Age=19
where Sid=103

▪ DELETE Statement: The DELETE statement is used to delete rows or records in a table.
You can use WHERE clause with DELETE query to delete selected rows, otherwise all the
records would be deleted
▪ Syntax:
DELETE FROM table_name
WHERE [condition];
Example:
DELETE FROM employee
WHERE eID = 101;

Compiled by :
LB Gurung
[email protected]

You might also like