Database Questions And Answers Pdf

1. What is DBMS?

A Database Management System (DBMS) is a program that controls creation, maintenance and use of a database. DBMS can be termed as File Manager that manages data in a database rather than saving it in file systems.

You are here: Home / Latest Articles / Database / Top 50 Oracle Interview Questions and Answers last updated August 24, 2019 / 5 Comments / in Database / by admin 1. Sql Database Interview Questions And Answers Pdf A Database Management System (DBMS) is a program that controls creation, maintenance and use of a database. Download PDF. SQL stands for Structured Query Language, and it is used to communicate with the Database. Top 72 Perl Interview Questions and Answers Top 65 PL/SQL Interview Questions. DBMS - Interview Questions and Answers Level 1 1. What is database? A database is a logically coherent collection of data with some inherent meaning, representing some aspect of real world and which is designed, built and populated with data for a specific purpose. What is DBMS? It is a collection of programs that enables user to create.

2. What is RDBMS?

RDBMS stands for Relational Database Management System. RDBMS store the data into the collection of tables, which is related by common fields between the columns of the table. It also provides relational operators to manipulate the data stored into the tables.

Example: SQL Server.

3. What is SQL?

SQL stands for Structured Query Language , and it is used to communicate with the Database. This is a standard language used to perform tasks such as retrieval, updation, insertion and deletion of data from a database.

Standard SQL Commands are Select.

4. What is a Database?

Database is nothing but an organized form of data for easy access, storing, retrieval and managing of data. This is also known as structured form of data which can be accessed in many ways.

Example: School Management Database, Bank Management Database.

5. What are tables and Fields?

A table is a set of data that are organized in a model with Columns and Rows. Columns can be categorized as vertical, and Rows are horizontal. A table has specified number of column called fields but can have any number of rows which is called record.

Example:.

Table: Employee.

Field: Emp ID, Emp Name, Date of Birth.

Data: 201456, David, 11/15/1960.

6. What is a primary key?

A primary key is a combination of fields which uniquely specify a row. This is a special kind of unique key, and it has implicit NOT NULL constraint. It means, Primary key values cannot be NULL.

7. What is a unique key?

A Unique key constraint uniquely identified each record in the database. This provides uniqueness for the column or set of columns.

A Primary key constraint has automatic unique constraint defined on it. But not, in the case of Unique Key.

There can be many unique constraint defined per table, but only one Primary key constraint defined per table.

8. What is a foreign key?

A foreign key is one table which can be related to the primary key of another table. Relationship needs to be created between two tables by referencing foreign key with the primary key of another table.

9. What is a join?

This is a keyword used to query data from more tables based on the relationship between the fields of the tables. Keys play a major role when JOINs are used.

10. What are the types of join and explain each?

There are various types of join which can be used to retrieve data and it depends on the relationship between tables.

  • Inner Join.

Inner join return rows when there is at least one match of rows between the tables.

  • Right Join.

Right join return rows which are common between the tables and all rows of Right hand side table. Simply, it returns all the rows from the right hand side table even though there are no matches in the left hand side table.

  • Left Join.

Left join return rows which are common between the tables and all rows of Left hand side table. Simply, it returns all the rows from Left hand side table even though there are no matches in the Right hand side table.

  • Full Join.

Full join return rows when there are matching rows in any one of the tables. This means, it returns all the rows from the left hand side table and all the rows from the right hand side table.

11. What is normalization?

Normalization is the process of minimizing redundancy and dependency by organizing fields and table of a database. The main aim of Normalization is to add, delete or modify field that can be made in a single table.

12. What is Denormalization.

DeNormalization is a technique used to access the data from higher to lower normal forms of database. It is also process of introducing redundancy into a table by incorporating data from the related tables.

13. What are all the different normalizations?

The normal forms can be divided into 5 forms, and they are explained below -.

  • First Normal Form (1NF):.

This should remove all the duplicate columns from the table. Creation of tables for the related data and identification of unique columns.

  • Second Normal Form (2NF):.
Database quiz questions and answers

Meeting all requirements of the first normal form. Placing the subsets of data in separate tables and Creation of relationships between the tables using primary keys.

  • Third Normal Form (3NF):.

This should meet all requirements of 2NF. Removing the columns which are not dependent on primary key constraints.

  • Fourth Normal Form (3NF):.

Meeting all the requirements of third normal form and it should not have multi- valued dependencies.

Questions

14. What is a View?

A view is a virtual table which consists of a subset of data contained in a table. Views are not virtually present, and it takes less space to store. View can have data of one or more tables combined, and it is depending on the relationship.

