You are on page 1of 16

DBMS:-

Q.1 What is DBMS ? Mention advantages..?


Ans:-A Database Management System (DBMS) is characterized as the software
framework that permits users to indicate, create, maintain and control access to the
data set. The DBMS allows an end-user to create, read, update and erase required
data in the dataset. DBMS works like a layer between the programs and data.

Advantages of Database Management System:-

1. Data Integrity
Data integrity means data is consistent and accurate in the database. It is essential
as there are multiple databases in DBMS. All these databases contain data which is
visible to multiple users. Therefore, it is essential to ensure that data is consistent
and correct in all databases for all users.

2. Data Security
Data security is a vital concept in a database. Only users authorized must be
allowed to access the database and their identity must be authenticated using
username and password. Unauthorized users shouldn’t be allowed to access the
database under any circumstances as it violets the integrity constraints.

A DBMS provides a better platform for data privacy thus helping companies to
offer an improved data security.

3. Better data integration


Due to the database management system, we have access to well managed and
synchronized form of data making it easy to handle. It also gives an integrated
view of how a particular organization is working and keeps track of how one
segment of the company affects another segment.

4. Minimized Data Inconsistency


Data inconsistency occurs between files when various versions of the same data
appear in different places. Data consistency is ensured in the database; there is no
data redundancy. Besides, any database changes are immediately reflected by all
users, and there is no data inconsistency.

5. Faster Data Access


The database management system helps the users to produce quick answers to
queries making data accessing accurate and faster.

6. Simplicity
DBMS allows us to understand data better with a clear and simple logical view.
With dbms, many operations like deletion, insertion or creation of file or data, are
easy to implement.

7. Recovery and Backup


DBMS automatically takes care of recovery and backup. The users are not required
to take periodical backup as this is taken care of by DBMS. Besides, it also restores
a database after a system failure or crash to prevent its previous condition.

8. Increased end-user productivity


The available data transform into helpful information with the help of combination
tools. It helps end users make better, informative and quick decisions that can
make the difference between success and failure in the global economy.

Q.2 What is Database?


Ans: A database is an organized collection of data, so that it can be easily accessed
and managed.
You can organize data into tables, rows, columns, and index it to make it easier to
find relevant information.
Database handlers create a database in such a way that only one set of software
program provides access of data to all the users.

The main purpose of the database is to operate a large amount of information by


storing, retrieving, and managing data.

There are many dynamic websites on the World Wide Web nowadays which are
handled through databases. For example, a model that checks the availability of
rooms in a hotel. It is an example of a dynamic website that uses a database.

There are many databases available like MySQL, Sybase, Oracle, MongoDB,
Informix, PostgreSQL, SQL Server, etc.

Modern databases are managed by the database management system (DBMS).


SQL or Structured Query Language is used to operate on the data stored in a
database. SQL depends on relational algebra and tuple relational calculus.

Q.3 What is RDBMS ? Mention its Properties?


Ans:- A relational database refers to a database that stores data in a structured
format, using rows and columns. This makes it easy to locate and access specific
values within the database. It is "relational" because the values within each table
are related to each other. Tables may also be related to other tables. The relational
structure makes it possible to run queries across multiple tables at once.

Relational databases have the following properties:

• Values are atomic.


• All of the values in a column have the same data type.
• Each row is unique.
• The sequence of columns is insignificant.
• The sequence of rows is insignificant.
• Each column has a unique name.
• Integrity constraints maintain data consistency across multiple tables.

Q.4 What are the different types of database languages?


Ans: Database languages can be used to read, store and update the data in the
database.

1. Data Definition Language


DDL stands for Data Definition Language. It is used to define database structure or
pattern.
It is used to create schema, tables, indexes, constraints, etc. in the database.
Using the DDL statements, you can create the skeleton of the database.
Data definition language is used to store the information of metadata like the
number of tables and schemas, their names, indexes, columns in each table,
constraints, etc.
Here are some tasks that come under DDL:

