Sie sind auf Seite 1von 48

 Hire a developer

 Apply as a developer
 Log in


 Top 3%
 Why
 Clients
 Enterprise
 Community
 Blog
 About Us

 Questions?
 Contact Us


45 Essential SQL Interview Questions *


 1.2Kshares

Submit a question
Looking for experts? Check out Toptal’s SQL developers.

What does UNION do? What is the difference between UNION and UNION ALL?
View the answer →

List and explain the different types of JOIN clauses supported in ANSI-standard SQL.

View the answer →

For a table orders having a column defined simply as customer_id VARCHAR(100),


consider the following two query results:

SELECT count(*) AS total FROM orders;


+-------+
| total |
+-------+
| 100 |
+-------+
SELECT count(*) AS cust_123_total FROM orders WHERE customer_id = '123';
+----------------+
| cust_123_total |
+----------------+
| 15 |
+----------------+

Given the above query results, what will be the result of the query below?

SELECT count(*) AS cust_not_123_total FROM orders WHERE customer_id <>


'123';
View the answer →

Find top SQL developers today. Toptal can match you with the best engineers to finish your
project.

Hire Toptal’s SQL developers


What will be the result of the query below? Explain your answer and provide a version that
behaves correctly.

select case when null = null then 'Yup' else 'Nope' end as Result;
View the answer →

Given the following tables:

sql> SELECT * FROM runners;


+----+--------------+
| id | name |
+----+--------------+
| 1 | John Doe |
| 2 | Jane Doe |
| 3 | Alice Jones |
| 4 | Bobby Louis |
| 5 | Lisa Romero |
+----+--------------+

sql> SELECT * FROM races;


+----+----------------+-----------+
| id | event | winner_id |
+----+----------------+-----------+
| 1 | 100 meter dash | 2 |
| 2 | 500 meter dash | 3 |
| 3 | cross-country | 2 |
| 4 | triathalon | NULL |
+----+----------------+-----------+

What will be the result of the query below?

SELECT * FROM runners WHERE id NOT IN (SELECT winner_id FROM races)

Explain your answer and also provide an alternative version of this query that will avoid the
issue that it exposes.

View the answer →


Given two tables created and populated as follows:

CREATE TABLE dbo.envelope(id int, user_id int);


CREATE TABLE dbo.docs(idnum int, pageseq int, doctext varchar(100));

INSERT INTO dbo.envelope VALUES


(1,1),
(2,2),
(3,3);

INSERT INTO dbo.docs(idnum,pageseq) VALUES


(1,5),
(2,6),
(null,0);

What will the result be from the following query:

UPDATE docs SET doctext=pageseq FROM docs INNER JOIN envelope ON


envelope.id=docs.idnum
WHERE EXISTS (
SELECT 1 FROM dbo.docs
WHERE id=envelope.id
);

Explain your answer.

View the answer →

What is wrong with this SQL query? Correct it so it executes properly.

SELECT Id, YEAR(BillingDate) AS BillingYear


FROM Invoices
WHERE BillingYear >= 2010;
View the answer →
Given these contents of the Customers table:

Id Name ReferredBy
1 John Doe NULL
2 Jane Smith NULL
3 Anne Jenkins 2
4 Eric Branford NULL
5 Pat Richards 1
6 Alice Barnes 2

Here is a query written to return the list of customers not referred by Jane Smith:

SELECT Name FROM Customers WHERE ReferredBy <> 2;

What will be the result of the query? Why? What would be a better way to write it?

View the answer →

Considering the database schema displayed in the SQLServer-style diagram below, write a
SQL query to return a list of all the invoices. For each invoice, show the Invoice ID, the
billing date, the customer’s name, and the name of the customer who referred that customer
(if any). The list should be ordered by billing date.
View the answer →

Assume a schema of Emp ( Id, Name, DeptId ) , Dept ( Id, Name).

If there are 10 records in the Emp table and 5 records in the Dept table, how many rows will
be displayed in the result of the following SQL query:

Select * From Emp, Dept

Explain your answer.

View the answer →


Given a table SALARIES, such as the one below, that has m = male and f = female values.
Swap all f and m values (i.e., change all f values to m and vice versa) with a single update
query and no intermediate temp table.

Id Name Sex Salary


1 A m 2500
2 B f 1500
3 C m 5500
4 D f 500
View the answer →

Given two tables created as follows

create table test_a(id numeric);

create table test_b(id numeric);

insert into test_a(id) values


(10),
(20),
(30),
(40),
(50);

insert into test_b(id) values


(10),
(30),
(50);

Write a query to fetch values in table test_a that are and not in test_b without using the
NOT keyword.

Note, Oracle does not support the above INSERT syntax, so you would need this instead:

insert into test_a(id) values (10);


insert into test_a(id) values (20);
insert into test_a(id) values (30);
insert into test_a(id) values (40);
insert into test_a(id) values (50);
insert into test_b(id) values (10);
insert into test_b(id) values (30);
insert into test_b(id) values (50);
View the answer →
Given a table TBL with a field Nmbr that has rows with the following values:

1, 0, 0, 1, 1, 1, 1, 0, 0, 1, 0, 1, 0, 1, 0, 1

Write a query to add 2 where Nmbr is 0 and add 3 where Nmbr is 1.

View the answer →

Write a SQL query to find the 10th highest employee salary from an Employee table. Explain
your answer.

(Note: You may assume that there are at least 10 records in the Employee table.)

View the answer →

Write a SQL query using UNION ALL (not UNION) that uses the WHERE clause to eliminate
duplicates. Why might you want to do this?

View the answer →


Given the following tables:

SELECT * FROM users;

user_id username
1 John Doe
2 Jane Don
3 Alice Jones
4 Lisa Romero

SELECT * FROM training_details;

user_training_id user_id training_id training_date


1 1 1 "2015-08-02"
2 2 1 "2015-08-03"
3 3 2 "2015-08-02"
4 4 2 "2015-08-04"
5 2 2 "2015-08-03"
6 1 1 "2015-08-02"
7 3 2 "2015-08-04"
8 4 3 "2015-08-03"
9 1 4 "2015-08-03"
10 3 1 "2015-08-02"
11 4 2 "2015-08-04"
12 3 2 "2015-08-02"
13 1 1 "2015-08-02"
14 4 3 "2015-08-03"

Write a query to to get the list of users who took the a training lesson more than once in the
same day, grouped by user and training lesson, each ordered from the most recent lesson date
to oldest date.

