Tab Pages

Monday, February 28, 2011

SQL Server DBA interview questions



SQL Server DBA interview questions
What are the steps to take to improve performance of a poor performing query?
  • Maximum use of indexes, stored procures should be done.
  • Avoid excessive use of complicated joins and cursors.
  • Avoid using conditional operators using columns of different tables.
  • Make use of computed columns and rewriting the query.

What is a deadlock and what is a live lock? How will you go about resolving deadlocks?
A deadlock occurs when two or more processes waits for a resource that is acquired by or is under the control of another process. A live lock is similar to a deadlock except the process states keeps changing. The result of such state is that none of the process will be complete.
Deadlock detection finds and resolves deadlocks. A WFG strategy is followed. WFG is wait for graph. In WFG, processes are represented by nodes while dependencies are represented by edges. Thus, if process A is waiting for a resource held by process B, there is an edge in the WFG from the node for process A to the node for process B. a cycle is this graph is a deadlock. WFG constantly checks for cycles or when a process is blocked and adds a new edge to the WFG.   When a cycle is found, a victim is selected and aborted.

What is blocking and how would you troubleshoot it?
Blocking occurs when two or more rows are locked by one SQL connection and a second connection to the SQL server requires a conflicting on lock on those rows. This results in the second connection to wait until the first lock is released.
Troubleshooting blocking:
  • SQL scripts can be written that constantly monitor the state of locking and blocking on SQL Server
  • The common blocking scenarios must be identified and resolved.
  • The scripts output must be checked constantly,
  • The SQL profilers data must be examined regularly to detect blocking.
Explain the different types of BACKUPs available in SQL Server.
Complete database backup: This type of backup will backup all the information in the database. Used most commonly for disaster recovery and takes the longest time to backup.
Differential databse backup: The database is divided into partitions that have been modified since last complete backup. Most suitable for large databases. The most recent differential backup contains the changes from previous backups.
Transaction log backups: Backups only the changes logged in the transaction log. The transaction log has all changes logged about a database. Once the changes are accommodated on the database, the log is truncated or backed up.
File/File Group backups: used to recover individual files or file groups. Each filegroup can be individually backed up. This helps in recovery only the required file or filegroup for disaster recovery.

What is database isolation in SQL Server?
Isolation in database defines how and when changes made by one transaction can be visible to other transactions. Different isolation levels are:
  • Serializable
  • Repeatable read
  • Read committed
  • Read uncommitted

What is a Schema in SQL Server 2005? Explain how to create a new Schema in a Database?
A schema is used to create database objects. It can be created using CREATE SCHEMA statement. The objects created can be moved between schemas. Multiple database users can share a single default schema.
CREATE SCHEMA sample;
Table creation
Create table sample.sampleinfo
{
id int primary key,
name varchar(20)
}

Explain how to create a Scrollable Cursor with the SCROLL Option.
Using the SCROLL keyword while declaring a cursor allows fetching of rows in any sequence
Example:
DECLARE employee_curs SCROLL CURSOR FOR SELECT * FROM employee;
The active set of the cursor is stored can be accessed in any order without the need of opening and closing the cursor. The Scroll cursors can be set for select and function cursors but not insert or update statements.

Explain how to create a Dynamic Cursor with the DYNAMIC Option.
When a cursor is declared as DYNAMIC, the cursor reflects all changes made to the base tables as the cursor is scrolled around.
Declare cursor_name cursor
[ STATIC | KEYSET | DYNAMIC | FAST_FORWARD ]
FOR select_statement
The dynamic option does not support ABSOLUTE FETCH.

What are database files and filegroups?

Database files are used for mapping the database over some operating system files. Data and log information are separate. SQL server database has three types of database files:

Primary: starting point of a database. It also points to other files in database. Extension: .mdf
Secondary: All data files except primary data file is a part of secondary files. Extension: .ndf
Log files: All log information used to recover database. Extension: .ldf


Describe in brief Databases and SQL Server Databases Architecture.

SQL Server consists of a set of various components which fulfill data storage and data analysis needs for enterprise applications. Database architecture: All the data is stored in databases which is organized into logical components visible to the end users. It’s only the administrator who needs to actually deal with the physical storage aspect of the databases, whereas users only deal with database tables.