Create: It is used to create objects in the database.


Alter: It is used to alter the structure of the database.
Drop: It is used to delete objects from the database.
Truncate: It is used to remove all records from a table.
Rename: It is used to rename an object.
Comment: It is used to comment on the data dictionary.

2. Data Manipulation Language


DML stands for Data Manipulation Language. It is used for accessing and
manipulating data in a database. It handles user requests.

Here are some tasks that come under DML:

Select: It is used to retrieve data from a database.


Insert: It is used to insert data into a table.
Update: It is used to update existing data within a table.
Delete: It is used to delete all records from a table.
Merge: It performs UPSERT operation, i.e., insert or update operations.
Call: It is used to call a structured query language or a Java subprogram.
Explain Plan: It has the parameter of explaining data.
Lock Table: It controls concurrency.

3. Data Control Language


DCL stands for Data Control Language. It is used to retrieve the stored or saved
data.
The DCL execution is transactional. It also has rollback parameters.
(But in Oracle database, the execution of data control language does not have the
feature of rolling back.)

Here are some tasks that come under DCL:

Grant: It is used to give user access privileges to a database.


Revoke: It is used to take back permissions from the user.

There are the following operations which have the authorization of Revoke:
CONNECT, INSERT, USAGE, EXECUTE, DELETE, UPDATE and SELECT.

4. Transaction Control Language


TCL is used to run the changes made by the DML statement. TCL can be grouped
into a logical transaction.

Here are some tasks that come under TCL:

Commit: It is used to save the transaction on the database.


Rollback: It is used to restore the database to original since the last Commit.

Q.5 What are ACID properties (VVVVV IMP)?


Ans:-ACID Properties
For maintaining the integrity of data in the database the certain properties are
followed by all the transactions that take place in the database. These properties are
popularly known as ACID properties where A is for Atomicity, C for Consistency,
I for Isolation and D for Durability.

Atomicity
This property states that the transaction should either occur completely or doesn't
occur at all. The transaction should not occur partially. Each transaction is treated
as a unit and the execution is completed else the transaction is aborted. If any
transaction is aborted all the changes made are reversed back. If the transaction
occurs completely then only it is committed.

Example: Suppose there are two accounts A and B having a balance of Rs 1000
and Rs 500 respectively. Now, if you have to transfer Rs 200 from Account A to
Account B then this transaction involves two operations. First, debiting Rs 200
from Account A and second, crediting Rs 200 to Account B.
Now, let's consider a situation where the first operation has occurred successfully
i.e. Rs 200 was debited from Account A and the balance in Account A is now Rs
800. But, the second transaction failed. So, the Rs 200 was not added to Account
B. This can lead to inconsistency in the database. So, either the transaction should
fail or both the operations should occur if the transaction has to be successful. The
atomicity thus helps in ensuring the correctness of the database.

Consistency
This property ensures that the integrity of the database is maintained before and
after the transaction. It ensures that when any transaction is executed then the
database should move from one consistent state to another consistent state.

Example: In the above example, Account A and Account B have Rs 1000 and Rs
500 respectively. So, the total amount is Rs 1000+ Rs 500 i.e. Rs 1500 before the
transaction. When any transaction is executed then the total amount should also be
Rs 1500. If the transaction occurs then Rs 200 will be deducted from Account A
and added to Account B. So, the total amount after the transaction will Rs 800 + Rs
700 i.e. Rs 1500. So, this property ensures the consistency of the database. If any
operation in the transaction fails it will produce inconsistency in the data.

Isolation
This property tells that each transaction is executed in the system such that it is the
only transaction in the system. If more than one transaction is taking place in
parallel, then the occurrence of one transaction will not affect the other transaction.
If any transaction is using a data item then it can’t be used by other transactions
until the first transaction ends.