View the answer →

What is an execution plan? When would you use it? How would you view the execution
plan?

View the answer →


List and explain each of the ACID properties that collectively guarantee that database
transactions are processed reliably.

View the answer →

Given a table dbo.users where the column user_id is a unique numeric identifier, how can
you efficiently select the first 100 odd user_id values from the table?

(Assume the table contains well over 100 records with odd user_id values.)

View the answer →

How can you select all the even number records from a table? All the odd number records?

View the answer →

What are the NVL and the NVL2 functions in SQL? How do they differ?
View the answer →

What is the difference between the RANK() and DENSE_RANK() functions? Provide an
example.

View the answer →

What is the difference between the WHERE and HAVING clauses?

View the answer →

Suppose we have a Customer table containing the following data:

CustomerID CustomerName
1 Prashant Kaurav
2 Ashish Jha
3 Ankit Varma
4 Vineet Kumar
5 Rahul Kumar

Write a single SQL statement to concatenate all the customer names into the following single
semicolon-separated string:

Prashant Kaurav; Ashish Jha; Ankit Varma; Vineet Kumar; Rahul Kumar
View the answer →
Given a table Employee having columns empName and empId, what will be the result of the
SQL query below?

select empName from Employee order by 2 desc;


View the answer →

What will be the output of the below query, given an Employee table having 10 records?

BEGIN TRAN
TRUNCATE TABLE Employees
ROLLBACK
SELECT * FROM Employees
View the answer →

1. What is the difference between single-row functions and multiple-row functions?


2. What is the group by clause used for?

View the answer →


What is the difference between char and varchar2?

View the answer →

Write an SQL query to display the text CAPONE as:

C
A
P
O
N
E

Or in other words, an SQL query to transpose text.

View the answer →

Can we insert a row for identity column implicitly?

View the answer →

Given this table:

Testdb=# Select * FROM "Test"."EMP";

ID
----
1
2
3
4
5
(5 rows)

What will be the output of below snippet?

Select SUM(1) FROM "Test"."EMP";


Select SUM(2) FROM "Test"."EMP";
Select SUM(3) FROM "Test"."EMP";
View the answer →

Table is as follows:

ID C1 C2 C3
1 Red Yellow Blue
2 NULL Red Green
3 Yellow NULL Violet

Print the rows which have ‘Yellow’ in one of the columns C1, C2, or C3, but without using
OR.

View the answer →

Write a query to insert/update Col2’s values to look exactly opposite to Col1’s values.

Col1 Col2
1 0
0 1
0 1
0 1
1 0
0 1
Col1 Col2
1 0
1 0
View the answer →

How do you get the last id without the max function?

View the answer →

What is the difference between IN and EXISTS?

View the answer →

Suppose in a table, seven records are there.

The column is an identity column.

Now the client wants to insert a record after the identity value 7 with its identity value
starting from 10.

Is it possible? If so, how? If not, why not?

View the answer →


How can you use a CTE to return the fifth highest (or Nth highest) salary from a table?

View the answer →

Imagine a single column in a table that is populated with either a single digit (0-9) or a single
character (a-z, A-Z). Write a SQL query to print ‘Fizz’ for a numeric value or ‘Buzz’ for
alphabetical value for all values in that column.

Example:

['d', 'x', 'T', 8, 'a', 9, 6, 2, 'V']

…should output:

['Buzz', 'Buzz', 'Buzz', 'Fizz', 'Buzz','Fizz', 'Fizz', 'Fizz', 'Buzz']

View the answer →

How do you get the Nth-highest salary from the Employee table without a subquery or CTE?

View the answer →


Given the following table named A:

x
------
2
-2
4
-4
-3
0
2

Write a single query to calculate the sum of all positive values of x and he sum of all negative
values of x.

View the answer →

Given the table mass_table:

weight
5.67
34.567
365.253
34

Write a query that produces the output:

weight kg gms
5.67 5 67
34.567 34 567
365.253 365 253
34 34 0
View the answer →
Consider the Employee table below.

Emp_Id Emp_name Salary Manager_Id


10 Anil 50000 18
11 Vikas 75000 16
12 Nisha 40000 18
13 Nidhi 60000 17
14 Priya 80000 18
15 Mohit 45000 18
16 Rajesh 90000 –
17 Raman 55000 16
18 Santosh 65000 17

Write a query to generate below output:

Manager_Id Manager Average_Salary_Under_Manager


16 Rajesh 65000
17 Raman 62500
18 Santosh 53750
View the answer →

How do you copy data from one table to another table ?

View the answer →


Find the SQL statement below that is equal to the following: SELECT name FROM customer
WHERE state = 'VA';

1. SELECT name IN customer WHERE state IN ('VA');


2. SELECT name IN customer WHERE state = 'VA';
3. SELECT name IN customer WHERE state = 'V';
4. SELECT name FROM customer WHERE state IN ('VA');

View the answer →

How to find a duplicate record?

1. duplicate records with one field


2. duplicate records with more than one field

View the answer →


* There is more to interviewing than tricky technical questions, so these are intended merely
as a guide. Not every “A” candidate worth hiring will be able to answer them all, nor does
answering them all guarantee an “A” candidate. At the end of the day, hiring remains an art, a
science — and a lot of work.
Submit an interview question
Submitted questions and answers are subject to review and editing, and may or may not be
selected for posting, at the sole discretion of Toptal, LLC.
SQL Server Interview Questions
In what sequence SQL statement are processed?

The clauses of the select are processed in the following sequence

1. FROM clause
2. WHERE clause
3. GROUP BY clause
4. HAVING clause
5. SELECT clause
6. ORDER BY clause
7. TOP clause

Can we write a distributed query and get some data which is located on other server
and on Oracle Database ?

SQL Server can be lined to any server provided it has OLE-DB provider from Microsoft to
allow a link.

E.g. Oracle has a OLE-DB provider for oracle that Microsoft provides to add it as linked
server to SQL Server group.

If we drop a table, does it also drop related objects like constraints, indexes, columns,
defaults, Views and Stored Procedures ?

YES, SQL Server drops all related objects, which exists inside a table like, constraints,
indexes, columns, defaults etc. BUT dropping a table will not drop Views and Stored
Procedures as they exists outside the table.

How would you determine the time zone under which a database was operating?

Can we add identity column to decimal datatype?

YES, SQL Server support this

What is the Difference between LEFT JOIN with WHERE clause & LEFT JOIN with
no WHERE clause ?

