Sunday, January 5, 2020

Database Interview Questions

1. What do you understand by ‘Database’?
Ans: Database is an organized collection of related data where the data is stored and organized to serve some specific purpose.
For Example, A librarian maintains a database of all the information related to the books that are available in the library.

2. Define DBMS.
Ans: DBMS stands for Database Management system. It is a collection of application programs which allow the user to organize, restore and retrieve information about data efficiently and as effectively as possible.
Some of the popular DBMS's are MySql, Oracle, Sybase, etc.

3. Define RDBMS.
Ans: Relational Database Management System(RDBMS) is based on a relational model of data that is stored in databases in separate tables and they are related to the use of a common column. Data can be accessed easily from the relational database using Structured Query Language (SQL).

4. Enlist the advantages of DBMS.
Ans: The Advantages of DBMS includes:
  • Data is stored in a structured way and hence redundancy is controlled.
  • Validates the data entered and provide restrictions on unauthorized access to the database.
  • Provides backup and recovery of the data when required.
  • Provides multiple user interfaces.
5. What do you understand by Data Redundancy?
Ans: Duplication of data in the database is known as Data redundancy. As a result of Data Redundancy, duplicated data is present at various locations, hence it leads to wastage of the storage space and the integrity of the database is destroyed.

6. What are the various types of relationships in Database? Define them.
Ans: There are 3 types of relationships in Database:
  • One-to-one: One table has the relationship with another table having the similar kind of column. Each primary key relates to only one or no record in the related table.
  • One-to-many: One table has a relationship with another table that has a primary and foreign key relations. The primary key table contains only one record that relates to none, one or many records in the related table.
  • Many-to-many: Each record in both the tables can relate to many numbers of record in another table.
7. Explain Normalization and De-Normalization.
Ans: Normalization is the process of removing redundant data from the database by splitting the table in a well-defined manner in order to maintain data integrity. This process saves much of the storage space.
De-normalization is the process of adding up redundant data on the table in order to speed up the complex queries and thus achieve better performance.

8. What are the different types of Normalization?
Ans: Different Types of Normalization are:
  • First Normal Form (1NF): A relation is said to be in 1NF only when all the entities of the table contain unique or atomic values.
  • Second Normal Form (2NF): A relation is said to be in 2NF only if it is in 1NF and all the non-key attribute of the table is fully dependent on the primary key.
  • Third Normal Form (3NF): A relation is said to be in 3NF only if it is in 2NF and every non-key attribute of the table is not transitively dependent on the primary key.
9. What is BCNF?
Ans: BCNF is the Boyce Code Normal form. It is the higher version of 3Nf which does not have any multiple overlapping candidate keys.

10. What is SQL?
Ans: Structured Query language, SQL is an ANSI(American National Standard Institute) standard programming language that is designed specifically for storing and managing the data in the relational database management system (RDBMS) using all kinds of data operations.

11. How many SQL statements are used? Define them.
Ans: SQL statements are basically divided into three categories, DDL, DML, and DCL.
They can be defined as:
Data Definition Language (DDL) commands are used to define the structure that holds the data. These commands are auto-committed i.e. changes done by the DDL commands on the database are saved permanently.
Data Manipulation Language (DML) commands are used to manipulate the data of the database. These commands are not auto-committed and can be rolled back.
Data Control Language (DCL) commands are used to control the visibility of the data in the database like revoke access permission for using data in the database.

12. Enlist some commands of DDL, DML, and DCL.
Ans: Data Definition Language (DDL) commands:
  • CREATE to create a new table or database.
  • ALTER for alteration.
  • Truncate to delete data from the table.
  • DROP to drop a table.
  • RENAME to rename a table.
Data Manipulation Language (DML) commands:
  • INSERT to insert a new row.
  • UPDATE to update an existing row.
  • DELETE to delete a row.
  • MERGE for merging two rows or two tables.
Data Control Language (DCL) commands:
  • COMMIT to permanently save.
  • ROLLBACK to undo the change.
  • SAVEPOINT to save temporarily.
13. Define DML Compiler.
Ans: DML compiler translates DML statements in a query language into a low-level instruction and the generated instruction can be understood by Query Evaluation Engine.

14. What is DDL interpreter?
Ans: DDL Interpreter interprets the DDL statements and records the generated statements in the table containing metadata.

15. Enlist the advantages of SQL.
Ans: Advantages of SQL are:
  • Simple SQL queries can be used to retrieve a large amount of data from the database very quickly and efficiently.
  • SQL is easy to learn and almost every DBMS supports SQL.
  • It is easier to manage the database using SQL as no large amount of coding is required.
16. Explain the terms ‘Record’, ‘Field’ and ‘Table’ in terms of database.
Ans: Record: Record is a collection of values or fields of a specific entity. Example: An employee, Salary account, etc.
Field: A field refers to an area within a record that is reserved for a specific piece of data. Example: Employee ID.
Table: Table is the collection of records of specific types. Example: Employee table is a collection of record related to all the employees.

17. What do you understand by Data Independence? What are its two types?
Ans: Data Independence refers to the ability to modify the schema definition in one level in such a way that it does not affect the schema definition in the next higher level.
The 2 types of Data Independence are:
  • Physical Data Independence: It modifies the schema at the physical level without affecting the schema at the conceptual level.
  • Logical Data Independence: It modifies the schema at the conceptual level without affecting or causing changes in the schema at the view level.
