SQL Server Interview Question
SQL Server Interview Question
● Windows Mode
● Mixed Mode
Modes can be changed by selecting the tools menu of SQL Server configuration
properties and choose security page.
SQL Profiler is a tool which allows system administrator to monitor events in the SQL
server. This is mainly used to capture and save data about each event of a file or a table
for analysis.
SQL Server supports recursive stored procedure which calls by itself. Recursive stored
procedure can be defined as a method of problem solving wherein the solution is arrived
repetitively. It can nest up to 32 levels.
@Number Integer,
AS
IF @Number != 1
BEGIN
END
ELSE
BEGIN
SELECT @RetVal = 1
END
RETURN
GO
4. What are the differences between local and global temporary tables?
● Local temporary tables are visible when there is a connection, and are deleted
when the connection is closed.
● Global temporary tables are visible to all users, and are deleted when the
connection that created it is closed.
A CHECK constraint can be applied to a column in a table to limit the values that can be
placed in a column. Check constraint is to enforce integrity.
So CHECK constraint set the limit of “Name” with 100 chars. If more than 100 chars are
comes then it Throws Error → string or binary data would be truncated when trying to
insert.
A sub-query is a query which can be nested inside a main query like Select, Update,
Insert or Delete statements. This can be used when expression is allowed. Properties of
sub query can be defined as
SELECT column-names
FROM table-name1
WHERE value IN (SELECT column-name
FROM table-name2
WHERE condition)
FLOOR function is used to round up a non-integer value to the previous least integer.
Example is given FLOOR(6.7) Output : 6
What is a Trigger?
Triggers are used to execute a batch of SQL code when insert or update or delete
commands are executed against a table. Triggers are automatically triggered or
executed when the data is modified. It can be executed automatically on insert, delete
and update operations.
● Insert
● Delete
● Update
● Instead of
IDENTITY column is used in table columns to make that column as Auto incremental
number or a surrogate key.
Bulkcopy is a tool used to copy large amount of data from Tables. This tool is used to
load large amount of data in SQL Server.
23. What are the differences between Stored Procedure and the dynamic SQL?
Collation is defined to specify the sort order in a table. There are three types of sort
order –
1. Case sensitive
2. Case Insensitive
3. Binary
29. Which SQL server table is used to hold the stored procedure scripts?
Sys.SQL_Modules is a SQL Server table used to store the script of stored procedure.
Name of the stored procedure is saved in the table called Sys.Procedure.
= is used to assign one value or variable to another variable. == is used for comparing
two strings or numbers. === is used to compare only string with the string and number
with numbers.
ISNULL function is used to check whether value given is NULL or not NULL in sql
server. This function also provides to replace a value with the NULL.
FOR clause is mainly used for XML and browser options. This clause is mainly used to
display the query results in XML format or in browser.
For SQL Server 2008 100 Index can be used as maximum number per table. 1
Clustered Index and 999 Non-clustered indexes per table can be used in SQL Server.
Every statement between BEGIN and COMMIT becomes persistent to database when
the COMMIT is executed. Every statement between BEGIN and ROOLBACK are
reverted to the state when the ROLLBACK was executed.
Varchar and nvarchar are same but the only difference is that nvarhcar can be used to
store Unicode characters for multiple languages and it also takes more space when
compared with varchar.
run time? Stored Procedure can be executed with the help of keyword
Duplicate rows can be deleted using CTE and ROW NUMER feature of
SQL Server. 41. Where are SQL Server user names and passwords
User Names and Passwords are stored in sys.server_principals and sys.sql_logins. But
passwords are not stored in normal text.
Both are same but GETDATE can give time till milliseconds and SYSDATETIME can
give precision till nanoseconds. SYSDATE TIME is more accurate than GETDATE.
43. How data can be copied from one table to another table?
This command is used to create a new table and its structure and data can be copied
from existing table.
CDC is abbreviated as Change Data Capture which is used to capture the data that has
been changed recently. This feature is present in SQL Server 2008.
49. What are the methods used to protect against SQL injection
injection attack:
Filtered Index is used to filter some portion of rows in a table to improve query
performance, index maintenance and reduces index storage costs. When the index is
created with WHERE clause, then it is called Filtered Index
● Sql Query Interview Question Link - number of join, row number , union,
union all question
●