Every SQL Server instance has primarily 4 system database i.e. master, model, tempdb and msdb. All other databases are user created databases as per their needs and requirements.

A single SQL Server instance is capable of handling thousands of users working on multiple databases.



SQL Server Performance Tuning


SQL Server Performance Tuning
SQL Server Performance Tuning is a very challenging subject that requires expertise in Database Administration and Database Development. We provides specialized health check service where we dive deep into your SQL Server configurations and potential issues and propose solutions to resolve your issues. We also provide maintenance scripts and train your team on few of the key areas in order to empower them to understand and tune the systems in the future. We also provide Hands-On sessions for tuning your queries and propose solutions for your deadlock situations.
Index Analysis and Extremely Effective Index Created
Indexes are considered valuable for performance improvements. We analyze all your indexes to identify non-performing indexes and missing indexes that can improve performance. We provide you with the necessary action items and scripts that can be used for analyzing future workloads and index performance.
Server/Instance Level Configuration Check
We review all the SQL Server/Instance Level settings of the server and tune it based on system workload. We also provide a quick tutorial to your DBA on these setting changes and reasons.
I/O distribution Analysis for Performance
We analyze the I/O of your system and decide the best distribution for the I/O load. We also perform object level analysis and do performance tuning at table level. Our goal is to reduce I/O performance bottlenecks and suggest optimal setting for read and write database. This is especially critical for databases that need to sustain heavy updates during peak usage hours.
SQL Server Resource Wait Stats Analysis
Wait Stat Analysis is very crucial for optimizing databases, but is often overlooked due to lack of understanding. We perform advanced resource wait statistics analysis and provide you with suggestion to optimize your database server. We train your DBA to enable them to perform this analysis in the future.
TempDB Space Review
We review the size and usage of your TempDB database and provide suggestions for tuning it.
Database Files (MDF, NDF) and Log File Inspection
We review all the files and filegroups of each of your databases and analysis them to identify any object or files that are causing bottlenecks. Once we identify the issue, we recommend the best practice to resolve the bottlenexk and avoid it in the future. We also provide your DBA required knowledge for setting up future databases using optimal settings
Fragmentations and Defragmentations
We identify the optimal settings of your database files and tables to reduce fragmentation and provide you scripts to help you reduce them.
DBCC Best Practices Implementations
This is a quick tutorial for DBAs covering some of the common and useful DBCC commands. The session covers the usage of DBCC FREEPROCCACHE, DBCC SRHINKDATABASE, DBCC SHRINKFILE, DBCC DROPCLEANBUFFER, DBCC REINDEX, as well as the usage of few system stored procedures like SP_UPDATESTATS. If you are currently using any of the above mentioned and a few other DBCC maintenance task commands, this session will educate you on the proper usage of the same.
Query Tuning Hands-On
We take any 3 of your preferred queries (or stored procedures) and try to improve the performance while teaching you the skills required to tune other similar queries.
You will receive a simple written explanation and suggestions of all our findings from the health check as well as our recommendations. We will also provide you with all the necessary scripts to enable you to detect potential issues early and resolve them in-house.
If you need this service drop me an email at pinal “at” SQLAuthority.com. If you specify SQLAuthority.com in Title, you will avail special discount in overall rates.

SQL Server Reporting Services: FAQs


1. Difference between Logical Page an Physical Page in SSRS.
Ø  Logical page breaks are page breaks that you insert before or after report items or groups. Page breaks help to determine how the content is fitted to a report page for optimal viewing when rendering or exporting the report.
The following rules apply when rendering logical page breaks:
  • Logical page breaks are ignored for report items that are constantly hidden and for report items where the visibility is controlled by clicking another report item.
  • Logical page breaks are applied on conditionally visible items if they are currently visible at the time the report is rendered.
  • Space is preserved between the report item with the logical page break and its peer report items.
  • Logical page breaks that are inserted before a report item push the report item down to the next page. The report item is rendered at the top of the next page.
  • Logical page breaks defined on items in table or matrix cells are not kept. This does not apply to items in lists.