15. What is an Index?

An index is performance tuning method of allowing faster retrieval of records from the table. An index creates an entry for each value and it will be faster to retrieve data.

16. What are all the different types of indexes?

There are three types of indexes -.

  • Unique Index.

This indexing does not allow the field to have duplicate values if the column is unique indexed. Unique index can be applied automatically when primary key is defined.

  • Clustered Index.

This type of index reorders the physical order of the table and search based on the key values. Each table can have only one clustered index.

  • NonClustered Index.

NonClustered Index does not alter the physical order of the table and maintains logical order of data. Each table can have 999 nonclustered indexes.

17. What is a Cursor?

A database Cursor is a control which enables traversal over the rows or records in the table. This can be viewed as a pointer to one row in a set of rows. Cursor is very much useful for traversing such as retrieval, addition and removal of database records.

18. What is a relationship and what are they?

Database Relationship is defined as the connection between the tables in a database. There are various data basing relationships, and they are as follows:.

  • One to One Relationship.
  • One to Many Relationship.
  • Many to One Relationship.
  • Self-Referencing Relationship.

19. What is a query?

A DB query is a code written in order to get the information back from the database. Query can be designed in such a way that it matched with our expectation of the result set. Simply, a question to the Database.

20. What is subquery?

A subquery is a query within another query. The outer query is called as main query, and inner query is called subquery. SubQuery is always executed first, and the result of subquery is passed on to the main query.

21. What are the types of subquery?

There are two types of subquery – Correlated and Non-Correlated.

A correlated subquery cannot be considered as independent query, but it can refer the column in a table listed in the FROM the list of the main query.

A Non-Correlated sub query can be considered as independent query and the output of subquery are substituted in the main query.

22. What is a stored procedure?

Stored Procedure is a function consists of many SQL statement to access the database system. Several SQL statements are consolidated into a stored procedure and execute them whenever and wherever required.

23. What is a trigger?

A DB trigger is a code or programs that automatically execute with response to some event on a table or view in a database. Mainly, trigger helps to maintain the integrity of the database.

Example: When a new student is added to the student database, new records should be created in the related tables like Exam, Score and Attendance tables.

24. What is the difference between DELETE and TRUNCATE commands?

DELETE command is used to remove rows from the table, and WHERE clause can be used for conditional set of parameters. Commit and Rollback can be performed after delete statement.

TRUNCATE removes all rows from the table. Truncate operation cannot be rolled back.

25. What are local and global variables and their differences?

Database Exam Questions And Answers Pdf

Local variables are the variables which can be used or exist inside the function. They are not known to the other functions and those variables cannot be referred or used. Variables can be created whenever that function is called.

Global variables are the variables which can be used or exist throughout the program. Same variable declared in global cannot be used in functions. Global variables cannot be created whenever that function is called.

26. What is a constraint?

Constraint can be used to specify the limit on the data type of table. Constraint can be specified while creating or altering the table statement. Sample of constraint are.

  • NOT NULL.
  • CHECK.
  • DEFAULT.
  • UNIQUE.
  • PRIMARY KEY.
  • FOREIGN KEY.

27. What is data Integrity?

Data Integrity defines the accuracy and consistency of data stored in a database. It can also define integrity constraints to enforce business rules on the data when it is entered into the application or database.

28. What is Auto Increment?

Auto increment keyword allows the user to create a unique number to be generated when a new record is inserted into the table. AUTO INCREMENT keyword can be used in Oracle and IDENTITY keyword can be used in SQL SERVER.

Mostly this keyword can be used whenever PRIMARY KEY is used.

29. What is the difference between Cluster and Non-Cluster Index?

Clustered index is used for easy retrieval of data from the database by altering the way that the records are stored. Database sorts out rows by the column which is set to be clustered index.

A nonclustered index does not alter the way it was stored but creates a complete separate object within the table. It point back to the original table rows after searching.

30. What is Datawarehouse?

Datawarehouse is a central repository of data from multiple sources of information. Those data are consolidated, transformed and made available for the mining and online processing. Warehouse data have a subset of data called Data Marts.

31. What is Self-Join?

Self-join is set to be query used to compare to itself. This is used to compare values in a column with other values in the same column in the same table. ALIAS ES can be used for the same table comparison.

32. What is Cross-Join?

Cross join defines as Cartesian product where number of rows in the first table multiplied by number of rows in the second table. If suppose, WHERE clause is used in cross join then the query will work like an INNER JOIN.

33. What is user defined functions?

