SQL Interview Questions For Experienced

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 5

SQL INTERVIEW QUESTIONS FOR EXPERIENCED

What is the difference between CHAR and VARCHAR2 datatype in


SQL?
Both Char and Varchar2 are used for characters datatype but varchar2 is
used for character strings of variable length whereas Char is used for
strings of fixed length. For example, char(10) can only store 10
characters and will not be able to store a string of any other length
whereas varchar2(10) can store any length i.e 6,8,2 in this variable.
What do you understand by query optimization?
The phase that identifies a plan for evaluation query which has the least
estimated cost is known as query optimization.
What is the difference between DROP and TRUNCATE
commands?
DROP command removes a table and it cannot be rolled back from the
database whereas TRUNCATE command removes all the rows from the
table.
What do you mean by “Trigger” in SQL?
Trigger in SQL is are a special type of stored procedures that are defined
to execute automatically in place or after data modifications. It allows
you to execute a batch of code when an insert, update or any other query
is executed against a specific table.
. What is the difference between cross join and natural join?
The cross join produces the cross product or Cartesian product of two
tables whereas the natural join is based on all the columns having the
same name and data types in both the tables.
What is the need for group functions in SQL?
Group functions work on the set of rows and return one result per group.
Some of the commonly used group functions are: AVG, COUNT, MAX,
MIN, SUM, VARIANCE.
How can you insert NULL values in a column while inserting the
data?
NULL values in SQL can be inserted in the following ways:
Implicitly by omitting column from column list.
Explicitly by specifying NULL keyword in the VALUES clause
What do you mean by recursive stored procedure?
Recursive stored procedure refers to a stored procedure which calls by
itself until it reaches some boundary condition. This recursive function
or procedure helps the programmers to use the same set of code n
number of times.
List the ways in which Dynamic SQL can be executed?
Following are the ways in which dynamic SQL can be executed:

Write a query with parameters.


Using EXEC.
Using sp_executesql.
What are aggregate and scalar functions?
Aggregate functions are used to evaluate mathematical calculation and
returns a single value. These calculations are done from the columns in a
table. For example- max(),count() are calculated with respect to
numeric.
Scalar functions return a single value based on the input value. For
example – UCASE(), NOW() are calculated with respect to string.
How can you select unique records from a table?
You can select unique records from a table by using the DISTINCT
keyword.
Select DISTINCT studentID from Student
Using this command, it will print unique student id from the table
Student.
How can you fetch first 5 characters of the string?
There are a lot of ways to fetch characters from a string. For example:
Select SUBSTRING(StudentName,1,5) as studentname from student
What do you mean by Collation?
Collation is defined as a set of rules that determine how data can be
sorted as well as compared. Character data is sorted using the rules that
define the correct character sequence along with options for specifying
case-sensitivity, character width etc.
What are the different types of Collation Sensitivity?
Following are the different types of collation sensitivity:
Case Sensitivity: A and a and B and b.
Kana Sensitivity: Japanese Kana characters.
Width Sensitivity: Single byte character and double-byte character.
Accent Sensitivity.
What is Auto Increment in SQL?
Autoincrement keyword allows the user to create a unique number to get
generated whenever a new record is inserted into the table.
This keyword is usually required whenever PRIMARY KEY in SQL is
used.
AUTO INCREMENT keyword can be used in Oracle and IDENTITY
keyword can be used in SQL SERVER.

What is a Datawarehouse?
Datawarehouse refers to a central repository of data where the data is
assembled from multiple sources of information. Those data are
consolidated, transformed and made available for the mining as well as
online processing. Warehouse data also have a subset of data called Data
Marts.
What are the different authentication modes in SQL Server? How
can it be changed?
Windows mode and Mixed Mode – SQL and Windows. You can go to
the below steps to change authentication mode in SQL Server:

Click Start> Programs> Microsoft SQL Server and click SQL Enterprise
Manager to run SQL Enterprise Manager from the Microsoft SQL
Server program group.
Then select the server from the Tools menu.
Select SQL Server Configuration Properties, and choose the Security
page.

You might also like