2. How to configure SSRS for Disaster recovery.
Depends on daily backup technique.
3. Describe the role of Encrpytion key in Report Server Configuration manager.
A.To encrypt credentials, connection strings. Can be taken backup and restore when required from configuration manager.
4. User want only to display only pdf as export option in report Manager .. Describe Steps to perform this .
A.using System.Reflection;
using Microsoft.Reporting.WebForms;
public void DisableUnwantedExportFormats()
{
foreach(RenderingExtension extension in serverReport.ListRenderingExtensions())
{
if(extension.Name == "XML" || extension.Name == "IMAGE"
|| extension.Name == "MHTML")
ReflectivelySetVisibilityFalse(extension);
}
}

5. Name and Describe few console utilities for SSRS.
RSConfig.exe
Configuration of connection properties between the Report Server to the repository database.
RSKeyMgmt.exe
Management of encryption keys via command-line
RS.exe
Scripting of report deployment
6. Name few Endpoints exposed by SSRS 2008.
o   Management Endpoints
o   Execution Endpoint
o   SharePoint Proxy Endpoints
7. How can you access the Code in You report. Describe the Static and intance based method with example.
A. Static methods within a custom assembly are available globally within the report. You can access static methods in expressions by namespace, class, and method name
The following example calls the method ToGBP, which converts the StandardCost field value from dollar to pounds sterling:
=CurrencyConversion.DollarCurrencyConversion.ToGBP(Fields!StandardCost.Value)
Instance-based methods are available through a globally defined Code member. You access these by referring to the Code member, and then the instance and method name. The following example calls the instance method ToEUR which converts the StandardCost field value from dollar to euro:
=Code.m_myDollarCoversion.ToEUR(Fields!StandardCost.Value)
8. how to add custom Assemblies to Report.
1.      On the Report menu, click Report Properties
2.       On the References tab, do the following:
a.       In References, click the add (...) button and then select or browse to the assembly from the Add Reference dialog box.
b.       In Classes, type name of the class and provide an instance name to use within the report.
9. What is Linked Report.
A> A linked report is a report server item that provides an access point to an existing report. Conceptually, it is similar to a program shortcut that you use to run a program or open a file.
10. What are different types of roles provided by SSRS?
A.1.      Browser
2.      Content Manager
3.      My Reports
4.      Publisher
5.      Report Builder
11. Describe different Processing Modes offered by SSRS.
Local Processing Mode:
Processes reports in the client application.
Remote Processing Mode:
Renders server reports that are processed on a SQL Server Reporting Services report server.
12. When to Use Null Data driven Subscription?
Create a data-driven subscription that uses the Null Delivery Provider. When you specify the Null Delivery Provider as the method of delivery in the subscription, the report server targets the report server database as the delivery destination and uses a specialized rendering extension called the null rendering extension. In contrast with other delivery extensions, the Null Delivery Provider does not have delivery settings that you can configure through a subscription definition.
13. What Factors need to take into consideration while designing a international report (Localization).
14. What are different option to deploy report from Dev to Prod.
Ø  From Solution Explorer by giving Target Sever URL
Ø  Uploading the .rdl from Report manager.
15. What are the new Controls / Features  added in SSRS 2008 / SSRS 2008 R2
16. How can you monitor the report Usage.
You can query theReportServer database for this information as follows:

SELECT
ex.UserName, ex.Format, ex.TimeStart, cat.Name,
ex.Parameters,
CONVERT(nvarchar(10), ex.TimeStart, 101) AS rundate
FROM ExecutionLog AS ex, Catalog AS cat
where ex.ReportID = cat.ItemID
ORDER BY ex.TimeStart DESC

 17. How can you add a new report User to report manager.
18. How can you create the dynamaic Datasource. Can a Shared Datasource be Dynamic?
 19. A report is Performing poorly . What steps you would take to troubleshoot the Issue.
