Viva Questions
Viva 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.
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-
TRUNCATE – Deletes all the records from the DB but not its database structure
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-
REVOKE – Removes access privileges from a user-provided with the GRANT command.
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.
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.
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
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;
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.
Count() – Returns the count of the number of rows returned by the SQL expression
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.
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?
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.
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.
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.
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.
A relationship is used to describe the relation between entities. Diamond or rhombus is used to
represent the 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.
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:
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.
Emp_Id → Emp_Name
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:
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)
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.
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.
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.