OUTER LEFT/RIGHT JOIN with WHERE clause can act like an INNER JOIN if not used
wisely or logically.

What are the Multiple ways to execute a dynamic query ?

EXEC sp_executesql, EXECUTE()

What is the Difference between COALESCE() & ISNULL() ?


ISNULL accepts only 2 parameters. The first parameter is checked for NULL value, if it is
NULL then the second parameter is returned, otherwise it returns first parameter.

COALESCE accepts two or more parameters. One can apply 2 or as many parameters, but it
returns only the first non NULL parameter,

How do you generate file output from SQL?

While using SQL Server Management Studio or Query Analyzer, we have an option in Menu
BAR.QUERTY >> RESULT TO >> Result to FILE

How do you prevent SQL Server from giving you informational messages during and
after a SQL statement execution?

SET NOCOUNT OFF

By Mistake, Duplicate records exists in a table, how can we delete copy of a record ?

;with T as
(
select * , row_number() over (partition by Emp_ID order by Emp_ID) as
rank
from employee
)

delete
from T
where rank > 1

WHAT OPERATOR PERFORMS PATTERN MATCHING?

Pattern matching operator is LIKE and it has to used with two attributes

1. % means matches zero or more characters and

2. _ ( underscore ) means matching exactly one character

What’s the logical difference, if any, between the following SQL expressions?

-- Statement 1
SELECT COUNT ( * ) FROM Employees

-- Statement 2
SELECT SUM ( 1 ) FROM Employees

They’re the same unless table Employee table is empty, in which case the first yields a one-
column, one-row table containing a zero and the second yields a one-column, one-row table
"containing a null."

s it possible to update Views? If yes, How, If Not, Why?


Yes, We can modify views but a DML statement on a join view can modify only one base
table of the view (so even if the view is created upon a join of many tables, only one table,
the key preserved table can be modified through the view).

Could you please name different kinds of Joins available in SQL Server ?

 OUTER JOIN – LEFT, RIGHT, CROSS, FULL ;


 INNER JOIN

How important do you consider cursors or while loops for a transactional database?

would like to avoid cursor in OLTP database as much as possible, Cursors are mainly only
used for maintenance or warehouse operations.

What is a correlated sub query?

When a sub query is tied to the outer query. Mostly used in self joins.

What is faster, a correlated sub query or an inner join?

Correlated sub query.

You are supposed to work on SQL optimization and given a choice which one runs
faster, a correlated sub query or an exists?

Exists

Can we call .DLL from SQL server?

YES, We can call .Dll from SQL Server.

What are the pros and cons of putting a scalar function in a queries select list or in the
where clause?

Should be avoided if possible as Scalar functions in these places make the query slow down
dramatically.

What is the difference between truncate and drop statement?

What is the difference between truncate and delete statement?

What are user defined data types and when you should go for them?

User-defined data types let you extend the base SQL Server data types by providing a
descriptive name, and format to the database. Take for example, in your database, there is a
column called Flight_Num which appears in many tables. In all these tables it should be
varchar(8). In this case you could create a user defined data type calledFlight_num_type of
varchar(8) and use it across all your tables.

See sp_addtype, sp_droptype in books online.


Can You Explain Integration Between SQL Server 2005 And Visual Studio 2005 ?

This integration provide wider range of development with the help of CLR for database
server because CLR helps developers to get flexibility for developing database applications
and also provides language interoperability just like Visual C++, Visual Basic .Net and
Visual C# .Net.

The CLR helps developers to get the arrays, classes and exception handling available through
programming languages such as Visual C++ or Visual C# which is use in stored procedures,
functions and triggers for creating database application dynamically and also provide more
efficient reuse of code and faster execution of complex tasks. We particularly liked the error-
checking powers of the CLR environment, which reduces run-time errors

SQL Server Interview Questions And Answers For Experienced

You are being assigned to create a complex View and you have completed that task and
that view is ready to be get pushed to production server now. you are supposed to fill a
deployment form before any change is pushed to production server.

One of the Filed in that deployment form asked, “Expected Storage requirement”.
What all factors you will consider to calculate storage requirement for that view ?

Very tricky, View, doesn’t takes space in Database, Views are virtual tables. Storage is
required to store Index, incase you are developing a indexed view.

What is Index, cluster index and non cluster index ?

Clustered Index:- A Clustered index is a special type of index that reorders the way records in
the table are physically stored. Therefore table may have only one clustered index.Non-
Clustered Index:- A Non-Clustered index is a special type of index in which the logical order
of the index does not match the physical stored order of the rows in the disk. The leaf nodes
of a non-clustered index does not consists of the data pages. instead the leaf node contains
index rows.

Write down the general syntax for a SELECT statements covering all the options.

Here’s the basic syntax: (Also checkout SELECT in books online for advanced syntax).

SELECT select_list

[INTO new_table_]

FROM table_source

[WHERE search_condition]

[GROUP BY group_by__expression]

[HAVING search_condition]
[ORDER BY order__expression [ASC | DESC] ]

What is a join and explain different types of joins?

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.

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.

For more information see pages from books online titled: "Join Fundamentals" and "Using
Joins".

What is OSQL utility ?

OSQL is command line tool which is used execute query and display the result same a query
analyzer but everything is in command prompt.

What Is Difference Between OSQL And Query Analyzer ?

OSQL is command line tool which executes query and display the result same a query
analyzer but query analyzer is graphical and OSQL is a command line tool. OSQL is quite
useful for batch processing or executing remote queries.

What Is Cascade delete / update ?

CASCADE allows deletions or updates of key values to cascade through the tables defined to
have foreign key relationships that can be traced back to the table on which the modification
is performed.

SQL Server Interview Questions For 2-5 Years Experienced

What are some of the join algorithms used when SQL Server joins tables.

1. Loop Join (indexed keys unordered)


2. Merge Join (indexed keys ordered)
3. Hash Join (non-indexed keys)
What is maximum number of tables that can joins in a single query ?

256, check SQL Server Limits

What is Magic Tables in SQL Server ?

The MAGIC tables are automatically created and dropped, in case you use TRIGGERS. SQL
Server has two magic tables named, INSERTED and DELETED

These are mantained by SQL server for there Internal processing. When we use update insert
or delete on tables these magic tables are used.These are not physical tables but are Internal
tables.When ever we use insert statement is fired the Inserted table is populated with newly
inserted Row and when ever delete statement is fired the Deleted table is populated with the
delete

