0% found this document useful (0 votes)
35 views

Viva Questions

Uploaded by

Avinav Doonga
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)
35 views

Viva Questions

Uploaded by

Avinav Doonga
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/ 18

Viva Practice Questions

1. What is a database?

A database is a structured collection of data for faster and better access, storage, and
manipulation of data. A database can also be defined as a collection of tables, schema, views,
and other database objects.

2. What is SQL?
Ans. SQL stands for Structured Query Language, It is a language used for creating, storing,
fetching, and updating data and database objects in RDBMS.

3. What are the different types of SQL commands?


Ans. SQL commands are the set of commands used to communicate and manage the data present
in the database. The different type of SQL commands are-

DDL – Data Definition Language

DML – Data Manipulation Language

DCL – Data Control Language

TCL – Transactional Control Language

4. Explain DDL commands. What are the different DDL commands in SQL?
Ans. DDL refers to Data Definition Language. The DDL commands are used to define or alter
the structure of the database. The different DDL commands are-

CREATE – Used to create a table in the DB

DROP – Drops the table from the DB

ALTER – Alters the structure of the DB

TRUNCATE – Deletes all the records from the DB but not its database structure

RENAME – Renames a DB object

5. Explain DML commands. What are the different DML commands in SQL?
Ans. DML refers to Data Manipulation Language. These commands are used for managing data
present in the database. Some of the DML commands are – select, insert, update, delete, etc.

6. Explain DCL commands. What are the different DCL commands in SQL?
Ans. DCL refers to Data Control Language. These commands are used to create roles, grant
permission, and control access to the database objects. The three DCL commands are-

GRANT – Grants permission to a database user.

REVOKE – Removes access privileges from a user-provided with the GRANT command.

7. What are SQL constraints?


Ans. SQL constraints are the set of rules that impose some restrictions while inserting, deleting,
or updating the data in the databases. In SQL, we have both column level as well as table level
constraints which are applied at columns and tables respectively. Some of the constraints in SQL
are – Primary Key, Foreign Key, Unique Key, Not NULL, DEFAULT, CHECK, and Index
constraint.

8. What is a Unique constraint?


Ans. A unique constraint is used to ensure that a field or column will have only a unique value
(no duplication).

9. What is a Primary Key?


Ans. A primary key is a column or a combination of columns that uniquely identifies a record in
the database. A primary key can only have unique and not NULL values and there can be only
one primary key in a table.

10. What is the difference between a unique key and a primary key?
Ans. A unique key allows null value (although only one) but a primary key doesn’t allow null
values. A table can have more than one unique keys columns while there can be only one
primary key.

11. What is a composite key?


Ans. A composite key is a primary key with multiple columns as in the case of some tables a
single field might not guarantee unique and not null values. So a combination of multiple fields
is taken as the primary key.

12. What is a NULL value?


Ans. A NULL value in SQL is an unknown or blank value. Since NULL is an unknown value so
the NULL value cannot be compared with another NULL value. Hence we cannot use the ‘=’
operator in where condition with NULL. For this, we have an IS NULL clause that checks if the
value in the field is NULL or not.

13. What is a Not NULL constraint?


Ans. A Not NULL constraint is used for ensuring that the value in the field cannot be NULL.

14. What is a Foreign Key?


Ans. A foreign key is used for enforcing referential integrity in which a field marked as a foreign
key in one table is linked with a primary key of another table. With this referential integrity, we
can have only the data in the foreign key which matches the data in the primary key of the other
table.

15. What is a Default constraint?


Ans. A Default constraint is used for providing a default value to a column when no value is
supplied at the time of insertion of record in the database.

16. What are the different types of joins in SQL?


Ans. Joins are used to combine records from multiple tables. The different types of joins in SQL
are-

Inner Join – To fetch rows from two tables having matching data in the specified columns of
both the tables.
SELECT * FROM TABLE1 INNER JOIN TABLE2 ON TABLE1.columnA =
TABLE2.columnA;