Durability
This property ensures that once the changes are made in the database these changes
persist in the database even if any system failure occurs. These changes are saved
permanently in the non-volatile memory. It is the responsibility of the recovery
manager to ensure the durability in the database.

Q.7 Difference between vertical and horizontal scaling?


Ans:- Horizontal Scaling (scaling out): In a database world, horizontal scaling is
usually based on the partitioning of data (each node only contains part of the data).
Examples:-Cassandra, MongoDB, Google Cloud Spanner...
Vertical Scaling (scaling up):In vertical scaling, the data lives on a single node
and scaling is done through multi-core, e.g. spreading the load between the CPU
and RAM resources of the machine.
Examples:-MySQL, Amazon RDS

Q.8 What are Keys in DBMS Explain?


Ans: Keys:-A key in DBMS is an attribute or a set of attributes that help to
uniquely identify a tuple (or row) in a relation (or table). Keys are also used to
establish relationships between the different tables and columns of a relational
database. Individual values in a key are called key values.

Types of Keys in DBMS:-


There are broadly seven types of keys in DBMS:

Primary Key
Candidate Key
Super Key
Foreign Key
Composite Key
Alternate Key
Unique Key

Primary Key:- A primary key is a column of a table or a set of columns that helps
to identify every record present in that table uniquely. There can be only one
primary Key in a table. Also, the primary Key cannot have the same values
repeating for any row. Every value of the primary key has to be different with no
repetitions.

The PRIMARY KEY (PK) constraint put on a column or set of columns will not
allow them to have any null values or any duplicates. One table can have only one
primary key constraint. Any value in the primary key cannot be changed by any
foreign keys which refer to it.

Candidate Key:-Candidate keys are those attributes that uniquely identify rows of
a table. The Primary Key of a table is selected from one of the candidate keys. So,
candidate keys have the same properties as the primary keys explained above.
There can be more than one candidate keys in a table.

Super Key:- Super Key is the set of all the keys which help to identify rows in a
table uniquely. This means that all those columns of a table that are capable of
identifying the other columns of that table uniquely will all be considered super
keys.

Super Key is the superset of a candidate key. The Primary Key of a table is picked
from the super key set to be made the table’s identity attribute.

Alternate Key:-As stated above, a table can have multiple choices for a primary
key; however, it can choose only one. So, all the keys which did not become the
primary Key are called alternate keys.

Foreign Key:-Foreign Key is used to establish relationships between two tables. A


foreign key will require each value in a column or set of columns to match the
Primary Key of the referential table. Foreign keys help to maintain data and
referential integrity.

Composite Key:-Composite Key is a set of two or more attributes that help


identify each tuple in a table uniquely. The attributes in the set may not be unique
when considered separately. However, when taken all together, they will ensure
uniqueness.

Unique Key:-Unique Key is a column or set of columns that uniquely identify


each record in a table. All values will have to be unique in this Key. A unique Key
differs from a primary key because it can have only one null value, whereas a
primary Key cannot have any null values.
Q.9 Types of relationship in DBMS?
Ans:-We have two entity types of 'Customer'(Customer_id, Name, City, Phone)
and 'Account'(Account_no, Type, Balance). We store the data of 'Customer' in one
table and his accounts details in the 'Account' table. Now, to link these two tables
we need to insert the primary key 'Customer_id' of the 'Customer' table in the
'Account' table. This key acts as a foreign key for the 'Account' table and refers to a
column with the same name in the 'Customer' table. This is how a relationship
between two tables is established. There are three types of relationships that can
exist between two entities.

One-to-One Relationship
One-to-Many or Many-to-One Relationship
Many-to-Many Relationship

One-to-One Relationship:-
Such a relationship exists when each record of one table is related to only one
record of the other table.

For example:- If there are two entities ‘Person’ (Id, Name, Age, Address)and
‘Passport’(Passport_id, Passport_no). So, each person can have only one passport
and each passport belongs to only one person.