d row.But in case of update statement is fired both Inserted and Deleted table used for records
the Original row before updation get store in Deleted table and new row Updated get store in
Inserted table.

Can we disable a triger?, if yes HOW ?

YES, we can disable a single trigger on the database by using “DISABLE TRIGGER
triggerName ON <>”

we also have an option to disable all the trigger by using, “DISABLE Trigger ALL ON ALL
SERVER”

Why you need indexing? where that is Stored and what you mean by schema object?
For what purpose we are using view?

We can’t create an Index on Index.. Index is stoed in user_index table. Every object that has
been created on Schema is Schema Object like Table, View etc. If we want to share the
particular data to various users we have to use the virtual table for the Base table. So that is a
view.

Indexing is used for faster search or to retrieve data faster from various table. Schema
containing set of tables, basically schema means logical separation of the database. View is
crated for faster retrieval of data. It’s customized virtual table. we can create a single view of
multiple tables. Only the drawback is..view needs to be get refreshed for retrieving updated
data.

What the difference between UNION and UNIONALL?

Union will remove the duplicate rows from the result set while Union all does’nt.

Which system table contains information on constraints on all the tables created ?

USER_CONSTRAINTS,
system table contains information on constraints on all the tables created

SQL Server Joins Interview Questions

Frequently Asked SQL Server Interview Questions & Answers

What are different Types of Join?

1. Cross Join A cross join that does not have a WHERE clause produces the Cartesian
product of the tables involved in the join. The size of a Cartesian product result set is
the number of rows in the first table multiplied by the number of rows in the second
table. The common example is when company wants to combine each product with a
pricing table to analyze each product at each price.
2. Inner Join A join that displays only the rows that have a match in both joined tables
is known as inner Join. This is the default type of join in the Query and View
Designer.
3. Outer Join A join that includes rows even if they do not have related rows in the
joined table is an Outer Join. You can create three different outer join to specify the
unmatched rows to be included:
1. Left Outer Join: In Left Outer Join all rows in the first-named table i.e. "left"
table, which appears leftmost in the JOIN clause are included. Unmatched
rows in the right table do not appear.
2. Right Outer Join: In Right Outer Join all rows in the second-named table i.e.
"right" table, which appears rightmost in the JOIN clause are included.
Unmatched rows in the left table are not included.
3. Full Outer Join: In Full Outer Join all rows in all joined tables are included,
whether they are matched or not.
4. Self Join This is a particular case when one table joins to itself, with one or two
aliases to avoid confusion. A self join can be of any type, as long as the joined tables
are the same. A self join is rather unique in that it involves a relationship with only
one table. The common example is when company has a hierarchal reporting structure
whereby one member of staff reports to another. Self Join can be Outer Join or Inner
Join.

What is Data-Warehousing?

1. Subject-oriented, meaning that the data in the database is organized so that all the
data elements relating to the same real-world event or object are linked together;
2. Time-variant, meaning that the changes to the data in the database are tracked and
recorded so that reports can be produced showing changes over time;
3. Non-volatile, meaning that data in the database is never over-written or deleted, once
committed, the data is static, read-only, but retained for future reporting.
4. Integrated, meaning that the database contains data from most or all of an
organization’s operational applications, and that this data is made consistent.

What is a live lock?

A live lock is one, where a request for an exclusive lock is repeatedly denied because a series
of overlapping shared locks keeps interfering. SQL Server detects the situation after four
denials and refuses further shared locks. A live lock also occurs when read transactions
monopolize a table or page, forcing a write transaction to wait indefinitely.

How SQL Server executes a statement with nested subqueries?

When SQL Server executes a statement with nested subqueries, it always executes the
innermost query first. This query passes its results to the next query and so on until it reaches
the outermost query. It is the outermost query that returns a result set.

How do you add a column to an existing table?

ALTER TABLE Department ADD (AGE, NUMBER);

Can one drop a column from a table?

YES, to delete a column in a table, use ALTER TABLE table_name DROP COLUMN
column_name

Which statement do you use to eliminate padded spaces between the month and day
values in a function TO_CHAR(SYSDATE,’Month, DD, YYYY’) ?

To remove padded spaces, you use the "fm" prefix before the date element that contains the
spaces. TO_CHAR(SYSDATE,’fmMonth DD, YYYY’)

Which operator do you use to return all of the rows from one query except rows are
returned in a second query?

You use the EXCEPT operator to return all rows from one query except where duplicate
rows are found in a second query. The UNION operator returns all rows from both queries
minus duplicates. The UNION ALL operator returns all rows from both queries including
duplicates. The INTERSECT operator returns only those rows that exist in both queries.

How will you create a column alias?

The AS keyword is optional when specifying a column alias.

In what sequence SQL statement are processed?

The clauses of the subselect are processed in the following sequence (DB2): 1. FROM clause
2. WHERE clause 3. GROUP BY clause 4. HAVING clause 5. SELECT clause 6. ORDER
BY clause 7. FETCH FIRST clause

How can we determine what objects a user-defined function depends upon?

sp_depends system stored procedure or query the sysdepends system table to return a list of
objects that a user-defined function depends upon

SELECT DISTINCT so1.name, so2.name FROM sysobjects so1


INNER JOIN sysdepends sd
ON so1.id = sd.id
INNER JOIN sysobjects so2
ON so2.id = sd.depid
WHERE so1.name = '<>'

What is lock escalation ?

A query first takes the lowest level lock possible with the smallest footprint (row-level).
When too many rows are locked (requiring too much RAM) the lock is escalated to a range
or page lock. If too many pages are locked, it may escalate to a table lock.

What are the main differences between #temp tables and @table variables and which
one is preferred ?

1. SQL Server can create column statistics on #temp tables


2. Indexes can be created on #temp tables
3. @table variables are stored in memory up to a certain threshold.

What are Checkpoint In SQL Server ?

When we done operation on SQL SERVER that is not commited directly to the database.All
operation must be logged in to Transaction Log files after that they should be done on to the
main database.CheckPoint are the point which alert Sql Server to save all the data to main
database if no check point is there then log files get full we can use Checkpoint command to
commit all data in the SQL SERVER.When we stop the SQL Server it will take long time
because Checkpoint is also fired.

Related Page: SQL Interview Questions For 5+ Years Experienced

Why we use OPENXML clause?

OPENXML parses the XML data in SQL Server in an efficient manner. It’s primary ability is
to insert XML data to the DB.

Can we store we store PDF files inside SQL Server table ?