User defined functions are the functions written to use that logic whenever required. It is not necessary to write the same logic several times. Instead, function can be called or executed whenever needed.

34. What are all types of user defined functions?

Three types of user defined functions are.

  • Scalar Functions.
  • Inline Table valued functions.
  • Multi statement valued functions.

Scalar returns unit, variant defined the return clause. Other two types return table as a return.

35. What is collation?

Collation is defined as set of rules that determine how character data can be sorted and compared. This can be used to compare A and, other language characters and also depends on the width of the characters.

ASCII value can be used to compare these character data.

36. What are all different types of collation sensitivity?

Following are different types of collation sensitivity -.

  • Case Sensitivity – A and a and B and b.
  • Accent Sensitivity.
  • Kana Sensitivity – Japanese Kana characters.
  • Width Sensitivity – Single byte character and double byte character.

37. Advantages and Disadvantages of Stored Procedure?

Stored procedure can be used as a modular programming – means create once, store and call for several times whenever required. This supports faster execution instead of executing multiple queries. This reduces network traffic and provides better security to the data.

Disadvantage is that it can be executed only in the Database and utilizes more memory in the database server.

38. What is Online Transaction Processing (OLTP)?

Online Transaction Processing (OLTP) manages transaction based applications which can be used for data entry, data retrieval and data processing. OLTP makes data management simple and efficient. Unlike OLAP systems goal of OLTP systems is serving real-time transactions.

Example – Bank Transactions on a daily basis.

39. What is CLAUSE?

SQL clause is defined to limit the result set by providing condition to the query. This usually filters some rows from the whole set of records.

Example – Query that has WHERE condition

Query that has HAVING condition.

40. What is recursive stored procedure?

A stored procedure which calls by itself until it reaches some boundary condition. This recursive function or procedure helps programmers to use the same set of code any number of times.

41. What is Union, minus and Interact commands?

UNION operator is used to combine the results of two tables, and it eliminates duplicate rows from the tables.

MINUS operator is used to return rows from the first query but not from the second query. Matching records of first and second query and other rows from the first query will be displayed as a result set.

INTERSECT operator is used to return rows returned by both the queries.

42. What is an ALIAS command?

ALIAS name can be given to a table or column. This alias name can be referred in WHERE clause to identify the table or column.

Example-.

Here, st refers to alias name for student table and Ex refers to alias name for exam table.

43. What is the difference between TRUNCATE and DROP statements?

TRUNCATE removes all the rows from the table, and it cannot be rolled back. DROP command removes a table from the database and operation cannot be rolled back.

44. What are aggregate and scalar functions?

Aggregate functions are used to evaluate mathematical calculation and return single values. This can be calculated from the columns in a table. Scalar functions return a single value based on the input value.

Example -.

Aggregate – max(), count - Calculated with respect to numeric.

Scalar – UCASE(), NOW() – Calculated with respect to strings.

45. How can you create an empty table from an existing table?

Example will be -.

Here, we are copying student table to another table with the same structure with no rows copied.

46. How to fetch common records from two tables?

Common records result set can be achieved by -.

47. How to fetch alternate records from a table?

Records can be fetched for both Odd and Even row numbers -.

To display even numbers-.

To display odd numbers-.

from (Select rowno, studentId from student) where mod(rowno,2)=1.[/sql]

48. How to select unique records from a table?

Select unique records from a table by using DISTINCT keyword.

49. What is the command used to fetch first 5 characters of the string?

There are many ways to fetch first 5 characters of the string -.

50. Which operator is used in query for pattern matching?

LIKE operator is used for pattern matching, and it can be used as -.

  1. % - Matches zero or more characters.
  2. _(Underscore) – Matching exactly one character.
Trivia questions and answers

Example -.

Sql Database Questions And Answers Pdf

1) Define Database.

A prearranged collection of figures known as data is called database.

2) What is DBMS?

Database Management Systems (DBMS) are applications designed especially which enable user interaction with other applications.

3) What are the various kinds of interactions catered by DBMS?

The various kind of interactions catered by DBMS are:

  • Data definition
  • Update
  • Retrieval
  • Administration

4) Segregate database technology's development.

The development of database technology is divided into:

  • Structure or data model
  • Navigational model
  • SQL/ relational model

5) Who proposed the relational model?

Edgar F. Codd proposed the relational model in 1970.

6) What are the features of Database language?

A database language may also incorporate features like:
DBMS-specific Configuration and management of storage engine
Computations to modification of query results by computations, like summing, counting, averaging, grouping, sorting and cross-referencing Constraint enforcement Application Programming Interface