18. Define the relationship between ‘View’ and ‘Data Independence’.
Ans: View is a virtual table that does not have its data on its own rather the data is defined from one or more underlying base tables.
Views account for logical data independence as the growth and restructuring of base tables is not reflected in views.

19. What are the advantages and disadvantages of views in the database?
Ans: Advantages of Views:
  • As there is no physical location where the data in views is stored, it generates output without wasting resources.
  • Data access is restricted as it does not allow commands like insertion, updation, and deletion.
Disadvantages of Views:
  • The view becomes irrelevant if we drop a table related to that view.
  • More memory is occupied when the view is created for large tables.
20. What do you understand by Functional dependency?
Ans: A relation is said to be in Functional dependency when one attribute uniquely defines another attribute.
For Example, R is a Relation, X and Y are two attributes. T1 and T2 are two tuples. Then,
T1[X]=T2[X] and T1[Y]=T2[Y] means the value of component X uniquely define the value of component Y.
Also, X->Y means Y is functionally dependent on X.

21. When is functional dependency said to be the fully functional dependency?
Ans: To fulfill the criteria of fully functional dependency, the relation must meet the requirement of functional dependency.
A functional dependency ‘A’ and ‘B’ are said to be fully functional dependent when removal of any attribute say ‘X’ from ‘A’ means the dependency does not hold anymore.

22. What do you understand by the E-R model?
Ans: E-R model is an Entity-Relationship model which defines the conceptual view of the database.
The E-R model basically shows the real-world entities and their association/relations. Entities here represent the set of attributes in the database.

23. Define Entity, Entity type, and Entity set.
Ans: Entity can be anything, be it a place, class or object which has an independent existence in the real world.
The entity type represents a set of entities that have similar attributes.
Entity set in the database represents a collection of entities having a particular entity type.

24. Define a Weak Entity set.
Ans: Weak entity set is the one whose primary key comprises of its partial key as well as the primary key of its parent entity.
This is the case because the entity set may not have sufficient attributes to form a primary key.
  
25. Explain the terms ‘Attribute’ and ‘Relations’
Ans: Attribute describes the properties or characteristics of an entity. For Example, Employee ID, Employee Name, Age, etc., can be attributes of the entity Employee.
The relation is a two-dimensional table containing a number of rows and columns where every row represents a record of the relation. Here, rows are also known as ‘Tuples’ and columns are known as ‘Attributes’.

26. What are VDL and SDL?
Ans: VDL is View Definition language which represents user views and their mapping to the conceptual schema.
SDL is Storage Definition Language which specifies the mapping between two schemas.

27. What is the Database transaction?
Ans: Sequence of operation performed which changes the consistent state of the database to another is known as the database transaction. After the completion of the transaction, either the successful completion is reflected in the system or the transaction fails and no change is reflected.

28. Define Database Lock and its types.
Ans: Database lock basically signifies the transaction about the current status of the data item i.e. whether that data is being used by other transactions or not at the present point of time.
There are two types of Database lock which are Shared Lock and Exclusive Lock.

29. What do you understand by Join?
Ans: Join is the process of explaining the relationship between different tables by combining columns from one or more table having common values in each. When a table joins with itself, it is known as Self Join.

30. What are the disadvantages of a Query?
Ans: Disadvantages of a Query are:
  • Indexes are not present.
  • Stored procedures are excessively compiled.
  • Difficulty in interfacing.
31. Define Join types.
Ans: Given below are the types of Join, which are explained with respect to the tables as an Example:
employee table:
employee table
employee_info table:
employee_info table

1) Inner JOIN: Inner JOIN is also known as a simple JOIN. This SQL query returns results from both the tables having a common value in rows.
SQL Query:
SELECT * from employee, employee_info WHERE employee.EmpID = employee_info.EmpID ;
Result:
Inner Join Example

2) Natural JOIN: This is a type of Inner JOIN that returns results from both the tables having the same data values in the columns of both the tables to be joined.
SQL Query:
SELECT * from employee NATURAL JOIN employee_info;
Result:
Natural JOIN

3) Cross JOIN: Cross JOIN return results as all the records where each row from the first table is combined with each row of the second table.
SQL Query:
SELECT * from employee CROSS JOIN employee_info;
Result:
Let us do some modification in the above tables to understand Right JOIN, Left JOIN, and Full JOIN.
employee table:
employee table new
employee_info table:
employee_info table new

1) Right JOIN: Right JOIN is also known as Right Outer JOIN. This returns all the rows as a result from the right table even if the JOIN condition does not match any records in the left table.
SQL Query:
SELECT * from employee RIGHT OUTER JOIN employee_info on (employee.EmpID = employee_info.EmpID);
Result:
Right Join Example

2) Left JOIN: Left JOIN is also known as Left Outer JOIN. This returns all the rows as a result of the left table even if JOIN condition does not match any records in the right table. This is exactly the opposite of Right JOIN.
SQL Query:
SELECT * from employee LEFT OUTER JOIN employee_info on (employee.EmpID = employee_info.EmpID);
Result:
Left JOIN

3) Outer/Full JOIN: Full JOIN return results in combining the result of both the Left JOIN and Right JOIN.
SQL Query:
SELECT * from employee FULL OUTER JOIN employee_info on (employee.EmpID = employee_info.EmpID);
Result:
Outer Full JOIN

No comments:

Post a Comment