0% found this document useful (0 votes)
32 views9 pages

SQL Interview

The document discusses various SQL concepts and techniques including: 1) The sequence that SQL clauses are processed, aggregate and scalar functions, pattern matching using the LIKE operator, and functions for string handling. 2) How to fetch the first 5 characters of a string using SUBSTRING or LEFT, and write queries to display even and odd records from a table using ROW_NUMBER. 3) The differences between clustered and nonclustered indexes, transactions, constraints, data integrity, entities and relationships in databases.
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
Download as docx, pdf, or txt
0% found this document useful (0 votes)
32 views9 pages

SQL Interview

The document discusses various SQL concepts and techniques including: 1) The sequence that SQL clauses are processed, aggregate and scalar functions, pattern matching using the LIKE operator, and functions for string handling. 2) How to fetch the first 5 characters of a string using SUBSTRING or LEFT, and write queries to display even and odd records from a table using ROW_NUMBER. 3) The differences between clustered and nonclustered indexes, transactions, constraints, data integrity, entities and relationships in databases.
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1/ 9

In what sequence SQL statement are processed

FROM clause

WHERE clause

GROUP BY clause

HAVING clause

SELECT clause

ORDER BY clause

FETCH FIRST clause

Normalization

Latest and Most recent by calander

Index rebuild vs reorganize

Ranking funtions

Write a Query to display even records from the table?

SELECT * FROM ( SELECT *, ROW_NUMBER() OVER (ORDER BY student_no) AS ‘ Row_ID’ FROM


student)

WHERE row_id %2=0

Write a Query to display odd records from student table?

SELECT * FROM (SELECT *, ROW_NUMBER() OVER (ORDER BY student_no) AS Row_ID FROM


student)

WHERE row_id %2!=0

What are aggregate and scalar functions?

Aggregate functions are used to evaluate mathematical calculation and return single values. This can
be calculated from the columns in a table. Scalar

functions return a single value based on the input value.

Example -.
Aggregate – max(), count – Calculated with respect to numeric.

Scalar – UCASE(), LCASE(), NOW() – Calculated with respect to strings.

What is the command used to fetch first 5 characters of the string?

There are many ways to fetch first 5 characters of the string -.

Select SUBSTRING(StudentName,1,5) as studentname from student

Select LEFT(Studentname,5) as studentname from student

Which operator is used in query for pattern matching?

LIKE operator is used for pattern matching, and it can be used as -.

% – Matches zero or more characters.

_(Underscore) – Matching exactly one character.

Example -.

Select * from Student where studentname like 'a%'

Select * from Student where studentname like 'ami_'

Table types CTE & recursive CTE,table variable, temp table

Lock

String hadling funcitons

Transaction control

Merge statement > multiple rows matching source vs destination


 Expertise in SQL (Tables, Views, Indexes, sub queries, joins, Constraints, UNION Operators,
Aggregate Functions, SQL Performance Tuning,

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,

Sort, Aggregation, and Derived Column.

Explain database white box testing and black box testing.

The white box test method mainly deals with the internal structure of a particular database, where
users hide specification details. The white box testing

method involves the following:

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.

This method verifies the referential integrity rule.

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

Verification of the incoming data

Verification of the outgoing data from the other query functions

7. What are Constraints in SQL?

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.

CHECK - Verifies that all values in a field satisfy a condition.

DEFAULT - Automatically assigns a default value if no value has been specified for the field.

UNIQUE - Ensures unique values to be inserted into the field.


INDEX - Indexes a field providing faster retrieval of records.

PRIMARY KEY - Uniquely identifies each record in a table.

FOREIGN KEY - Ensures referential integrity for a record in another table.

What is Data Integrity?

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

when it is entered into an application or a database

16 ot 18 >

What is a Subquery? What are its types?

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

have enrolled for the maths subject:

SELECT name, email, mob, address

FROM myDb.contacts

WHERE roll_no IN (

SELECT roll_no

FROM myDb.students

WHERE subject = 'Maths');

There are two types of subquery - Correlated and Non-Correlated.

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.

What are Entities and Relationships?


Entity: An entity can be a real-world object, either tangible or intangible, that can be easily
identifiable. For example, in a college database, students,

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

can be associated with the salary table in the same database.

What is a Stored Procedure?

A stored procedure is a subroutine available to applications that access a relational database


management system (RDBMS).

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.

What is a Recursive Stored Procedure?

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.

How are transactions used?

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.

What is the difference between a clustered and a nonclustered index?

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.

What are DBCC commands?

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:

DBCC CHECKALLOC -- Check disk allocation consistency.

DBCC OPENTRAN -- Display information about recent transactions.

DBCC HELP -- Display Help for DBCC commands.

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

Where will the generated Execution Plan be stored?

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,

without being executed

The Actual Execution Plan, that is generated by executing the submitted query, displaying the actual
steps that followed while executing the query

Q6: What are the three Execution Plan formats?

A: Graphical Format, Text Format and XML Format

Q #1) Which TCP/IP port does SQL Server run on?

Answer: By default SQL Server runs on port 1433.

Q #2) What is the difference between clustered and non-clustered index?

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?

Answer: A table can have one of the following index configurations:

No indexes

A clustered index

A clustered index and many non-clustered indexes

A non-clustered index

Many non-clustered indexes

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

recommendation with the query plan in green

For more information, check How to Analyze SQL Execution Plan Graphical Components

Q8: What is the correct way of reading the Execution Plan?

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

Q10: Can the Estimated SQL Execution Plan result be trusted?

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

Q12: What is the Aggregate operator in the Execution Plan?

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

Q13: What is the Compute Scalar operator in the Execution Plan?

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

You might also like