SQL SERVER INTERVIEW QUESTIONS 2014- SET 8 By
"Mr.J.Venkatesan Prabu"
KAASHIV INFOTECH
"Mr.J.Venkatesan Prabu"
1. What is the difference between UNION and UNION ALL?
- UNION The UNION command is used to select related
information from two tables, much like the JOIN command. However, when
using the UNION command all selected columns need to be of the same data
type. With UNION, only distinct values are selected.
- UNION ALL The UNION ALL command is
equal to the UNION command, except that UNION ALL selects all values.
The difference between Union and Union all is that Union all will not
eliminate duplicate rows, instead it just pulls all rows from all tables
fitting your query specifics and combines them into a table.
2. What is B-Tree?
The database server uses a B-tree structure to organize
index information. B-Tree generally has following types of index pages or
nodes:
- root node: A root node contains node
pointers to branch nodes which can be only one.
- branch node: A branch node contains
pointers to leaf nodes or other branch nodes which can be two or more.
- leaf nodes: A leaf node contains index
items and horizontal pointers to other leaf nodes which can be many.
3. What is the difference
between lock, block and deadlock?
Lock: DB engine
locks the rows/page/table to access the data which is worked upon according to
the query.
Block: When one process blocks the resources of
another process then blocking happens. Blocking can be identified by using
SELECT * FROM sys.dm_exec_requests where blocked
<> 0
SELECT * FROM master..sysprocesses where blocked
<> 0
Deadlock: When something happens as follows:
Error 1205 is reported by SQL Server for deadlock.
4.What is the meaning of lock escalation and why/how to stop
this?
When the DB engine
would try to lock page first and then it escalates locks to page and then
table. If we understand that whole table would be locked for the processing
thenn this is better to use TABLOCK hint and get complete table blocked. This
is a nice way to avoid the wastage of sql server DB engine processing for lock
escalation. Somewhere you may also need to use TABLOCKX when you want an
exclusive lock on the table in the query.
5. How
to truncate the log in sql server 2008?
BACKUP LOG TestDB WITH TRUNCATE_ONLY is gone. SQL
server doesn’t allow you to truncate the log now otherwise whole purpose of a
DB is defeated. Read articlehttp://mssqlcorruptiontackle.blogspot.com/2010/12/mssql-server-dbcc-loginfo-status-2-log.html to
surprise interviewer with your answer. You have to make sure whether you need
log or not. If you don’t need log then have the recovery model simple instead
of full. If you don’t want the log to be accumulated in some particular bulk logging
then change the recovery model BULK LOGGED for that duration and take one tlog
backup just before and after this change. I shall discuss this later in my
later blog. BACKUP LOG command backs up the t-log and frees the space in the
log file.
6. What
changes in the front end code is needed if mirroring is implemented for the
high availability?
You need to add only FAILOVER PARTNER information in
your front end code. “Data Source=ServerA;Failover Partner=ServerB;Initial
Catalog=AdventureWorks;Integrated Security=True;”.
7. Where
does the copy job runs in the logshipping… Primary or secondary?
Secondary server. This question is basically asked to
find out whether you have a handson work on logshipping or not. I came through
many cases when candidates have mentioned logshipping experience in many
projects and they can’t answer this question. I never selected any candidate if
he/she don’t answer these kind of small questions.
8. What are
the ways to find what code is running for any spid?
Well there are many
ways to do this.
1. find the spid which you want to analyze. An spid is assigned as soon as a
client connection is established with the SQL server. To find the spid you can
run any of the following command:
a) SP_WHO2 ‘ACTIVE’ — This will give you only active spids.
b) SELECT * FROM sys.dm_exec_requests
2. Get the spid
from above two queries and use any of the following query to get what is
happening behind that spid.
a) dbcc inputbuffer()
b) sql2005 and sql2008 – SELECT * FROM sys.dm_exec_sql_text()
c) sql2005 and sql2008 – SELECT * FROM fn_get_sql()
9. When you
get following error? Error 3154: The backup set holds a backup of a database
other than the existing database.
The error comes when you are trying to restore the DB
which already exists. Use WITH REPLACE option to restore the DB with a
different name.
Yes and No. This is tricky question.
If you are using repair option with CHECKDB then you have to have the DB in
single user mode. Following is the method to have your DB in a single user
mode.
Use master
go
sp_dboption dbname, single, true
Following is the
error which you get when you run the DBCC CHECKDB with repair option w\o having
the DB in single user mode.
The same is true for DBCC CHECKDB also.
11. How to
view the error log for any specific instance?
There are many
ways but I prefer following method. Take a scenario when you want to find the
error log when the DB was put in a single user mode.
CREATE TABLE
#Errorlog (Logdate Datetime, Processinfo VARCHAR(20),Text VARCHAR(2000))
INSERT INTO #Errorlog
EXEC xp_readerrorlog
SELECT * FROM #Errorlog
WHERE Text Like ‘%SINGLE%USER%’
Block: When one process blocks the resources of another process then blocking happens. Blocking can be identified by using
SELECT * FROM sys.dm_exec_requests where blocked <> 0
SELECT * FROM master..sysprocesses where blocked <> 0
Deadlock: When something happens as follows: Error 1205 is reported by SQL Server for deadlock.
1. find the spid which you want to analyze. An spid is assigned as soon as a client connection is established with the SQL server. To find the spid you can run any of the following command:
a) SP_WHO2 ‘ACTIVE’ — This will give you only active spids.
b) SELECT * FROM sys.dm_exec_requests
a) dbcc inputbuffer(
b) sql2005 and sql2008 – SELECT * FROM sys.dm_exec_sql_text(
c) sql2005 and sql2008 – SELECT * FROM fn_get_sql(
go
sp_dboption dbname, single, true
EXEC xp_readerrorlog
SELECT * FROM #Errorlog
WHERE Text Like ‘%SINGLE%USER%’
12. What does the NOLOCK query hint do?
Table hints allow you to override the
default behavior of the query optimizer for statements. They are specified in
the FROM clause of the statement. While overriding the query optimizer is not
always suggested, it can be useful when many users or processes are touching
data. The NOLOCK query hint is a good example because it allows you to read
data regardless of who else is working with the data; that is, it allows a
dirty read of data -- you read data no matter if other users are manipulating
it. A hint like NOLOCK increases concurrency with large data stores.
SELECT * FROM table_name (NOLOCK)
Microsoft advises against using
NOLOCK, as it is being replaced by the READUNCOMMITTED query hint. There
are lots more query hints with plenty of information online.
13. What are the new features in SQL
Server 2005 when compared to SQL Server 2000?
There are quite a lot of changes and enhancements in SQL Server
2005. Few of them are listed here :
§ Database
Partitioning
§ Dynamic
Management Views
§ System
Catalog Views
§ Resource
Database
§ Database
Snapshots
§ SQL Server
Integration Services
§ Support
for Analysis Services on a a Failover Cluster.
§ Profiler
being able to trace the MDX queries of the Analysis Server.
§ Peer-toPeer
Replication
§ Database
Mirroring
14. What are
the High-Availability solutions in SQL Server and differentiate them
briefly.
§
Failover Clustering, Database Mirroring, Log Shipping and
Replication are the High-Availability features available in SQL Server. I would
recommend reading this blog of mine which explains the differences between
these 4 features. Comparing the High Availability
Features in SQL Server 2005
15. How do you
troubleshoot errors in a SQL Server Agent Job?
§
Inside SSMS, in Object explorer under SQL Server Agent
look for Job Activity Monitor. The job activity monitor displays the current
status of all the jobs on the instance. Choose the particular job which failed,
right click and choose view history from the drop down menu. The
execution history of the job is displayed and you may choose the execution time
(if the job failed multiple times during the same day). There would information
such as the time it took to execute that Job and details about the error
occurred.
There are quite a lot of changes and enhancements in SQL Server 2005. Few of them are listed here :
Day
|
Programme
|
Day 1
|
BigData (Practical Demos)
|
Day 2
|
Windows 8 App Development (Practical Demos)
|
Day 3
|
Ethical Hacking (Facebook Hack,Server/Website Hacking(20 Attacks)
|
Day 4
|
Cloud Computing (Live Server Demo,Live Pjt Implementation)
|
Day 5
|
CCNA (-Networking-Router Configurations Practical Demo)
|
Day
|
Programme
|
Day 1
|
Embedded System (Embedded Program Designing ,Chip Burning)
|
Day 2
|
Wireless System (Device Designing,Controlling Fans with Wireless Sensors)
|
Day 3
|
CCNA (-Networking-Router Configurations Practical Demo)
|
Day 4
|
Ethical Hacking (Facebook Hack,Server/Website Hacking(20 Attacks)
|
Day 5
|
Matlab (Capture Image,Processing, Animate Images-Practical Demos)
|
Mechanical/Civil Inplant training Schedule
Day
|
Programme
|
Day 1
|
Aircraft Designing
|
Day 2
|
Vehicle Movement in Airports
|
Day 3
|
3D Packaging Designs
|
Day 4
|
3D Modeling
|
Day 5
|
3D Window Shading
|
Shivanantha Building,
X41, 5th Floor,2nd Avenue,
(Near Ayyappan Temple)
Anna Nagar, Chennai = 600040.
No comments:
Post a Comment