Top 25 SQL Interview Questions & Answers
SQL is a language for accessing and manipulating database standardized by ANSI. To be successful with database-centric applications (which includes most of the applications Data Warehousing domain), one must be strong enough in SQL. Bringing an SQL Certification to the table gives you an edge for jobs. In this article, we will learn about SQL in the form of many question-answer sessions commonly asked in Interviews.
- What is the difference between SQL and PL/SQL?
PL/SQL is a dialect of SQL that adds procedural features of programming in SQL. It was developed by Oracle Corporation in the early 90’s to enhance the capabilities of SQL.
- When SQL appeared?
It appeared in 1974.
- Does SQL support programming?
No, SQL doesn’t have Conditional statement or loop. It is used like commanding language to access databases.
- What is a primary key?
A primary key is an aggregate of fields which uniquely specify a row. This is a special kind of unique key. Primary key values cannot be NULL.
- What are the type of operators available in SQL?
Arithmetic operators, Logical operators, Comparison operator
- What is an Index in SQL?
Index is used to increase the performance and allow faster retrieval of records from the table. An index creates an entry for each value and it will be faster to retrieve data.
- What is the SQL query to display current date?
There is a built in function in SQL called GetDate() which is used to return current timestamp.
- Can you sort a column using a column alias?
Yes. A column alias could be used in the ORDER BY clause.
- What is the purpose of the condition operators BETWEEN and IN?
The operator BETWEEN shows rows based on a range of values and IN condition operator checks for values contained in a specific set of values.
- What is the main purpose of the NVL function?
The NVL function change a NULL value to an actual value.
- What is a unique key?
A Unique key constraint uniquely identifies each record in the database. This provides uniqueness for the column or set of columns.
- Which are the most commonly used SQL joins?
One of the most commonly used SQL joins are INNER JOIN and (left/right) OUTER JOIN.
- What is Inner Join in SQL?
Inner join returns rows when there is at least one match of rows between the tables.
- What is self join and what is the requirement of self join?
Self join is often so useful to change a hierarchical structure to a flat structure. It is used to join a table to itself.
- What are set operators in SQL?
Union, Intersect or Minus operators are called set operators.
- Which statement is used to add a new row in a database table?
The INSERT INTO statement.
- How do you copy rows from one table to another?
The INSERT statement can be used to add rows to a table by replicating from another table. For this situation, a subquery is used in the place of the VALUES clause.
- What happens if you omit the WHERE clause in the UPDATE statement?
All the rows in the table are modified.
- What is the default ordering of data using the ORDER BY clause?
The default sorting order is ascending. It can be changed using the DESC keyword, after the column name in the ORDER BY clause.
- What are the case manipulation functions of SQL?
LOWER, UPPER, INITCAP
- Which function returns the remainder in a division operation?
The MOD function returns the remainder in a division operation.
- What is the usage of NVL function?
The NVL function is used to convert NULL value to a actual value.
- What do you mean by Cross Join?
The term cross join will return all records where each row from the first table is consolidated with each row from the second table.
- What are the main uses of SQL functions?
Performing calculations on data, manipulating the output, formatting dates and numbers, modifying data individual items, and converting data types.
- What is the use of the NULLIF function?
NULLIF function compares two expressions. If they are not equal, the first expression is returned, If they are equal, the function returns null.
Author Bio:
The Michael Warne is a SQL certified professional with more than 5 years of experience in the industry. The author has imparted SQL Server Certification Training, to working professionals and has been proactively talking about the importance of this course.