YES, we can store this sort of data using a blob datatype.

Can we store Videos inside SQL Server table ?

YES, we can store Videos inside SQL Server by using FILESTREAM datatype, which was
introduced in SQL Server 2008.

Can we hide the definition of a stored procedure from a user ?

YES, while creating stored procedure we can use WITH ENCRYPTION which will convert
the original text of the CREATE PROCEDURE statement to an encrypted format.

What are included columns when we talk about SQL Server indexing?

Indexed with included columns were developed in SQL Server 2005 that assists in covering
queries. Indexes with Included Columns are non clustered indexes that
have the following benefits:

 Columns defined in the include statement, called non-key columns, are not counted in
the

number of columns by the Database Engine.


 Columns that previously could not be used in queries, like nvarchar(max), can be
included

as a non-key column.
 A maximum of 1023 additional columns can be used as non-key columns.

What is an execution plan? How would you view the execution plan?

An execution plan is basically a road map that graphically or textually shows the data
retrieval methods chosen by the SQL Server query optimizer for a stored procedure or ad-hoc
query and is a very useful tool for a developer to understand the performance characteristics
of a query or stored procedure since the plan is the one that SQL Server will place in its
cache and use to execute the stored procedure or query. From within Query Analyzer is an
option called "Show Execution Plan" (located on the Query drop-down menu). If this option
is turned on it will display query execution plan in separate window when query is ran again.

Explain UNION, MINUS, UNION ALL, INTERSECT ?

INTERSECT returns all distinct rows selected by both queries.

MINUS – returns all distinct rows selected by the first query but not by the second.

UNION – returns all distinct rows selected by either query

UNION ALL - returns all rows selected by either query, including all duplicates

 INTERVIEWS
 BOOKS
 NEWS
 EVENTS
 CAREER
 JOBS
 TRAINING
 MORE
Interview Questions For 2 Years Experience
in SQL and C#


 Rasmita Dash
 May 29 2015
 Article


 35
 47
 783.3k

 facebook
 twitter
 linkedIn
 google Plus
 Reddit

o Email
o Bookmark
o Other Artcile
 Expand

Download Free Office API

I appeared for an interview that was for 2 years experience and had 4 technical rounds. Here
my purpose is to share the questions that I encountered. However, I have given brief answers
just for reference.

General SQL Interview Questions:

1. What is a Database?
A database is a collection of information in an organized form for faster and better access,
storage and manipulation. It can also be defined as a collection of tables, schema, views and
other database objects.

2. What is Database Testing?


It is AKA back-end testing or data testing.
Database testing involves in verifying the integrity of data in the front end with the data
present in the back end. It validates the schema, database tables, columns, indexes, stored
procedures, triggers, data duplication, orphan records, junk records. It involves in updating
records in a database and verifying the same on the front end.

3. What is the difference between GUI Testing and Database Testing?

 GUI Testing is AKA User Interface Testing or Front-end testing


Database Testing is AKA back-end testing or data testing.
 GUI Testing deals with all the testable items that are open to the user to interaction
such as Menus, Forms etc.
Database Testing deals with all the testable items that are generally hidden from the
user.
 The tester who is performing GUI Testing doesn’t need to know Structured Query
Language
The tester who is performing Database Testing needs to know Structured Query
Language
 GUI Testing includes invalidating the text boxes, check boxes, buttons, drop-downs,
forms etc., majorly the look and feel of the overall application
Database Testing involves in verifying the integrity of data in the front end with the
data present in the back end. It validates the schema, database tables, columns,
indexes, stored procedures, triggers, data duplication, orphan records, junk records. It
involves in updating records in a database and verifying the same on the front end.

4. What is a Table in a Database?


A table is a database object used to store records in a field in the form of columns and rows
that holds data.

5. What is a Field in a Database?


A field in a Database table is a space allocated to store a particular record within a table.

6. What is a Record in a Database?


A record (also called a row of data) is an ordered set of related data in a table.

7. What is a column in a Table?


A column is a vertical entity in a table that contains all information associated with a specific
field in a table.

8. What is DBMS?
Database Management System is a collection of programs that enables a user to store,
retrieve, update and delete information from a database.

9. What is RDBMS?
RDBMS stands for Relational Database Management System. RDBMS is a database
management system (DBMS) that is based on the relational model. Data from relational
database can be accessed using Structured Query Language (SQL)

10. What are the popular Database Management Systems in the IT Industry?
Oracle, MySQL, Microsoft SQL Server, PostgreSQL, Sybase, MongoDB, DB2, and
Microsoft Access etc.,
11. What is SQL?
SQL Overview: SQL stands for Structured Query Language. It is an American National
Standard Institute (ANSI) standard. It is a standard language for accessing and manipulating
databases. Using SQL, some of the action we could do are to create databases, tables, stored
procedures (SP’s), execute queries, retrieve, insert, update, delete data against a database.

12. What are the different types of SQL commands?


SQL commands are segregated into following types:

 DDL – Data Definition Language


 DML – Data Manipulation Language
 DQL – Data Query Language
 DCL – Data Control Language
 TCL – Transaction Control Language

View Complete Post

13. What are the different DDL commands in SQL?


DDL commands are used to define or alter the structure of the database.

 CREATE: To create databases and database objects


 ALTER: To alter existing database objects
 DROP: To drop databases and databases objects
 TRUNCATE: To remove all records from a table but not its database structure
 RENAME: To rename database objects

14. What are the different DML commands in SQL?


DML commands are used for managing data present in the database.

 SELECT: To select specific data from a database


 INSERT: To insert new records into a table
 UPDATE: To update existing records
 DELETE: To delete existing records from a table

15. What are the different DCL commands in SQL?


DCL commands are used to create roles, grant permission and control access to the database
objects.

 GRANT: To provide user access


 DENY: To deny permissions to users
 REVOKE: To remove user access

16. What are the different TCL commands in SQL?


TCL commands are used to manage the changes made by DML statements.

 COMMIT: To write and store the changes to the database


 ROLLBACK: To restore the database since the last commit
17. What is an Index?
An index is used to speed up the performance of queries. It makes faster retrieval of data
from the table. The index can be created on one column or a group of columns.

18. What is a View?


A view is like a subset of a table which is stored logically in a database. A view is a virtual
table. It contains rows and columns similar to a real table. The fields in the view are fields
from one or more real tables. Views do not contain data of their own. They are used to restrict
access to the database or to hide data complexity.

CREATE VIEW view _name AS S