7) What do database languages do?

As special-purpose languages, they have:

  • Data definition language
  • Data manipulation language
  • Query language

8) Define database model.

A data model determining fundamentally how data can be stored, manipulated and organised and the structure of the database logically is called database model.

9) What is SQL?

Structured Query Language (SQL) being ANSI standard language updates database and commands for accessing.

10) Enlist the various relationships of database.

The various relationships of database are:

  • One-to-one: Single table having drawn relationship with another table having similar kind of columns.
  • One-to-many: Two tables having primary and foreign key relation.
  • Many-to-many: Junction table having many tables related to many tables.

11) Define Normalization.

Organized data void of inconsistent dependency and redundancy within a database is called normalization.

12) Enlist the advantages of normalizing database.

Advantages of normalizing database are:

  • No duplicate entries
  • Saves storage space
  • Boasts the query performances.

13) Define Denormalization.

Boosting up database performance, adding of redundant data which in turn helps rid of complex data is called denormalization.

14) Define DDL and DML.

Managing properties and attributes of database is called Data Definition Language(DDL).

Manipulating data in a database such as inserting, updating, deleting is defined as Data Manipulation Language. (DML)

15) Enlist some commands of DDL.

They are:

CREATE:

Create is used in the CREATE TABLE statement. Syntax is:

ALTER:

It helps in modification of an existing object of database. Its syntax is:

DROP:

It destroys an existing database, index, table or view. Its syntax is:

16) Define Union All operator and Union.

Full recordings of two tables is Union All operator.A distinct recording of two tables is Union.

17) Define cursor.

A database object which helps in manipulating data row by row representing a result set is called cursor.

18) Enlist the cursor types.

They are:

  • Dynamic: it reflects changes while scrolling.
  • Static: doesn't reflect changes while scrolling and works on recording of snapshot.
  • Keyset: data modification without reflection of new data is seen.

19) Enlist the types of cursor.

They types of cursor are:

  • Implicit cursor: Declared automatically as soon as the execution of SQL takes place without the awareness of the user.
  • Explicit cursor: Defined by PL/ SQL which handles query in more than one row.

20) Define sub-query.

A query contained by a query is called Sub-query.

21) Why is group-clause used?

Group-clause uses aggregate values to be derived by collecting similar data.

22) Compare Non-clustered and clustered index

Both having B-tree structure, non-clustered index has data pointers enabling one table many non-clustered indexes while clustered index is distinct for every table.

23) Define Aggregate functions.

Functions which operate against a collection of values and returning single value is called aggregate functions

24) Define Scalar functions.

Scalar function is depended on the argument given and returns sole value.

25) What restrictions can you apply when you are creating views?

Restrictions that are applied are:

  • Only the current database can have views.
  • You are not liable to change any computed value in any particular view.
  • Integrity constants decide the functionality of INSERT and DELETE.
  • Full-text index definitions cannot be applied.
  • Temporary views cannot be created.
  • Temporary tables cannot contain views.
  • No association with DEFAULT definitions.
  • Triggers such as INSTEAD OF is associated with views.

26) Define 'correlated subqueries'.

A 'correlated subquery' is a sort of sub query but correlated subquery is reliant on another query for a value that is returned. In case of execution, the sub query is executed first and then the correlated query.

27) Define Data Warehousing.

Storage and access of data from the central location in order to take some strategic decision is called Data Warehousing. Enterprise management is used for managing the information whose framework is known as Data Warehousing.

28) Define Join and enlist its types.

Joins help in explaining the relation between different tables. They also enable you to select data with relation to data in another table.

The various types are:

  • INNER JOINs: Blank rows are left in the middle while more than equal to two tables are joined.
  • OUTER JOINs: Divided into Left Outer Join and Right Outer Join. Blank rows are left at the specified side by joining tables in other side.

Other joins are CROSS JOINs, NATURAL JOINs, EQUI JOIN and NON-EQUI JOIN.

29) What do you mean by Index hunting?

Indexes help in improving the speed as well as the query performance of database. The procedure of boosting the collection of indexes is named as Index hunting.

30) How does Index hunting help in improving query performance?

Index hunting helps in improving the speed as well as the query performance of database. The followed measures are achieved to do that:

  • The query optimizer is used to coordinate the study of queries with the workload and the best use of queries suggested based on this.
  • Index, query distribution along with their performance is observed to check the effect.
  • Tuning databases to a small collection of problem queries is also recommended.

31) Enlist the disadvantages of query.