Left Join – To fetch all rows from the left table and matching rows of the right table
SELECT * FROM TABLE1 LEFT JOIN TABLE2 ON TABLE1.columnA =
TABLE2.columnA;

Right Join – To fetch all rows from right table and matching rows of the left table
SELECT * FROM TABLE1 RIGHT JOIN TABLE2 ON TABLE1.columnA =
TABLE2.columnA;

Full Outer Join – To fetch all rows of the left table and all rows of right table
SELECT * FROM TABLE1 FULL OUTER JOIN TABLE2 ON TABLE1.columnA =
TABLE2.columnA;

Self Join – Joining a table to itself, for referencing its own data
SELECT * FROM TABLE1 T1, TABLE1 T2 WHERE T1.columnA = T2.columnB;

17. What is the difference between cross join and full outer join?
Ans. A cross join returns the cartesian product of the two tables. So there is no condition or on
clause as each row of TabelA is joined with each row of TableB whereas a full outer join will
join the two tables on the basis of the condition specified in the on clause and for the records not
satisfying the condition null value is placed in the join result.

18. What is the difference between where and having clause?


Ans. This is one of the commonly asked DBMS interview questions in which the interviewer
wants to check your knowledge of the ‘where’ and ‘having’ clause along with their usage.
A ‘where’ clause is used to fetch data from the database that specifies particular criteria
(specified after the where clause). Whereas a ‘having’ clause is used along with ‘GROUP BY’ to
fetch data that meets particular criteria specified by the aggregate function.

For example – for a table with Employee and Project fields. If we want to fetch Employee
working on a particular project P2, we will use ‘where’ clause-

Select Employee

From Emp_Project

where Project = P2;

Now if we want to fetch Employees who are working on more than one project. We will first
have to group the Employee column along with the count of the project and then the ‘having’
clause can be used to fetch relevant records-

Select Employee

From Emp_Project

GROUP BY Employee

Having count(Project)>1;

What is a View in SQL?


Ans. A view is a virtual table. It is a named set of SQL statements that can be later referenced
and used as a table.

What is Database Normalisation?


Ans. Database normalization is the process of organization of data in order to reduce the
redundancy and anomalies in the database. We have different Normalisation forms in SQL like –
First Normal Form, Second Normal Form, Third Normal Form, and BCNF.

Explain the First Normal Form(1NF).


Ans. According to First Normal Form, a column cannot have multiple values. Each value in the
columns must be atomic.

Explain second normal form?

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
Explain the Third Normal Form(3NF).
Ans. For a table to be Third Normal Form, it must follow 2NF and each non-prime attribute must
be dependent on the primary key of the table.

For each functional dependency X -> Y either-


X should be the super key or Y should be the prime attribute (part of one of the candidate keys)
of the table.

What are the aggregate functions in SQL?


Ans. Aggregate functions are SQL functions that return a single value calculated from multiple
values of columns. Some of the aggregate functions in SQL are-

Count() – Returns the count of the number of rows returned by the SQL expression

Max() – Returns the max value out of the total values

Min() – Returns the min value out of the total values

Avg() – Returns the average of the total values

Sum() – Returns the sum of the values returned by the SQL expression

What is Anomaly?

Anomaly means inconsistency in the pattern from the normal form. In Database Management
System (DBMS), anomaly means the inconsistency occurred in the relational table during the
operations performed on the relational table.

There can be various reasons for anomalies to occur in the database. For example, if there is a lot
of redundant data present in our database then DBMS anomalies can occur. If a table is
constructed in a very poor manner then there is a chance of database anomaly. Due to database
anomalies, the integrity of the database suffers.

The other reason for the database anomalies is that all the data is stored in a single table. So, to
remove the anomalies of the database, normalization is the process which is done where the
splitting of the table and joining of the table (different types of join) occurs.

Explain 3 types of anomalies?

Worker_id Worker_name Worker_dept Worker_address

65 Ramesh ECT001 Jaipur


65 Ramesh ECT002 Jaipur

73 Amit ECT002 Delhi

