SQL SERVER – 2008 – Interview Questions and Answers – Part 4

Click here to get free chapters (PDF) in the mailbox

SQL SERVER – 2008 – Interview Questions and Answers Complete List Download

1) General Questions of SQL SERVER
Which command using Query Analyzer will give you the version of SQL server and operating system?

SELECT SERVERPROPERTY ('productversion'), SERVERPROPERTY ('productlevel'), SERVERPROPERTY ('edition')

What is SQL Server Agent?

SQL Server agent plays an important role in the day-to-day tasks of a database administrator (DBA). It is often overlooked as one of the main tools for SQL Server management. Its purpose is to ease the implementation of tasks for the DBA, with its full-function scheduling engine, which allows you to schedule your own jobs and scripts. (Read More Here)

Can a stored procedure call itself or recursive stored procedure? How much level SP nesting is possible?

Yes. Because Transact-SQL supports recursion, you can write stored procedures that call themselves. Recursion can be defined as a method of problem solving wherein the solution is arrived at by repetitively applying it to subsets of the problem. A common application of recursive logic is to perform numeric computations that lend themselves to repetitive evaluation by the same processing steps. Stored procedures are nested when one stored procedure calls another or executes managed code by referencing a CLR routine, type, or aggregate. You can nest stored procedures and managed code references up to 32 levels.

What is Log Shipping?

Log shipping is the process of automating the backup of database and transaction log files on a production SQL server, and then restoring them onto a standby server. Enterprise Editions only supports log shipping. In log shipping the transactional log file from one server is automatically updated into the backup database on the other server. If one server fails, the other server will have the same db and can be used this as the Disaster Recovery plan. The key feature of log shipping is that it will automatically backup transaction logs throughout the day and automatically restore them on the standby server at defined interval.

Name 3 ways to get an accurate count of the number of records in a table?

SELECT * FROM table1


SELECT rows FROM sysindexes WHERE id = OBJECT_ID(table1) AND indid < 2

What does it mean to have QUOTED_IDENTIFIER ON? What are the implications of having it OFF?

When SET QUOTED_IDENTIFIER is ON, identifiers can be delimited by double quotation marks, and literals must be delimited by single quotation marks. When SET QUOTED_IDENTIFIER is OFF, identifiers cannot be quoted and must follow all Transact-SQL rules for identifiers. (Read More Here)

What is the difference between a Local and a Global temporary table?

A local temporary table exists only for the duration of a connection or, if defined inside a compound statement, for the duration of the compound statement.

A global temporary table remains in the database permanently, but the rows exist only within a given connection. When connection is closed, the data in the global temporary table disappears. However, the table definition remains with the database for access when database is opened next time.

What is the STUFF function and how does it differ from the REPLACE function?

STUFF function is used to overwrite existing characters. Using this syntax, STUFF (string_expression, start, length, replacement_characters), string_expression is the string that will have characters substituted, start is the starting position, length is the number of characters in the string that are substituted, and replacement_characters are the new characters interjected into the string. REPLACE function to replace existing characters of all occurrences. Using the syntax REPLACE (string_expression, search_string, replacement_string), where every incidence of search_string found in the string_expression will be replaced with replacement_string.


A PRIMARY KEY constraint is a unique identifier for a row within a database table. Every table should have a primary key constraint to uniquely identify each row and only one primary key constraint can be created for each table. The primary key constraints are used to enforce entity integrity.

What is UNIQUE KEY constraint?

A UNIQUE constraint enforces the uniqueness of the values in a set of columns, so no duplicate values are entered. The unique key constraints are used to enforce entity integrity as the primary key constraints.


A FOREIGN KEY constraint prevents any actions that would destroy links between tables with the corresponding data values. A foreign key in one table points to a primary key in another table. Foreign keys prevent actions that would leave rows with foreign key values when there are no primary keys with that value. The foreign key constraints are used to enforce referential integrity.

What is CHECK Constraint?

A CHECK constraint is used to limit the values that can be placed in a column. The check constraints are used to enforce domain integrity. (Read More Here)

What is NOT NULL Constraint?

A NOT NULL constraint enforces that the column will not accept null values. The not null constraints are used to enforce domain integrity, as the check constraints.

(Read More Here)

How to get @@ERROR and @@ROWCOUNT at the same time?

If @@Rowcount is checked after Error checking statement then it will have 0 as the value of @@Recordcount as it would have been reset. And if @@Recordcount is checked before the error-checking statement then @@Error would get reset. To get @@error and @@rowcount at the same time do both in same statement and store them in local variable. SELECT @RC = @@ROWCOUNT, @ER = @@ERROR

What is a Scheduled Jobs or What is a Scheduled Tasks?

Scheduled tasks let user automate processes that run on regular or predictable cycles. User can schedule administrative tasks, such as cube processing, to run during times of slow business activity. User can also determine the order in which tasks run by creating job steps within a SQL Server Agent job. E.g. back up database, Update Stats of Tables. Job steps give user control over flow of execution. If one job fails, user can configure SQL Server Agent to continue to run the remaining tasks or to stop execution.