The disadvantages of query are:

  • No indexes
  • Stored procedures are excessively compiled.
  • Triggers and procedures are without SET NOCOUNT ON.
  • Complicated joins making up inadequately written query.
  • Cursors and temporary tables showcase a bad presentation.

32) Enlist ways to efficiently code transactions.

Ways to efficiently code transactions:

  • User input should not be allowed while transactions.
  • While browsing, transactions must not be opened of data.
  • Transactions must be kept as small as possible.
  • Lower transaction segregation levels.
  • Least information of data must be accessed while transacting.

33) What is Executive Plan?

Executive plan can be defined as:

  • SQL Server caches collected procedure or the plan of query execution and used thereafter by subsequent calls.
  • An important feature in relation to performance enhancement.
  • Data execution plan can be viewed textually or graphically.

34) Define B-trees.

A data structure in the form of tree which stores sorted data and searches, insertions, sequential access and deletions are allowed in logarithmic time.

35) Differentiate Table Scan from Index Scan.

Iterating over all the table rows is called Table Scan while iterating over all the index items is defined as Index Scan.

36) What do you mean by Fill Factor concept with respect to indexes?

Fill Factor can be defined as being that value which defines the percentage of left space on every leaf-level page that is to be packed with data. 100 is the default value of Fill Factor.

37) Define Fragmentation.

Fragmentation can be defined as a database feature of server that promotes control on data which is stored at table level by the user.

38) Differentiate Nested Loop, Hash Join and Merge Join.

Nested loop (loop over loop)

An outer loop within an inner loop is formed consisting of fewer entries and then for individual entry, inner loop is individually processed.

E.g.

  • Select col1.*, col2.* from coll, col2 where coll.col1=col2.col2;

It's processing takes place in this way:

For i in (select * from col1) loop
For j in (select * from col2 where col2=i.col1) loop
Results are displayed;
End of the loop;
End of the loop;

The Steps of nested loop are:

  • Identify outer (driving) table
  • Assign inner (driven) table to outer table.
  • For every row of outer table, access the rows of inner table.

Nested Loops is executed from the inner to the outer as:

  • outer_loop
  • inner_loop
  • Hash join

While joining large tables, the use of Hash Join is preferred.

Algorithm of Hash Join is divided into:

  • Build: It is a hash table having in-memory which is present on the smaller table.
  • Probe: this hash value of the hash table is applicable for each second row element.
  • Sort merge join

Two independent sources of data are joined in sort merge join. They performance is better as compared to nested loop when the data volume is big enough but it is not good as hash joins generally.The full operation can be divided into parts of two:

Sort join operation :

Get first row R1 from input1

Get first row R2 from input2.

Merge join operation:

'while' is not present at either loop's end.
if R1 joins with R2
next row is got R2 from the input 2
return (R1, R2)
else if R1 <> next row is got from R1 from input 1
else
next row is got from R2 from input 2
end of the loop

39) What is Database partitioning?

Division of logical database into independent complete units for improving its management, availability and performance is called Database partitioning.

40) Explain the importance of partitioning.

Splitting of one table which is large into smaller database entities logically is called database partitioning. Its benefits are:

  • To improve query performance in situations dramatically when mostly rows which are heavily accessed are in one partition.
  • Accessing large parts of a single partition
  • Slower and cheaper storage media can be used for data which is seldom used.

41) Define Database system.

DBMS along with database is called Database system.

42) What do you mean by Query Evaluation Engine?

Query Evaluation Engine executes the low-level instructions that are generated by the compiler.

43) Define DDL Interpreter.

DDL statements are interpreted and recorded in tables called metadata.

44) Define Atomicity and Aggregation.

Atomicity: It's an all or none concept which enables the user to be assured of incomplete transactions to be taken care of. The actions involving incomplete transactions are left undone in DBMS.

Aggregation: The collected entities and their relationship are aggregated in this model. It is mainly used in expressing relationships within relationships.

45) Enlist the various transaction phases.

The various transaction phases are:

  • Analysis Phase.
  • Redo Phase
  • Undo Phase

46) Define Object-oriented model.

Compilations of objects make up this model in which values are stored within instance variables which is inside the object. The object itself comprises bodies of object for its operation which are called methods. Objects containing same kind of variables and methods are called classes.

47) Define Entity.

It can be defined as being a 'thing' with an independent existence in the real world.

48) What do you mean by Entity type?

A set of entries having similar attributes are entity types.

49) Define Entity Set.

Compilation of all entries of any particular type of entry in the database is called Entity Set.

50) What do you mean by Entity type extension?

Compilation of similar entity types into one particular type which is grouped together as an entity set.