76 Vikas ECT501 Pune

76 Vikas ECT502 Pune

79 Rajesh ECT669 Mumbai

Updation / Update Anomaly

When we update some rows in the table, and if it leads to the inconsistency of the table then this
anomaly occurs. This type of anomaly is known as an updation anomaly. In the above table, if
we want to update the address of Ramesh then we will have to update all the rows where Ramesh
is present. If during the update we miss any single row, then there will be two addresses of
Ramesh, which will lead to inconsistent and wrong databases.

Insertion Anomaly

If there is a new row inserted in the table and it creates the inconsistency in the table then it is
called the insertion anomaly. For example, if in the above table, we create a new row of a
worker, and if it is not allocated to any department then we cannot insert it in the table so, it will
create an insertion anomaly.

Deletion Anomaly

If we delete some rows from the table and if any other information or data which is required is
also deleted from the database, this is called the deletion anomaly in the database. For example,
in the above table, if we want to delete the department number ECT669 then the details of Rajesh
will also be deleted since Rajesh's details are dependent on the row of ECT669. So, there will be
deletion anomalies in the table.

specific
Types
database
the
Whatwhole
are
ofend
abstraction
the
database
users,
types
Internal
Conceptual
External ornearest
ofView
Levelorrelationships?
or to theLevel-
Logical user.
Physical
level- related
Level-
Describes
to Physical
the data,
thestorage
which
Database
isstructure
viewed
structure
of
bythe
of

One-to-one relationship

One-to-many relationship

Many-to-many relationship
What do you mean by ER model?

o ER model stands for an Entity-Relationship model. It is a high-level data model. This


model is used to define the data elements and relationship for a specified system.
o It develops a conceptual design for the database. It also develops a very simple and easy
to design view of data.
o In ER modeling, the database structure is portrayed as a diagram called an entity-
relationship diagram.

What are the components of an ER diagram?

What is an entity?

An entity may be any object, class, person or place. In the ER diagram, an entity can be
represented as rectangles.
Consider an organization as an example- manager, product, employee, department etc. can be
taken as an entity.

What is a week entity?

An entity that depends on another entity called a weak entity. The weak entity doesn't contain
any key attribute of its own. The weak entity is represented by a double rectangle.

What is an attribute?

The attribute is used to describe the property of an entity. Eclipse is used to represent an
attribute.

For example, id, age, contact number, name, etc. can be attributes of a student.

What is a key attribute?

The key attribute is used to represent the main characteristics of an entity. It represents a primary
key. The key attribute is represented by an ellipse with the text underlined.
What is a composite attribute?

An attribute that composed of many other attributes is known as a composite attribute. The
composite attribute is represented by an ellipse, and those ellipses are connected with an ellipse.

What is a multivalued attribute?

An attribute can have more than one value. These attributes are known as a multivalued attribute.
The double oval is used to represent multivalued attribute.

For example, a student can have more than one phone number.
What do you mean By Derived attribute?

An attribute that can be derived from other attribute is known as a derived attribute. It can be
represented by a dashed ellipse.

For example, A person's age changes over time and can be derived from another attribute like
Date of birth.

What do you mean by relationship in ER Diagram?

A relationship is used to describe the relation between entities. Diamond or rhombus is used to
represent the relationship.

Types of relationship are as follows:


a. One-to-One Relationship

When only one instance of an entity is associated with the relationship, then it is known as one to
one relationship.

For example, A female can marry to one male, and a male can marry to one female.

One-to-many relationship

When only one instance of the entity on the left, and more than one instance of an entity on the
right associates with the relationship then this is known as a one-to-many relationship.

For example, Scientist can invent many inventions, but the invention is done by the only
specific scientist.

Many-to-one relationship

When more than one instance of the entity on the left, and only one instance of an entity on the
right associates with the relationship then it is known as a many-to-one relationship.

For example, Student enrolls for only one course, but a course can have many students.

Many-to-many relationship

