Structured Query Language (SQL) is a special-purpose language for interacting with relational databases. The vast majority of applications that use data are backed by a good relational database system. SQL is a language that enables you to work with databases. Using SQL, you can insert records, update and delete records, and can also create new objects such as databases and tables.
There are far more advanced features that include creating stored procedures or SQL scripts, views, and setting permissions on database objects (such as tables, stored procedures, and views). Although ANSI (American National Standards Institute) has established SQL standards, there are many different versions of SQL based on different types of databases (or vendors). However, to be in compliance with the ANSI standard, they need to at least support the major commands such as DELETE, INSERT, UPDATE, WHERE, etc.
SQL is classified or divided into DDL and DML statements, Data Manipulation Language (DML), and Data Definition Language (DDL).
DML enables you to work with the data that goes into the database. DML is used to insert, select, update, and delete records in the database.
DDL statements are the subset of SQL statements that helps you to change the structure of the database schema in some way by creating, deleting, or modifying schema objects such as databases, tables, and views.
Now, let's get ahead and know the SQL interview questions that may strike in your next interview.
Let’s also look at some of the key things that you need to keep in mind while answering the interview questions. The general questions will revolve around key concepts like Constraints, Indexes, Views, Joins, Functions, Stored Procedures, Transactions, and Locks. You may also get some scenario-based questions than objective questions when the interviewer wants to test your knowledge in deep for example: How will you tune your SQL and Stored Procedures and what are the best practices? The level of the interview entirely depends on the position. It could be simple SQL for analyst roles, or it could be more complex SQL interview questions and data modeling questions for engineering roles.
A) Allen
B) CLARK
C) JACKSON
D) David
A) AVG
B) MIN
C) LENGTH
D) SUM
E) ROUND
A) RTRIM
B) RPAD
C) TRIM
A) SELECT CustomerName, SalesDate FROM Sales ORDER BY SalesDate DESC, CustomreName;
SELECT TOP(1) Salary FROM
{
SELECT DISTINCT TOP(10) Salary FROM EMPLOYEE ORDER BY Salary DESC
} AS EMP ORDER BY SALARY
B) SELECT CustomerName, SalesDate FROM Sales ORDER BY CustomreName;
SELECT TOP(1) Salary FROM
{
SELECT DISTINCT TOP(10) Salary FROM EMPLOYEE ORDER BY Salary
} AS EMP ORDER BY SALARY DESC
C) SELECT CustomerName, SalesDate FROM Sales ORDER BY CustomreName, SalesDate;
SELECT TOP(1) Salary FROM
{
SELECT DISTINCT TOP(10) Salary FROM EMPLOYEE ORDER BY Salary
} AS EMP ORDER BY SALARY
D) SELECT CustomerName, SalesDate FROM Sales ORDER BY CustomreName, SalesDate DESC;
SELECT TOP(1) Salary FROM
{
SELECT DISTINCT TOP(10) Salary FROM EMPLOYEE ORDER BY Salary DESC
} AS EMP ORDER BY SALARY DESC
A) Select name from instructor where salary between 1,00,000 and 90,000
B) Select name from instructor where salary < 90,000 and salary >= 1,00,000
C) Select name from instructor where salary <= 90,000 and salary >= 1,00,000
D) Select name from instructor where salary between 90,000 and 1,00,000
Using ROWID.
SELECT CUSTOMER.T. CUSTOMER_ID, ORDER_T. CUSTOMER_ID, NAME, ORDER_ID FROM CUSTOMER_T, ORDER_T where CUSTOMER_T.CUSTOMER_ID=ORDER_T.CUSTOMER.ID
A) Outer Join
B) Cartesian Join
C) Equi-Join
D) Natural Join
Maintaining the integrity of the data through a set of rules that restrict the values of one or more columns of the tables based on the values of the primary key or unique key of the referenced table.
9. Identify correct ANSI SQL Syntax. Select all that are applicable.
A) Select e* from emp e join dept d on e.deptno=d.deptno
B) Select e* from emp e, dept d where e.deptno=d.deptno
C) Select e* from emp e inner join dept d on e.deptno=d.deptno
D) Select *from emp INNER JOIN dept USING (deptno)
A) Secondary Key
B) Unique Indexes
C) NOT NULL
D) Primary Key
A) Updates the statistics of every table in the database only once at 1:00 AM, writes a log entry to SQL Server log and NT application log
B) Updates the statistics of every table in the database every night at 1:00 AM, writes a log entry to SQL Server log and NT application log
C) Error Message
D) Updates the statistics of every table in the database every night at 1:00 AM
A) UPDATE Supplier SET city=’Chennai’ AND Phone=’8929182918’ AND Fax=’044-42323233’
B) UPDATE Supplier SET city=’Chennai’, Phone=’8929182918’, Fax=’044-42323233’
C) Options A & B
D) None of the above
A) select decode (sex, ’M’,’Male’,’F’,’Female’,’Unknown’) from employees
B) select name, CASE When SAL>1000 THEN ‘OverPaid’ ELSE ‘UnderPaid’ END from EMP;
C) Option A& B
D) None of the above
SELECT * FROM table1
SELECT COUNT (*) FROM table1
SELECT rows FROM sysindexes WHERE id = OBJECT_ID(table1) AND indid < 2
A) SELECT * from Persons WHERE FirstName STARTSWITH ‘a’
B) SELECT * from Persons WHERE FirstName LIKE ‘%a’
C) SELECT * from Persons WHERE FirstName = ‘%a%’
D) SELECT * from Persons WHERE FirstName LIKE ‘%a’
SELECT e.emp_id,(.15*e.salary) + (.5*e.comiss_pct) + (s.sales*(.35*e.bonus)) AS CALC VALUE FROM emp e, sales s where e.emp_id=s.emp_id;
A) Error Message will be displayed
B) CALC_VALUE column will be higher
C) CALC_VALUE column will be lower
D) There will be no difference in the value displayed CALC_VALUE column.
An Index is an optional structure related to a table. It is used to access rows directly and can be created to increase the performance of data retrieval. The index can be created on one or more columns of a table.
A) UPDATE SET LastName=’Hanson’ INTO LastName=’Nileson’ FROM PERSONS
B) UPDATE SET LastName=Nilesen WHERE LastName=’Hanson’ FROM PERSONS
C) UPDATE PERSONS SET LastName=’Hansen’ INTO LastName=’Nilson’
D) UPDATE PERSONS SET LastName=’Nilsen’ WHERE LastName=’Hanson’
TRUNCATE commits after deleting the entire table, i.e., cannot be rolled back. Database triggers do not fire on TRUNCATE.
DELETE allows the filtered deletion. Deleted records can be rolled back or committed. Database triggers fire on DELETE.
A) True
B) False
C) UNKNOWN
D) All of the above
INSTR (String1, String2(n, (m)),
INSTR returns the position of the nth occurrence of string 2 in
string1. The search begins from the nth position of string1.
SUBSTR (String1 n, m)
SUBSTR returns a character string of size m in string1, starting from the nth position of string1.
Considering a large subquery result, EXISTS is faster than IN because IN returns a value whereas EXISTS returns a Boolean value.
The highest value that a BYTE field can store is 255 (from -128 to 127).
A) WHERE Expenses <>
B) WHERE Expenses IS NULL
C) WHERE Expenses = NULL
D) WHERE Expenses NOT IN (*)
A) INSERT
B) UPDATE
C) GRANT
D) TRUNCATE
E) CREATE
SELECT a.empname ||' is working under '||b. emp name FROM EMP a, EMP b WHERE a.mgr=b.empno UNION SELECT 'There is no manager to '|| emp name FROM EMP WHERE mgr IS NULL
A) COMMIT and ROLLBACK commands are used only while creating and dropping tables
B) ROLLBACK command is used to undo transactions since the last commit or rollback was issued
C) COMMIT command is used to save transactions since the last commit or rollback was issued
D) Everything that is included within the BEGIN and END statements will execute as a unit or will not execute at all
SELECT DISTINCT (a.salary) FROM EMP A
WHERE &N = (SELECT COUNT (DISTINCT (b.salary)) FROM EMP B
WHERE a.salary<=b.salary);
A) Serializable
B) Read Committed
C) Read Uncommitted
D) Repeatable Read
A) A view is a group of SQL statements forming a logical unit of work.
B) Views are queries that can provide users with a managed (limited) presentation of data or in other words, provides an abstraction of the table.
C) Views are nothing but a set of nested inner and outer queries.
D) Views are created using CREATE TABLE statements.
These 30 SQL interview questions and answers would have given you an insight into what kind of questions could be asked in your next interview, and you need to be prepared for it.
SQL is evolving rapidly and is one of the widely used query languages for data extraction and analysis from relational databases. Despite the outburst of NoSQL in recent years, SQL is still making its way back to become the widespread interface for data extraction and analysis. It is also not very hard to learn unlike some programming languages, and the good news is that if you learn how to write SQL queries, you would be able to work with almost any of the relational database management systems. Simplilearn has many courses in SQL which can help you get foundational and deep knowledge in SQL and eventually become a SQL expert.
SQL training is highly recommended for anyone who would like to make their career in SQL. So why wait? Enroll in our course below to become a SQL expert now.
John Terra lives in Nashua, New Hampshire and has been writing freelance since 1986. Besides his volume of work in the gaming industry, he has written articles for Inc.Magazine and Computer Shopper, as well as software reviews for ZDNet. More recently, he has done extensive work as a professional blogger. His hobbies include running, gaming, and consuming craft beers. His refrigerator is Wi-Fi compliant.
Full Stack Java Developer
Full Stack Web Developer - MEAN Stack
SQL Training
*Lifetime access to high-quality, self-paced e-learning content.
Explore CategoryDevOps Interview Guide
How to Combine Tables Using Join in SQL
Top 90+ AWS Interview Questions and Answers in 2020
Kubernetes Interview Guide
What Is SQL? The Most Widely-Used Relational Database Language
Top 45 RPA Interview Questions and Answers in 2020