CREATE VIEW view_name AS SELECT column_name1, column_name2 FROM


1
table_name WHERE CONDITION;

19. What are the advantages of Views?


Some of the advantages of Views are

1. Views occupy no space


2. Views are used to simply retrieve the results of complicated queries that need to be
executed often.
3. Views are used to restrict access to the database or to hide data complexity.

20. What is a Subquery ?


A Subquery is a SQL query within another query. It is a subset of a Select statement whose
return values are used in filtering the conditions of the main query.

21. What is a temp table?


Ans. A temp table is a temporary storage structure to store the data temporarily.

22. How to avoid duplicate records in a query?


The SQL SELECT DISTINCT query is used to return only unique values. It eliminates all the
duplicated values.
View Detailed Post

23. What is the difference between Rename and Alias?


‘Rename’ is a permanent name given to a table or column
‘Alias’ is a temporary name given to a table or column.

24. What is a Join?


Join is a query, which retrieves related columns or rows from multiple tables.

25. What are the different types of joins?


Types of Joins are as follows:

 INNER JOIN
 LEFT JOIN
 RIGHT JOIN
 OUTER JOIN

View Complete Post

26. What is the difference between an inner and outer join?


An inner join returns rows when there is at least some matching data between two (or more)
tables that are being compared.
An outer join returns rows from both tables that include the records that are unmatched from
one or both the tables.

27. What are SQL constraints?


SQL constraints are the set of rules that enforced some restriction while inserting, deleting or
updating of data in the databases.

28. What are the constraints available in SQL?


Some of the constraints in SQL are – Primary Key, Foreign Key, Unique Key, SQL Not Null,
Default, Check and Index constraint.

29. What is a Unique constraint?


A unique constraint is used to ensure that there are no duplication values in the field/column.

30. What is a Primary Key?


A PRIMARY KEY constraint uniquely identifies each record in a database table. All columns
participating in a primary key constraint must not contain NULL values.

31. Can a table contain multiple PRIMARY KEY’s?

The short answer is no, a table is not allowed to contain multiple primary keys but it allows to
have one composite primary key consisting of two or more columns.

32. What is a Composite PRIMARY KEY?


Composite PRIMARY KEY is a primary key created on more than one column (combination
of multiple fields) in a table.

33. What is a FOREIGN KEY?


A FOREIGN KEY is a key used to link two tables together. A FOREIGN KEY in a table is
linked with the PRIMARY KEY of another table.

34. Can a table contain multiple FOREIGN KEY’s?


A table can have many FOREIGN KEY’s.

35. What is the difference between UNIQUE and PRIMARY KEY constraints?
There should be only one PRIMARY KEY in a table whereas there can be any number of
UNIQUE Keys.
PRIMARY KEY doesn’t allow NULL values whereas Unique key allows NULL values.

36. What is a NULL value?


A field with a NULL value is a field with no value. A NULL value is different from a zero
value or a field that contains spaces. A field with a NULL value is one that has been left blank
during record creation. Assume, there is a field in a table is optional and it is possible to insert
a record without adding a value to the optional field then the field will be saved with a NULL
value.

37. What is the difference between NULL value, Zero, and Blank space?
As I mentioned earlier, Null value is field with no value which is different from zero value
and blank space.
Null value is a field with no value.
Zero is a number
Blank space is the value we provide. The ASCII value of space is CHAR(32).

38. How to Test for NULL Values?


A field with a NULL value is a field with no value. NULL value cannot be compared with
other NULL values. Hence, It is not possible to test for NULL values with comparison
operators, such as =, <, or <>. For this, we have to use the IS NULL and IS NOT NULL
operators.

SELECT column_names FROM t

1 SELECT column_names FROM table_name WHERE column_name IS NULL;


SELECT column_names FROM t

1 SELECT column_names FROM table_name WHERE column_name IS NOT NULL;

39. What is SQL NOT NULL constraint?


NOT NULL constraint is used to ensure that the value in the filed cannot be a NULL

40. What is a CHECK constraint?


A CHECK constraint is used to limit the value that is accepted by one or more columns.

E.g. ‘Age’ field should contain only the value greater than 18.