When more than one instance of the entity on the left, and more than one instance of an entity on
the right associates with the relationship then it is known as a many-to-many relationship.
For example, Employee can assign by many projects and project can have many employees.

What is a functional Depenedency?

The functional dependency is a relationship that exists between two attributes. It typically exists
between the primary key and non-key attribute within a table.

X → Y

The left side of FD is known as a determinant, the right side of the production is known as a
dependent.

For example:

Assume we have an employee table with attributes: Emp_Id, Emp_Name, Emp_Address.

Here Emp_Id attribute can uniquely identify the Emp_Name attribute of employee table because
if we know the Emp_Id, we can tell that employee name associated with it.

Functional dependency can be written as

Emp_Id → Emp_Name

We can say that Emp_Name is functionally dependent on Emp_Id.

o A → B has trivial functional dependency if B is a subset of A.


o The following dependencies are also trivial like: A → A, B → B
o A → B has a non-trivial functional dependency if B is not a subset of A.
o When A intersection B is NULL, then A → B is called as complete non-trivial.

What is a relational algebra?

Relational algebra is a procedural query language. It gives a step by step process to obtain the
result of the query. It uses operators to perform queries.
Select Operation:

o The select operation selects tuples that satisfy a given predicate.


o It is denoted by sigma (σ)

Project Operation:
o This operation shows the list of those attributes that we wish to appear in the result. Rest
of the attributes are eliminated from the table.
o It is denoted by ∏.

Union Operation:
o Suppose there are two tuples R and S. The union operation contains all the tuples that are
either in R or S or both in R & S.
o It eliminates the duplicate tuples. It is denoted by ∪.

Set Intersection:
o Suppose there are two tuples R and S. The set intersection operation contains all tuples
that are in both R & S.
o It is denoted by intersection ∩.

Cartesian product
o The Cartesian product is used to combine each row in one table with each row in the
other table. It is also known as a cross product.
o It is denoted by X.
Rename Operation:

The rename operation is used to rename the output relation. It is denoted by rho (ρ).

Example: We can use the rename operator to rename STUDENT relation to STUDENT1.

ρ(STUDENT1, STUDENT)

What is Data independence?


o Data independence can be explained using the three-schema architecture.
o Data independence refers characteristic of being able to modify the schema at one level
of the database system without altering the schema at the next higher level.

There are two types of data independence:

1. Logical Data Independence

o Logical data independence refers characteristic of being able to change the conceptual
schema without having to change the external schema.
o Logical data independence is used to separate the external level from the conceptual
view.
o If we do any changes in the conceptual view of the data, then the user view of the data
would not be affected.
o Logical data independence occurs at the user interface level.

2. Physical Data Independence

o Physical data independence can be defined as the capacity to change the internal schema
without having to change the conceptual schema.
o If we do any changes in the storage size of the database system server, then the
Conceptual structure of the database will not be affected.
o Physical data independence is used to separate conceptual levels from the internal levels.
o Physical data independence occurs at the logical interface level.
What do you mean integrity constraints?
o Integrity constraints are a set of rules. It is used to maintain the quality of information.
o Integrity constraints ensure that the data insertion, updating, and other processes have to
be performed in such a way that data integrity is not affected.
o Thus, integrity constraint is used to guard against accidental damage to the database.
Domain constraints
o Domain constraints can be defined as the definition of a valid set of values for an
attribute.
o The data type of domain includes string, character, integer, time, date, currency, etc. The
value of the attribute must be available in the corresponding domain.

Entity integrity constraints


o The entity integrity constraint states that primary key value can't be null.
o This is because the primary key value is used to identify individual rows in relation and if
the primary key has a null value, then we can't identify those rows.
o A table can contain a null value other than the primary key field.
Referential Integrity Constraints
o A referential integrity constraint is specified between two tables.
o 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 2.

Key constraints
o Keys are the entity set that is used to identify an entity within its entity set uniquely.
o An entity set can have multiple keys, but out of which one key will be the primary key. A
primary key can contain a unique and null value in the relational table.

You might also like