20. Write an Expression to perform a Division of two Integers fields and  to avoid NAN error.
21. have you ever used Rank, Dense Rank Ntile, CTE and Pivot..
22. Is SSRs 2008 dependent on IIS? if not how it perform the operations.
Although, in SSRS 2008, the Report Server configuration Manager configures the majority of settings, it is also possible to use command-line utilities. This can be useful for configuring SSRS 2008 scale-out deployments, sharing encryption keys and so on. The three main command lines are listed here, and this is then followed by details of the available parameters for each command.
RSConfig.exe
Configuration of connection properties between the Report Server to the repository database.
RSKeyMgmt.exe
Management of encryption keys via command-line
RS.exe
Scripting of report deployment
RSConfig Details

Here are the parameters for RSConfig.exe. Note that you will need to use quotation marks if any of the parameters e.g. database name contain a space:
Parameter
Description
/m
Remote server name; default is localhost
/i
Instance name, if a named instance is used
/c
Connection
/s
Database server name
/d
Database name
/a
Authentication method; either Windows or SQL authentication
/u
Username
/p
Password
/t
Trace log output goes to SSRS
/e
Unattended report execution; also needs /u and /p
RSKeyMgmt Details

Here are the parameters for RSKeyMgmt.exe:
Parameter
Description
/a
Restored and overwritten
/d
Deletes the key and encrypted data
/e
Extract key for backup to a file
/f
Filepath parameter for /a or /e parameter
/i
Named instance
/p
Password
/t
Trace log output goes to SSRS
/j
Adds a remote SSRS instance to the local Report Server database. /m (report server) and /n (instance name) are used with this parameter; /i refers to the local named instance
/r
Removes an SSRS instance from the scale-out deployment; use the GUID Installation ID to specify the instance
/u
Account name of the remote SSRS instance (optional)
/v
Password for the local admin of the remote SSRS instance (optional)
/m
Remote server name for /j
/n
Remote instance name for /j
RS Details

Here are the parameters for RS.exe, which is used for deploying reports:
Parameter
Description
/i
Input .rss file for execution
/s
URL to SSRS virtual directory
/u
Username
/p
Password
/l
Timeout in seconds; default is 60 seconds
/b
Batch command execution
/e
SOAP endpoint used; default is mgmt2005
/v
Global Variable mapping
/t
Trace log output goes to SSRS
To add this post to Twitter, please click here.

 What can SQL Server Reporting Services do?

SQL Server Reporting Service is one of the server-based software systems that generate reports developed by Microsoft. It is used for preparing and delivering interactive and variety of printed reports. It is administered through an interface that is web based. Reporting services utilizes a web service interface for supporting and developing of customized reporting applicatons. It can be competed with Crystal Reports and other business intelligent tools.

Explain the architecture of reporting services?

Reporting services architecture is comprises of integrated components. It is multi-tiered, included with application, server and data layers. This architecture is scalable and modular. A single installation can be used across multiple computers. It includes the following components:

- Report Manager, Reporting Designer, Browser Types Supported by Reporting services, Report server, Report server command line utilities, Report Server Database, Reporting Services Extensibility, Data sources that is supported by Reporting Services.

Describe Reporting Lifecycle?

The Reporting Lifecycle includes

- Report designing – The designing is done in Visual Studio Report Designer. It generates a class which embodies the Report Definition.

- Report processing – The processing includes binging the report definition with data from the report data source. It performs on all grouping, sorting and filtering calculations. The expressions are evaluated except the page header, footer and section items. Later it fires the Binding event and Bound event. As a result of the processing, it produces Report Instance. Report instance may be persisted and stored which can be rendered at a later point of time.

- Report Rendering: Report rendering starts by passing the Report Instance to a specific rendering extension (HTML or PDF formats). The instance of reports is paged if paging supported by output format. The expressions of items are evaluated in the page header and footer sections for every page. As a final step, the report is rendered to the specific output document.

 What are the ways to tune Reporting Services?

To tune-up the Reporting Services, follow the below mentioned ways:

- Expand the Server or utilizing the reporting services of another database server. For better embedding of report contents, report application’s logic and characteristics can have a duplicate copy of data.

- Replication of data continuously. Using nolock, the issues of locking can well be resolved and the performance of the query can be improved. This can be done by using dirty read at the time of duplicating the data is unavailable.