One-to-Many or Many-to-One Relationship:-


Such a relationship exists when each record of one table can be related to one or
more than one record of the other table. This relationship is the most common
relationship found. A one-to-many relationship can also be said as a many-to-one
relationship depending upon the way we view it.

For example:- If there are two entity type ‘Customer’ and ‘Account’ then each
‘Customer’ can have more than one ‘Account’ but each ‘Account’ is held by only
one ‘Customer’. In this example, we can say that each Customer is associated with
many Account. So, it is a one-to-many relationship. But, if we see it the other way
i.e many Account is associated with one Customer then we can say that it is a
many-to-one relationship.

Many-to-Many Relationship:-
Such a relationship exists when each record of the first table can be related to one
or more than one record of the second table and a single record of the second table
can be related to one or more than one record of the first table. A many-to-many
relationship can be seen as a two one-to-many relationship which is linked by a
'linking table' or 'associate table'. The linking table links two tables by having
fields which are the primary key of the other two tables. We can understand this
with the following example.

Example:- If there are two entity type ‘Customer’ and ‘Product’ then each
customer can buy more than one product and a product can be bought by many
different customers.

Q.10 What is Data abstraction in DBMS, define three levels of it?


Ans:- Data Abstraction
Data Abstraction refers to the process of hiding irrelevant details from the user. So,
what is the meaning of irrelevant details? Let's understand this with one example.
Example: If we want to access any mail from our Gmail then we don't know where
that data is physically stored i.e is the data present in India or USA or what data
model has been used to store that data? We are not concerned about these things.
We are only concerned with our email. So, information like these i.e. location of
data and data models are irrelevant to us and in data abstraction, we do this only.
Apart from the location of data and data models, there are other factors that we
don't care of. We hide the unnecessary data from the user and this process of
hiding unwanted data is called Data Abstraction.
There are mainly three levels of data abstraction and we divide it into three levels
in order to achieve Data Independence. Data Independence means users and data
should not directly interact with each other. The user should be at a different level
and the data should be present at some other level. By doing so, Data
Independence can be achieved. So, let's see in details what are these three levels of
data abstraction:

View Level
Conceptual Level
Physical Level

View Level or External Schema:-


This level tells the application about how the data should be shown to the user.
Example: If we have a login-id and password in a university system, then as a
student, we can view our marks, attendance, fee structure, etc. But the faculty of
the university will have a different view. He will have options like salary, edit
marks of a student, enter attendance of the students, etc. So, both the student and
the faculty have a different view. By doing so, the security of the system also
increases. In this example, the student can't edit his marks but the faculty who is
authorized to edit the marks can edit the student's marks. Similarly, the dean of the
college or university will have some more authorization and accordingly, he will
has his view. So, different users will have a different view according to the
authorization they have.

Conceptual Level or Logical Level:-


This level tells how the data is actually stored and structured. We have different
data models by which we can store the data(You can read more about the different
types of data model from here). Example: Let us take an example where we use the
relational model for storing the data. We have to store the data of a student, the
columns in the student table will be student_name, age, mail_id, roll_no etc. We
have to define all these at this level while we are creating the database. Though the
data is stored in the database but the structure of the tables like the student table,
teacher table, books table, etc are defined here in the conceptual level or logical
level. Also, how the tables are related to each other are defined here. Overall, we
can say that we are creating a blueprint of the data at the conceptual level.

Physical Level or Internal Schema:-


As the name suggests, the Physical level tells us that where the data is actually
stored i.e. it tells the actual location of the data that is being stored by the user. The
Database Administrators(DBA) decide that which data should be kept at which
particular disk drive, how the data has to be fragmented, where it has to be stored
etc. They decide if the data has to be centralized or distributed. Though we see the
data in the form of tables at view level the data here is actually stored in the form
of files only. It totally depends on the DBA, how he/she manages the database at
the physical level.

