SQL Interview
SQL Interview
FROM clause
WHERE clause
GROUP BY clause
HAVING clause
SELECT clause
ORDER BY clause
Normalization
Ranking funtions
Aggregate functions are used to evaluate mathematical calculation and return single values. This can
be calculated from the columns in a table. Scalar
Example -.
Aggregate – max(), count – Calculated with respect to numeric.
Example -.
Lock
Transaction control
Report Generation), T-SQL (Procedures, Functions, Triggers, Cursors, Tables, Views, Indexes, Sub
queries, Joins, SQL Functions)
Transformed unstructured data from various data sources using SSIS Transformations like
Multicast, Conditional Split, Lookup, Merge Join, Union All,
The white box test method mainly deals with the internal structure of a particular database, where
users hide specification details. The white box testing
As the coding error can be detected by testing the white box, it can eliminate internal errors.
To check for the consistency of the database, it selects the default table values.
It helps perform the module testing of database functions, triggers, views, and SQL queries.
The black box test method generally involves interface testing, followed by database integration. It
includes:
Mapping details
Constraints are used to specify the rules concerning data in the table. It can be applied for single or
multiple fields in an SQL table during the creation
of the table or after creating using the ALTER TABLE command. The constraints are:
NOT NULL - Restricts NULL value from being inserted into a column.
DEFAULT - Automatically assigns a default value if no value has been specified for the field.
Data Integrity is the assurance of accuracy and consistency of data over its entire life-cycle and is a
critical aspect of the design, implementation,
and usage of any system which stores, processes, or retrieves data. It also defines integrity
constraints to enforce business rules on the data
16 ot 18 >
A subquery is a query within another query, also known as a nested query or inner query. It is used
to restrict or enhance the data to be queried by the
main query, thus restricting or enhancing the output of the main query respectively. For example,
here we fetch the contact information for students who
FROM myDb.contacts
WHERE roll_no IN (
SELECT roll_no
FROM myDb.students
A correlated subquery cannot be considered as an independent query, but it can refer to the column
in a table listed in the FROM of the main query.
A non-correlated subquery can be considered as an independent query and the output of the
subquery is substituted in the main query.
professors, workers, departments, and projects can be referred to as entities. Each entity has some
associated properties that provide it an identity.
Relationships: Relations or links between entities that have something to do with each other. For
example - The employee's table in a company's database
Such procedures are stored in the database data dictionary. The sole disadvantage of stored
procedure is that it can be executed nowhere
except in the database and occupies more memory in the database server. It also provides a sense of
security and functionality as users who can't
access the data directly can be granted access via stored procedures.
A stored procedure that calls itself until a boundary condition is reached, is called a recursive stored
procedure. This recursive
function helps the programmers to deploy the same set of code several times as and when required.
Some SQL programming languages limit the recursion
depth to prevent an infinite loop of procedure calls from causing a stack overflow, which slows
down the system and may lead to system crashes.
Transactions allow you to group SQL commands into a single unit. The transaction begins with a
certain task and ends when all tasks within it are complete.
The transaction completes successfully only if all commands within it complete successfully. The
whole thing fails if one command fails.
The BEGIN TRANSACTION, ROLLBACK TRANSACTION, and COMMIT TRANSACTION statements are
used to work with transactions. A group of tasks starts with the
begin statement. If any problems occur, the rollback command is executed to abort. If everything
goes well, all commands are permanently executed via
the commit statement.
A clustered index affects the way the rows of data in a table are stored on disk. When a clustered
index is used, rows are stored in sequential order
according to the index column value; for this reason, a table can contain only one clustered index,
which is usually used on the primary index value.
A nonclustered index does not affect the way data is physically stored; it creates a new object for the
index and stores the column(s) designated for
indexing with a pointer back to the row containing the indexed values.
You can think of a clustered index as a dictionary in alphabetical order, and a nonclustered index as a
book's index.
Basically, the Database Consistency Checker (DBCC) provides a set of commands (many of which are
undocumented) to maintain databases -- maintenance,
validation, and status checks. The syntax is DBCC followed by the command name. Here are three
examples:
Which component of the SQL Server Engine is responsible for generating an Execution Plan for the
submitted query?
A: The SQL Server Query Optimizer is responsible for creating the most efficient plan to execute the
provided query
A: The SQL Server Execution Plan will be stored in the Plan Cache memory storage
What is the goal behind storing the Execution Plan for the query in the Plan Cache?
A: The process of generating the most optimal execution plan is an expensive process. Instead of
creating a new Execution Plan each time a
new query is submitted, the SQL Server Query Optimizer will search in the plan cache storage for an
existing Execution Plan for the submitted
query and use it. If there is no plan that can be used for that query, the Query Optimizer will create a
new plan, taking more time to execute that query.
The Execution plans reuse mechanism is very helpful when there are stored procedures executed
frequently
Q5: What are the main types of Execution Plans that you can generate for a T-SQL query and what is
the difference between these two types?
A: The Estimated Execution Plan. It is the plan that is generated by parsing the submitted query as an
estimate of how the query will be executed,
The Actual Execution Plan, that is generated by executing the submitted query, displaying the actual
steps that followed while executing the query
Answer: A clustered index is an index that rearranges the table in the order of the index itself. Its
leaf nodes contain data pages. A table can have only one clustered index.
A non-clustered index is an index that does not re-arrange the table in the order of the index itself.
Its leaf nodes contain index rows instead of data pages. A table can have many non-clustered
indexes.
Q #3) List the different index configurations possible for a table?
No indexes
A clustered index
A non-clustered index
Q7: How could the Execution Plan help in identifying the missing index for a specific query?
A: Based on the available SQL Server statistics and the workload performed on the SQL Server, the
SQL Server Query Optimizer will provide us with a
suggested index, that may improve the performance of the submitted query in a calculated
percentage. So, it will display that index as a
For more information, check How to Analyze SQL Execution Plan Graphical Components
A: The correct way to read the SQL Execution Plan is to start from the right side of the plan to the left
side and from the top to the bottom,
and the most left SELECT operator contains the final result of the submitted query
Q9: How could we use the arrow between the Execution Plan operators to read the plan?
A: You can make use of the arrows that are connecting the operators in identifying the direction and
the amount of the data passed between the
Execution Plan operators. In addition, the arrow is an indication of how much data passed
between the operators
A: This depends on the statistics. If it is updated, the results should be the same. You need the
Estimated SQL Execution Plan in case the query
will take a long time to execute and you need to troubleshoot it
A: The Aggregate Operator is mainly used to calculate the aggregate expressions in the submitted
query, by grouping the values of an aggregated column.
The aggregate expressions include the MIN, MAX, COUNT, AVG, SUM operations
A: The Compute Scalar operator is used to perform scalar computation operations in order to
calculate a new value from the existing row value
CDC Vs CT
> same data schema, same table > data is transferring > how to validate and determine what are all
records to be transferred > Delta