CREATE TABLE EMP_DETAILS(

CREATE TABLE EMP_DETAILS(EmpID int NOT NULL, NAME VARCHAR (30)


1
NOT NULL, Age INT CHECK (AGE &gt; 18), PRIMARY KEY (EmpID));

41. What is a DEFAULT constraint?


DEFAULT constraint is used to include a default value in a column when no value is supplied
at the time of inserting a record.
42. What is Normalization?
Normalization is the process of table design to minimize the data redundancy. There are
different types of Noramalization forms in SQL.

 First Normal Form


 Second Normal Form
 Third Normal Form
 Boyce and Codd Normal Form

43. What is Stored procedure?


A Stored Procedure is a collection of SQL statements that have been created and stored in the
database to perform a particular task. The stored procedure accepts input parameters and
processes them and returns a single value such as a number or text value or a result set (set of
rows).

44. What is a Trigger?


A Trigger is a SQL procedure that initiates an action in response to an event (Insert, Delete or
Update) occurs. When a new Employee is added to an Employee_Details table, new records
will be created in the relevant tables such as Employee_Payroll, Employee_Time_Sheet etc.,

45. Explain SQL Data Types?


In SQL Server, each column in a database table has a name and a data type. We need to
decide what type of data to store inside each and every column of a table while creating a
SQL table.

View Detailed Post

46. What are the possible values that can be stored in a BOOLEAN data field?
TRUE and FALSE

47. What is the largest value that can be stored in a BYTE data field?
The largest number that can be represented in a single byte is 11111111 or 255. The number
of possible values is 256 (i.e. 255 (the largest possible value) plus 1 (zero), or 28).

48. What are Operators available in SQL?


SQL Operator is a reserved word used primarily in an SQL statement’s WHERE clause to
perform operations, such as arithmetic operations and comparisons. These are used to specify
conditions in an SQL statement.

There are three types of Operators.

1. Arithmetic Operators
2. Comparison Operators
3. Logical Operators

View Detailed Post

49. Which TCP/IP port does SQL Server run?


By default it is 1433
50. List out the ACID properties and explain?
Following are the four properties of ACID. These guarantees that the database transactions
are processed reliably.

 Atomicity
 Consistency
 Isolation
 Durability

51. Define the SELECT INTO statement.


The SELECT INTO statement copies data from one table into a new table. The new table will
be created with the column-names and types as defined in the old table. You can create new
column names using the AS clause.

SELECT * INTO new table FROM

1 SELECT * INTO newtable FROM oldtable WHERE condition;

52. What is the difference between Delete, Truncate and Drop command?
The difference between the Delete, Truncate and Drop command is

 Delete command is a DML command, it is used to delete rows from a table. It can be
rolled back.
 Truncate is a DDL command, it is used to delete all the rows from the table and free
the space containing the table. It cant be rolled back.
 Drop is a DDL command, it removes the complete data along with the table
structure(unlike truncate command that removes only the rows). All the tables’ rows,
indexes, and privileges will also be removed.

53. What is the difference between Delete and Truncate?


The difference between the Delete, and Truncate are

DELETE TRUNCATE
Delete statement is used to delete Truncate statement is used to delete all the rows from
rows from a table. It can be rolled the table and free the space containing the table. It
back. cant be rolled back.
We can use WHERE condition in
We cant use WHERE condition in TRUNCATE
DELETE statement and can delete
statement. So we cant delete required rows alone
required rows
We can delete specific rows using We can only delete all the rows at a time using
DELETE TRUNCATE
Delete is a DML command Truncate is a DDL command
Delete maintains log and performance Truncate maintains minimal log and performance wise
is slower than Truncate faster
We need DELETE permission on We need at least ALTER permission on the table to
DELETE TRUNCATE
Table to use DELETE command use TRUNCATE command

54. What is the difference between Union and Union All command?
This is one of the tricky SQL Interview Questions. Interviewer may ask you this question in
another way as what are the advantages of Union All over Union.

Both Union and Union All concatenate the result of two tables but the way these two queries
handle duplicates are different.

Union: It omits duplicate records and returns only distinct result set of two or more select
statements.
Union All: It returns all the rows including duplicates in the result set of different select
statements.

Performance wise Union All is faster than Union, Since Union All doesn’t remove duplicates.
Union query checks the duplicate values which consumes some time to remove the duplicate
records.

Assume: Table1 has 10 records, Table2 has 10 records. Last record from both the tables are
same.

If you run Union query.

SELECT * FROM Table1


UNION
SELECT * FROM Table2

1 SELECT * FROM Table1


2 UNION
3 SELECT * FROM Table2

Output: Total 19 records

If you run Union query.

SELECT * FROM Table1


UNION ALL
SELECT * FROM Table2

1 SELECT * FROM Table1


2 UNION ALL
3 SELECT * FROM Table2

Output: Total 20 records

Data type of all the columns in the two tables should be same.
55. What is the difference between Having and Where clause?
Where clause is used to fetch data from a database that specifies particular criteria whereas a
Having clause is used along with ‘GROUP BY’ to fetch data that meets particular criteria
specified by the Aggregate functions. Where clause cannot be used with Aggregate functions,
but the Having clause can.

56. What are aggregate functions in SQL?


SQL aggregate functions return a single value, calculated from values in a column. Some of
the aggregate functions in SQL are as follows

 AVG() – This function returns the average value


 COUNT() – This function returns the number of rows
 MAX() – This function returns the largest value
 MIN() – This function returns the smallest value
 ROUND() – This function rounds a numeric field to the number of decimals specified
 SUM() – This function returns the sum

View Detailed Post

57. What are string functions in SQL?


SQL string functions are used primarily for string manipulation. Some of the widely used
SQL string functions are

 LEN() – It returns the length of the value in a text field


 LOWER() – It converts character data to lower case
 UPPER() – It converts character data to upper case
 SUBSTRING() – It extracts characters from a text field
 LTRIM() – It is to remove all whitespace from the beginning of the string
 RTRIM() – It is to remove all whitespace at the end of the string
 CONCAT() – Concatenate function combines multiple character strings together
 REPLACE() – To update the content of a string.

View Detailed Post

Practical SQL Interview Questions:

58. How to add new Employee details in an Employee_Details table with the following
details
Employee_Name: John, Salary: 5500, Age: 29?

INSERT into Employee_Details (E

INSERT into Employee_Details (Employee_Name, Salary, Age) VALUES (‘John’, 5500 ,


1
29);

View Detailed Post


59. How to add a column ‘Salary’ to a table Employee_Details?

ALTER TABLE Employee_Details

1 ALTER TABLE Employee_Details ADD (Salary);

View Detailed Post

60. How to change a value of the field ‘Salary’ as 7500 for an Employee_Name ‘John’ in
a table Employee_Details?

UPDATE Employee_Details set S

1 UPDATE Employee_Details set Salary = 7500 where Employee_Name = ‘John’;

View Detailed Post

61. Write an SQL Query to select all records from the table?

Select * from table_name;

1 Select * from table_name;

View Detailed Post

62. How To Get List of All Tables From A DataBase?


To view the tables available on a particular DataBase

USE TestDB
GO
SELECT * FROM sys.Tables
GO

1 USE TestDB
2 GO
3 SELECT * FROM sys.Tables
4 GO
63. Define SQL Delete statement.
The SQL Delete statement is used to delete records from a table.

DELETE FROM table_name WHE

1 DELETE FROM table_name WHERE some_column=some_value;

View Detailed Post

64. Write the command to remove all Players named Sachin from the Players table.

DELETE from Players WHERE Pl

1 DELETE from Players WHERE Player_Name = ‘Sachin’

65. How to fetch values from TestTable1 that are not in TestTable2 without using NOT
keyword?

--------------
| TestTable1 |
--------------
| 11 |

1 --------------
2 | TestTable1 |
3 --------------
4 | 11 |
5 | 12 |
6 | 13 |
7 | 14 |
8 --------------
--------------
| TestTable2 |
--------------
| 11 |

1 --------------
2 | TestTable2 |
3 --------------
4 | 11 |
5 | 12 |
6 --------------
By using the except keyword

SELECT * FROM TestTable1 EXC

1 SELECT * FROM TestTable1 EXCEPT SELECT * FROM TestTable2;

66. How to get each name only once from an employee table?
By using the DISTINCT keyword, we could get each name only once.

SELECT DISTINCT employee_na

1 SELECT DISTINCT employee_name FROM employee_table;

67. How to rename a column in the output of SQL query?


By using SQL AS keyword

SELECT column_name AS new _

1 SELECT column_name AS new_name FROM table_name;

68. What is the order of SQL SELECT?


Order of SQL SELECT statement is as follows

SELECT, FROM, WHERE, GROUP BY, HAVING, ORDER BY.

69. How to display the current date in SQL.


By using query

SELECT GetDate();

1 SELECT GetDate();

70. Write an SQL Query to find an Employee_Name whose Salary is equal or greater
than 5000 from the below table Employee_Details.
| Employee_Name | Salary|
-----------------------------
| John | 2500 |
| Emma | 3500 |

1 | Employee_Name | Salary|
2 -----------------------------
3 | John | 2500 |
4 | Emma | 3500 |
5 | Mark | 5500 |
6 | Anne | 6500 |
7 -----------------------------

Syntax:

SELECT Employee_Name FROM

1 SELECT Employee_Name FROM Employee_Details WHERE Salary>=5000;

Output:

| Employee_Name | Salary|
-----------------------------
| Mark | 5500 |
| Anne | 6500 |

1 | Employee_Name | Salary|
2 -----------------------------
3 | Mark | 5500 |
4 | Anne | 6500 |
5 -----------------------------
71. Write an SQL Query to find list of Employee_Name start with ‘E’ from the below
table
| Employee_Name | Salary|
-----------------------------
| John | 2500 |
| Emma | 3500 |

1 | Employee_Name | Salary|
2 -----------------------------
3 | John | 2500 |
4 | Emma | 3500 |
5 | Mark | 5500 |
6 | Anne | 6500 |
7 -----------------------------
Syntax:
SELECT * FROM Employee_Deta

1 SELECT * FROM Employee_Details WHERE Employee_Name like 'E%';


Output:
| Employee_Name | Salary|
-----------------------------
| Emma | 3500 |
-----------------------------

1 | Employee_Name | Salary|
2 -----------------------------
3 | Emma | 3500 |
4 -----------------------------
72. Write SQL SELECT query that returns the FirstName and LastName from
Employee_Details table.
SELECT FirstName, LastName F

1 SELECT FirstName, LastName FROM Employee_Details;


73. How to rename a Table?
SP_RENAME TABLE 'SCOREBO

1 SP_RENAME TABLE 'SCOREBOARD', 'OVERALLSCORE'


To rename Table Name & Column Name
sp_rename OldTableName,New
sp_rename 'TableName.OldColu

1 sp_rename OldTableName,NewTableName
2 sp_rename 'TableName.OldColumnName', 'NewColumnName'
74. How to select all the even number records from a table?
To select all the even number records from a table:
Select * from table w here id % 2

1 Select * from table where id % 2 = 0


2
75. How to select all the odd number records from a table?
To select all the odd number records from a table:
Select * from table w here id % 2

1 Select * from table where id % 2 != 0


76. What is the SQL CASE statement?
SQL Case statement allows embedding an if-else like clause in the SELECT statement.

77. Can you display the result from the below table TestTable based on the criteria M,m
as M and F, f as F and Null as N and g, k, I as U

SELECT Gender from TestTable

1 SELECT Gender from TestTable


| Gender |
------------
| M |
| F |

1 | Gender |
2 ------------
3 | M |
4 | F |
5 | NULL |
6 | m |
7 | f |
8 | g |
9 | H |
10 | i |
11 ------------

By using the below syntax we could achieve the output as required.

SELECT Gender,
case
w hen Gender='i' then 'U'
w hen Gender='g' then 'U'

1 SELECT Gender,
2 case
3 when Gender='i' then 'U'
4 when Gender='g' then 'U'
5 when Gender='H' then 'U'
6 when Gender='NULL' then 'N'
7 else upper(Gender)
8 end as newgender from TestTable GROUP BY Gender

78. What will be the result of the query below?

select case w hen null = null the

1 select case when null = null then 'True' else 'False' end as Result;

This query returns “False”. In the above question, we could see null = null is not the proper
way to compare a null value. To compare a value with null, we use IS operator in SQL.

So the correct way is as follows

select case w hen null is null the

1 select case when null is null then 'True' else 'False' end as Result;

79. What will be the result of the query below?

select case w hen null is null the

select case when null is null then 'Queries In SQL Server' else 'Queries In MySQL' end as
1
Result;

This query will returns “Queries In SQL Server”.

80. How do you update F as M and M as F from the below table TestTable?

| Name | Gender |
------------------------
| John | M |
| Emma | F |

1 | Name | Gender |
2 ------------------------
3 | John | M |
4 | Emma | F |
5 | Mark | M |
6 | Anne | F |
7 ------------------------

By using the below syntax we could achieve the output as required.

UPDATE TestTable SET Gender

1 UPDATE TestTable SET Gender = CASE Gender WHEN 'F' THEN 'M' ELSE 'F' END

81. Describe SQL comments?


Single Line Comments: Single line comments start with two consecutive hyphens (–) and
ended by the end of the line
Multi-Line Comments: Multi-line comments start with /* and end with */. Any text between
/* and */ will be ignored.

82. How to get unique records from a table?


By using DISTINCT keyword.

SELECT DISTINCT Col1, Col2 fro

1 SELECT DISTINCT Col1, Col2 from Table1

83. What is the difference between NVL function, IFNULL function, and ISNULL
function?
These three functions work in the same way. These functions are used to replace NULL value
with another value. Oracle developers use NVL function, MySQL developers use IFNULL
function and SQL Server developers use ISNULL function.
Assume, some of the values in a column are NULL.
If you run below statement, you will get result as NULL

SELECT col1 * (col2 + col3) FRO

1 SELECT col1 * (col2 + col3) FROM Table1

Suppose any of the value in col3 is NULL then as I said your result will be NULL.
To overcome this we use NVL() function, IFNULL() function, ISNULL() Function.

ORACLE:

SELECT col1 * (col2 + NVL(col3

1 SELECT col1 * (col2 + NVL(col3,0)) FROM Table1

MySQL:

SELECT col1 * (col2 + IFNULL(c

1 SELECT col1 * (col2 + IFNULL(col3,0)) FROM Table1

Also, you can use the COALESCE() function

SELECT col1 * (col2 + COALESC

1 SELECT col1 * (col2 + COALESCE(col3,0)) FROM Table1

SQL Server:

SELECT col1 * (col2 + ISNULL(c

1 SELECT col1 * (col2 + ISNULL(col3,0)) FROM Table1

Final words, Bookmark this post “SQL Interview Questions For Testers” for future reference.
After reading this post “SQL Interview Questions”, if you find that we missed some
important SQL Server Interview Questions, please comment below we would try to include
those with answers.

Das könnte Ihnen auch gefallen