Q.11 Indexing in DBMS?


Ans:-Indexing is a data structure technique to efficiently retrieve records from the
database files based on some attributes on which the indexing has been done.
Indexing can be of the following types −

Primary Index − Primary index is defined on an ordered data file. The data file is
ordered on a key field. The key field is generally the primary key of the relation.

Secondary Index − Secondary index may be generated from a field which is a


candidate key and has a unique value in every record, or a non-key with duplicate
values.

Clustering Index − Clustering index is defined on an ordered data file. The data
file is ordered on a non-key field.
Q.12 What is Normalization? Types of them ..?
Ans:-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. Normalization divides the larger table into the
smaller table and links them using relationship.

First Normal Form:-


First Normal Form is defined in the definition of relations (tables) itself. This rule
defines that all the attributes in a relation must have atomic domains. The values in
an atomic domain are indivisible units.

We re-arrange the relation (table) as below, to convert it to First Normal Form.

Second Normal Form:


Before we learn about the second normal form, we need to understand the
following −

Prime attribute − An attribute, which is a part of the candidate-key, is known as a


prime attribute.

Non-prime attribute − An attribute, which is not a part of the prime-key, is said to


be a non-prime attribute.

If we follow second normal form, then every non-prime attribute should be fully
functionally dependent on prime key attribute. That is, if X → A holds, then there
should not be any proper subset Y of X, for which Y → A also holds true.
We see here in Student_Project relation that the prime key attributes are Stu_ID
and Proj_ID. According to the rule, non-key attributes, i.e. Stu_Name and
Proj_Name must be dependent upon both and not on any of the prime key attribute
individually. But we find that Stu_Name can be identified by Stu_ID and
Proj_Name can be identified by Proj_ID independently. This is called partial
dependency, which is not allowed in Second Normal Form.

We broke the relation in two as depicted in the above picture. So there exists no
partial dependency.

Third Normal Form:-


For a relation to be in Third Normal Form, it must be in Second Normal form and
the following must satisfy −

No non-prime attribute is transitively dependent on prime key attribute.


For any non-trivial functional dependency, X → A, then either −
X is a superkey or,
A is prime attribute.

We find that in the above Student_detail relation, Stu_ID is the key and only prime
key attribute. We find that City can be identified by Stu_ID as well as Zip itself.
Neither Zip is a superkey nor is City a prime attribute. Additionally, Stu_ID → Zip
→ City, so there exists transitive dependency.

To bring this relation into third normal form, we break the relation into two
relations as follows −

Boyce-Codd Normal Form:-


Boyce-Codd Normal Form (BCNF) is an extension of Third Normal Form on strict
terms. BCNF states that −

For any non-trivial functional dependency, X → A, X must be a super-key.


In the above image, Stu_ID is the super-key in the relation Student_Detail and Zip is
the super-key in the relation ZipCodes. So,

Stu_ID → Stu_Name, Zip

and

Zip → City

Which confirms that both the relations are in BCNF.

Q.13 What is Denormalization?


Ans:-Denormalization
Denormalization is a database optimization technique where we add redundant
data in the database to get rid of the complex join operations. This is done to speed
up database access speed. Denormalization is done after normalization for
improving the performance of the database. The data from one table is included in
another table to reduce the number of joins in the query and hence helps in
speeding up the performance.
Note:-A denormalized database should never be confused by a database that has
never been normalized.

Example: Suppose after normalization we have two tables first, Student table and
second, Branch table. The student has the attributes as Roll_no, Student-name,
Age, and Branch_id.

The branch table is related to the Student table with Branch_id as the foreign key
in the Student table.

If we want the name of students along with the name of the branch name then we
need to perform a join operation. The problem here is that if the table is large we
need a lot of time to perform the join operations. So, we can add the data of
Branch_name from Branch table to the Student table and this will help in reducing
the time that would have been used in join operation and thus optimize the
database.

You might also like