1. Explain a join?

Joins are used in queries to explain how different tables are related.
Joins also let you select data from a table depending upon data from another table.

2. Can you explain different types of joins?

Types of joins: INNER JOINs, OUTER JOINs, CROSS JOINs.
OUTER JOINs are further classified as LEFT OUTER JOINS, RIGHT OUTER JOINS and FULL OUTER JOINS.

3. What are different Types of Join?

A join is typically used to combine results of two tables. A Join in SQL can be:-

Inner joins
Outer Joins
Left outer joins
Right outer joins
Full outer joins
Inner join

An inner join looks for matching records taken from one table from another.
A left outer join limits results to the table in left of JOIN.
A right outer join limits results to the table in right of JOIN.
Full outer joins are the combination of left and right outer joins

4. What is a self join in SQL Server?

Two instances of the same table will be joined in the query.

5. Explain Nested Join?

In nested joins, for each tuple in the outer join relation, the system scans the entire inner-join relation and appends any tuples that match the join-condition to the result set.

6. What is Merge join?

Merge join If both join relations come in order, sorted by the join attribute(s), the system can perform the join trivially, thus: It can consider the current group of tuples from the inner relation which consists of a set of contiguous tuples in the inner relation with the same value in the join attribute. For each matching tuple in the current inner group, add a tuple to the join result. Once the inner group has been exhausted, advance both the inner and outer scans to the next group.

7. What is Hash join?

A hash join algorithm can only produce equi-joins. The database system pre-forms access to the tables concerned by building hash tables on the join-attributes.

8. What is inner join? Explain with an example?

INNER JOIN: Inner join returns rows when there is at least one match in both tables.

Syntax:

SELECT column_name(s) FROM table_name1 INNER JOIN table_name2 ON table_name1.column_name=table_name2.column_name

Example: To display records of an employee who got an appraisal.

SELECT employee.firstname, appraisal.amount FROM employee INNER JOIN appraisal ON employee.id = appraisal.employee.id;

9. What is OUTER JOIN?

In An outer join, rows are returned even when there are no matches through the JOIN criteria on the second table.

10. What is LEFT OUTER JOIN?

A left outer join or a left join returns results from the table mentioned on the left of the join irrespective of whether it finds matches or not. If the ON clause matches 0 records from table on the right, it will still return a row in the result-but with NULL in each column.

Example: To display employees irrespective of whether they have got bonus.
Select * From employee LEFT OUTER JOIN bonus ON employee.bonusID=bonus.bonusID

Download Interview PDF

11. What is RIGHT OUTER JOIN?

A right outer join or a right join returns results from the table mentioned on the right of the join irrespective of whether it finds matches or not. If the ON clause matches 0 records from table on the left, it will still return a row in the result-but with NULL in each column.

Example: To display Bonus irrespective of whether they are an employee or not.
Select * From employee RIGHT OUTER JOIN bonus ON employee.bonusID=bonus.bonusID

12. What is FULL OUTER JOIN?

A full outer join will combine results of both left and right outer join. Hence the records from both tables will be displayed with a NULL for missing matches from either of the tables.

Example: To display employees who have a bonus and to display bonus even if he is not an employee.
Select * From employee FULL OUTER JOIN bonus ON employee.bonusID=bonus.bonusID

13. Explain RDBMS?

Relational Data Base Management Systems (RDBMS) are database management systems that maintain data records and indices in tables. Relationships may be created and maintained across and among the data and tables. In a relational database, relationships between data items are expressed by means of tables. Inter-dependencies among these tables are expressed by data values rather than by pointers. This allows a high degree of data independence. An RDBMS has the capability to recombine the data items from different files, providing powerful tools for data usage.

14. Explain the properties of the Relational tables?

☛ Values are atomic.
☛ Column values are of the same kind.
☛ Each row is unique.
☛ The sequence of columns is insignificant.
☛ The sequence of rows is insignificant.
☛ Each column must have a unique name.

15. What is De-normalization?

De-normalization is the process of attempting to optimize the performance of a database by adding redundant data. It is sometimes necessary because current DBMSs implement the relational model poorly. A true relational DBMS would allow for a fully normalized database at the logical level, while providing physical storage of data that is tuned for high performance. De-normalization is a technique to move from higher to lower normal forms of database modeling in order to speed up database access.

16. What is 1NF normalization form?

Eliminate Repeating Groups Make a separate table for each set of related attributes, and give each table a primary key. Each field contains at most one value from its attribute domain.

17. What is 2NF normalization form?

Eliminate Redundant Data If an attribute depends on only part of a multi-valued key, remove it to a separate table.

18. What is 3NF normalization form?

Eliminate Columns Not Dependent On Key If attributes do not contribute to a description of the key, remove them to a separate table. All attributes must be directly dependent on the primary key.

19. What is BCNF normalization form?

Boyce-Codd Normal Form If there are non-trivial dependencies between candidate key attributes, separate them out into distinct tables.

20. What is 4NF in normalization form?

Isolate Independent Multiple Relationships No table may contain two or more 1:n or n:m relationships that are not directly related.

21. What is 5NF in normalization form?

Isolate Semantically Related Multiple Relationships There may be practical constrains on information that justify separating logically related many-to-many relationships.

22. What is ONF in normalization form?

Optimal Normal Form A model limited to only simple (elemental) facts, as expressed in Object Role Model notation.

23. What is DKNF in normalization form?

Domain-Key Normal Form A model free from all modification anomalies is said to be in DKNF.

24. Explain Stored Procedure?

A stored procedure is a named group of SQL statements that have been previously created and stored in the server database. Stored procedures accept input parameters so that a single procedure can be used over the network by several clients using different input data. And when the procedure is modified, all clients automatically get the new version. Stored procedures reduce network traffic and improve performance. Stored procedures can be used to help ensure the integrity of the database.
☛ e.g. sp_helpdb, sp_renamedb, sp_depends etc.

Download Interview PDF

25. Explain triggers in SQL?

A trigger is a SQL procedure that initiates an action when an event (INSERT, DELETE or UPDATE) occurs. Triggers are stored in and managed by the DBMS. Triggers are used to maintain the referential integrity of data by changing the data in a systematic fashion. A trigger cannot be called or executed; DBMS automatically fires the trigger as a result of a data modification to the associated table. Triggers can be viewed as similar to stored procedures in that both consist of procedural logic that is stored at the database level. Stored procedures, however, are not event-drive and are not attached to a specific table as triggers are. Stored procedures are explicitly executed by invoking a CALL to the procedure while triggers are implicitly executed. In addition, triggers can also execute stored procedures.