What are the advantages of using Stored Procedures?

  • Stored procedure can reduced network traffic and latency, boosting application performance.
  • Stored procedure execution plans can be reused, staying cached in SQL Server’s memory, reducing server overhead.
  • Stored procedures help promote code reuse.
  • Stored procedures can encapsulate logic. You can change stored procedure code without affecting clients.
  • Stored procedures provide better security to your data.

What is a table called, if it has neither Cluster nor Non-cluster Index? What is it used for?

Unindexed table or Heap. Microsoft Press Books and Book on Line (BOL) refers it as Heap. A heap is a table that does not have a clustered index and, therefore, the pages are not linked by pointers. The IAM pages are the only structures that link the pages in a table together. Unindexed tables are good for fast storing of data. Many times it is better to drop all indexes from table and then do bulk of inserts and to restore those indexes after that.

Can SQL Servers linked to other servers like Oracle?

SQL Server can be linked to any server provided it has OLE-DB provider from Microsoft to allow a link. E.g. Oracle has an OLE-DB provider for oracle that Microsoft provides to add it as linked server to SQL Server group

What is BCP? When does it used?

BulkCopy is a tool used to copy huge amount of data from tables and views. BCP does not copy the structures same as source to destination. BULK INSERT command helps to import a data file into a database table or view in a user-specified format.

© Copyright 2000-2009 Pinal Dave. All Rights Reserved. SQLAuthority.com

Reference : Pinal Dave (https://blog.sqlauthority.com)

Database, SQL Constraint and Keys, SQL Function, SQL Index, SQL Scripts, SQL Stored Procedure, SQL Utility
Previous Post
SQL SERVER – 2008 – Interview Questions and Answers – Part 3
Next Post
SQL SERVER – 2008 – Interview Questions and Answers – Part 5

Related Posts

15 Comments. Leave new

  • pl send me on this mail id.

  • Hi Pinal

    Want to clarify, you wrote
    Enterprise Editions only supports log shipping.

    Standard editions also support log shipping (and mirroring) as well

  • I guess there is a type mistake in this, instead of @@ROWCOUNT, @@Recordcount is mentioned.

  • 4 way to get an accurate count of the number of records in a table:
    SELECT COUNT(1) AS number_of_records
    FROM tabla

    • I like your solution though it was kind of already put by Pinal

      SELECT COUNT(1) AS number_of_records
      FROM tabla

  • hi pinal

    This site is very nice…lot of information is there ..
    if it possible plz provide printer friendly option

  • Hi,

    I want to check the expiration date of sql server 2008 evaluation copy. And also want to verify the licenesed version of sql server 2008 standard edition’s validity period.

    please guide me.

    Expecting your reply.


  • pete blackwell
    August 28, 2009 11:24 pm

    Just an idea question if you don’t mind providing your insight.

    We have an application which several regular processing jobs. Each job may call any number of programs which individually update the database.

    Periodically, one of these programs may fail, so we want to put the database back to the state it was before any of the programs in the job ran. Since they are separate programs we can’t use a transaction.

    The only way I know how to do this is to backup the db prior to the job starting, or recover using the a prior backup the and associated log file.

    Is there a way to mark the db as it is at a given time, and then rollback to that point without involvement of a database backup? I was hoping if full logging was on that this would be possible, but I don’t see anything that would help with this.

    If you reply, could you please send reply to my email address (you can post it as well if you wish)?

    Thanks much,
    Pete Blackwell

  • SELECT rows FROM sysindexes WHERE id = OBJECT_ID(table1) AND indid < 2

    Did not work.
    can u guide to me for this?

  • Kadir Evciler
    December 3, 2010 8:05 pm

    I think this is the best way to count of any
    table (It’s in sp_spaceused code)

    SELECT SUM (CASE WHEN (index_id<2) THEN row_count ELSE 0 END) FROM sys.dm_db_partition_stats WHERE object_id = OBJECT_ID('Table')


  • rafi.tdata@gmail.com
    May 28, 2011 8:21 pm

    i have three columns like

    stno stmar1 stmar2 stmar3

    01 65 90 99
    02 90 100 65
    03 03 90 100
    04 99 20 22

    in this table i want max marks of top 3 student information

    please solve this problem

    • Select Top 3 stno, SUM(stmar1 + stmar2 + stmar3) as ‘Total’
      GROUP BY stno
      ORDER BY Total DESC

  • @rafi.tdata
    SELECT MAX(column_name) FROM table_name

  • select top 3
    ,case when (a.stmar1>b.stmar2) and (a.stmar1>b.stmar3) then a.stmar1
    when (a.stmar2>b.stmar1) and (a.stmar2>b.stmar3) then a.stmar2
    when (a.stmar3>b.stmar1) and (a.stmar3>b.stmar2) then a.stmar3
    end as ‘Max Marks’
    from ##test1 a inner join ##test1 b
    on a.stno = b.stno


Leave a ReplyCancel reply

Exit mobile version