Wednesday, May 4, 2011

Announcement for Blog

Dear/Respected All,

I am pleased to announce that my blog is now available at http://www.varindersandhu.in for better features and presentation for users or readers.

The primary objective of my blog is to share my experience and notes with all technical persons. It would mean the world to me if you’d stop by my blog at some point.

I really appreciate the response of readers on my blog and I hope the same response will be continuing in future.

This Message/Post can be forwarded to anyone who might be interested.

Sincerely,
Varinder Sandhu

Monday, April 18, 2011

SQL Server – Policy Based Management

SQL Server 2008 has a new feature called Policy Based Management, also know as Declarative Management Framework (DMF), to tackle the problem of standardizing your SQL server instance. Although Policy Based Management can be used just to alert an administrator when an object is out of compliance, depending upon the type of policy, you can also enforce compliance by preventing changes that would violate a policy. Policy Based Management introduces the following new objects that are used to design and check for compliance:
  • Facts
  • Conditions
  • Policies
  • Policy Targets
  • Policy Categories
For more information click here

SQL Server – Distributing and Partitioning

Key Points of Distributing and Partitioning
  • Partition allow you to divide a table or index into multiple filegroups.
  • Table and index are partition horizontally, based on rows by specifying a partitioning column.
  • To create a portioned table or index you need to perform the following actions:
    • Create a partition function
    • Create a partition schema mapped to partition function
    • Create a table or index on the partition schema
  • SPLIT function to add a new boundary point and hence partition.
  • MERGE function to remove a boundary point and hence partition.
  • SWITCH function to move a partition of data between tables.

Sunday, April 10, 2011

SQL Server – Backup Type for Each Recovery Model

Before looking about Backup type for each Model, sharing with brief information about Recovery and Recovery Model

Recovery


Recovery options determine the behavior of transaction log and how damaged pages are handled.

Recovery Model

Every database within a SQL server a SQL server instance has a property setting called recovery model. The recovery model determines the types of backups you can perform against a database. The recovery models available in SQL server 2008 are:
  • Full
  • Bulk-Logged
  • Simple

SQL Server – Backup all the sql server databases

Sharing with you script to backup all the SQL server databases


Script:


DECLARE @name VARCHAR(50) — database name
DECLARE @path VARCHAR(256) — path for backup files
DECLARE @fileName NVARCHAR(256) — filename for backup
DECLARE @fileDate VARCHAR(20) — used for file name

SET @path = ‘D:\Backup\’

SELECT @fileDate = CONVERT(VARCHAR(20),GETDATE(),113)
SELECT name,flag=0 INTO #temp FROM master.dbo.sysdatabases
WHERE name NOT IN (‘master’,'model’,'msdb’,'tempdb’)

–according to requirement we can filter databases in where clause

SET ROWCOUNT 1

WHILE (exists(SELECT * FROM #temp WHERE flag=0))

BEGIN

SELECT @name=name FROM #temp WHERE flag=0
SET @fileName = @path + @name + ‘_’ + @fileDate + ‘.BAK’
BACKUP DATABASE @name TO DISK = @fileName WITH INIT
UPDATE #temp SET flag=1 WHERE flag=0

END

SET ROWCOUNT 0

DROP TABLE #temp

if anybody have any other idea please share.

Saturday, April 2, 2011

SQL Server – Understanding the System Database of SQL Server

We all know there are some system databases available in SQL Server. But we should have understanding about system databases. Here just try to give you understanding of system databases very briefly.

There are four system databases available in SQL Server 2008
  • Master
  • Model
  • msdb
  • tempdb
Master Database


The master database records all the system-level information for a SQL Server system.The master is the database that records the existence of all other databases and the location of those database files and records the initialization information for SQL Server. Therefore, SQL Server cannot start if the master database is unavailable. In short, Master database is the logical repository for the system objects residing in the sys schema.

Model Database

The model database is used as the template for all databases created on the instance of SQL Server. Template can include specific settings and all sorts of useful stuff.


Msdb Database

The msdb database is used by SQL Server Agent for scheduling alerts and jobs. If the MSDB database is corrupted or damaged then scheduling information used by SQL Server Agent will be lost.

Tempdb Database

The tempdb database is a workspace for holding temporary objects or intermediate result sets, temporary table creation/processing. The TempDB is recreated every time when ever SQL Server restarts


For more Detail go to below URL

http://msdn.microsoft.com/en-us/library/ms178028%28v=SQL.105%29.aspx

 

Wednesday, March 30, 2011

SQL Server – Linked Server – Mapped all users with one statement

Hello Friends,
I have setup the Linked server with the help of script here. My one of colleague helps me to write the script with we can map all user with one statement. This script will map all local SQL server users with remote user that you provide in the script.

You don’t need to map all user manually.

Script:

EXEC master.dbo.sp_addlinkedserver @server = N‘dsql2k’, @srvproduct=N, @provider=N‘SQLOLEDB’, @datasrc=N‘servername’

EXEC master.dbo.sp_addlinkedsrvlogin@rmtsrvname=N‘dsql2k’,@useself=N‘False’,
@locallogin=NULL,@rmtuser=N‘sa’,@rmtpassword=‘XXXXXX’


if anybody have any other experience, please share as comment.

Sunday, March 6, 2011

Transaction Isolation Level

What is default Isolation level for SQL Server 2008 or Crystal Report?

Many people have same above question about Isolation Level, may we have same question. So here share the brief answers of this question.

Transaction Isolation Level:
In database systems, isolation is a property that defines how/when the changes made by one operation become visible to other concurrent operations.

Default Isolation level for SQL Server 2008 is “Read Committed”

SQL Server 2008 has following transaction isolation level

Read Committed
Read Uncommitted
Repeatable Read
Serializable
Snapshot

Learn More about TRANSACTION ISOLATION LEVEL (Transact-SQL)

Crystal Report Isolation Level

The default isolation level for database reads in Crystal Reports 9.0 is set to Read Committed

Crystal Reports .Net 1.1 Patch –> Problem ID # ADAPT00194820

http://search-pdf-files.com/pdf/193365-read-leel-error-description-isolation

Sunday, February 27, 2011

SQL Search

Dear Friends,

I have tried the Utility SQL Search, it is really helpful for me…
Thought it will be handy to all of us and it is a free tool from Red Gate.
SQL Search is an add-in for SQL Server Management Studio that lets you quickly search for SQL across your databases.

Click here for more detail.

SQL Server Editions

Dear friends

Most of time we have a question about difference between the SQL server editions, Lot of detailed stuff available over the internet but here sharing with you the brief information about the each SQL server editions so that we can understand easily about all the editions.

SQL server 2008 is available in the following editions


Enterprise:
Designed for largest organizations and those needing to leverage the full power of SQL server 2008 platform. Learn More


Standard:
Designed for small and midsized organizations that do not need all the capability available in SQL Server 2008 Enterprise. Learn More


Workgroup:
Suitable for small departmental project with a limited set of features. Learn More


Express:
A freely re-distribution version of SQL server that is ideal for learning and building desktop and small server applications with small number of users. Learn More

Available as a free download on Microsoft Site: Download Now


Compact:
Designed for emended Databases. Learn More


Developer:
Designed for use by developer in creating SQL server applications. SQL Server 2008 Developer editions has all the features and capability as SQL server 2008 Enterprise, except that is not allowed to be used in production environment. Learn More

After that want to share with you all the Compare Edition Features

Thursday, February 17, 2011

Welcome SQL Server 2011-Denali – CTP1

Dear friends,

A new release of SQL Server is available, and if you follow blogs or tweets or check Microsoft’s SQL Server website. You might have seen mention of the new version, code-named “Denali” SQL Server 2011 – CTP1 Released. CTP stands for Community Technology Preview


It’s available in both 32-bit and 64-bit version. May you are getting excited about the new version. So that‘s why I am sharing with you all…

If anybody have any experience about this, please share as comment

Friday, February 11, 2011

Query Optimization with Linked Server

Hello Friends,

I have faced a problem in SQL queries with Linked server; I just want to share with you all.

Let me explain with example as below

Say, we have set of applications which are running on SQL 2000, due to some reason we need to migrate sub set of applications to SQL 2008.

Now the few applications running on SQL 2008 and few on SQL 2000, applications running on SQL 2008 using some of databases which lie on SQL 2000 with Linked server


Now the problem is the some triggers and stored procedures which need to insert the values from SQL 2008 to SQL 2000 databases using Linked server. Now stored procedures and triggers are taking very long time to execute in this scenario.

But the same stored procedures and triggers are working fine when all the databases are on same SQL server i.e. SQL server 2000.

So the problem comes into the picture when we introduce the Linked Server.

So the solution of this problem, we optimized our stored procedures and triggers like remove the cursors, optimize the joins etc.

Note: As per above scenario query optimization is required with linked server. Whether both SQL server 2000 and SQL 2008 on same physical machine or on different machine.

If anybody has any other experiences about this, please share as comment.

SQL Server – Fix orphaned SQL users

Once you restore a Microsoft SQL Server database on a different machine, you cannot access the database until you fix the users.

The problem is that the user in the database is an “orphan”. This means that there is no login id or password associated with the database user

So before accessing database we need to maps an existing database user to a SQL Server login. For that use sp_change_users_login to link a database user in the current database with a SQL Server login.

First we have to identify the “orphanusers. Below will lists the orphaned users:

EXEC  sp_change_users_login  ‘Report’
Go

If you have login ID myUser in security of Server and you db have user mydbUser then

EXEC  sp_change_users_login  ‘Update_One’,  ‘mydbUser’,  ‘myUser’;
GO
If you want to create a new login id and password for this user, fix it by doing:

Exec  sp_change_users_login  ‘Auto_fix’, ’mydbUser’, ’myUser’, ’mypassword’

For detail see the
http://msdn.microsoft.com/en-us/library/ms174378.aspx

Monday, January 31, 2011

Add the value into an Identity Column in SQL Server

Identity columns are commonly used as primary keys in database tables.
These columns automatically assign a value for each new row inserted.
But sometime Identity columns  missed the value, we want to insert missed value into the column. For that we need to enable IDENTITY_INSERT for the table.


USE mytempDB
GO
CREATE TABLE myTable
(
myIdentity INT NOT NULL IDENTITY(1,1) PRIMARY KEY,
myValue NVARCHAR(30) NOT NULL
)
GO

INSERT myTable(myIdentity, myValue)
VALUES (5, ‘Varinder Sandhu’)

–Result =  Error because IDENTITY is OFF
–Below enable IDENTITY_INSERT

SET IDENTITY_INSERT myTable ON

INSERT myTable(myIdentity, myValue)
VALUES (5, ‘Varinder Sandhu’)

SET IDENTITY_INSERT myTable OFF

Note:
Once we enabled IDENTITY_INSERT on a table you must specify a value for the identity column.

–If IDENTITY_INSERT is OFF then use  below insert statement for above example

INSERT myTable(myValue)
VALUES (‘Varinder Sandhu’)

Thursday, January 27, 2011

Find EDITION, VERSION and SERVICEPACK information of SQL Serve

Hello Friends

Generally, we choose the  @@VERSION to get the version information for SQL Server, but using this function we can’t get the Service Pack information installed…

Alternative way

Get Editions of SQL Server


SELECT SERVERPROPERTY(‘EDITION‘) AS EDITION

Get Version Detail of SQL Server


SELECT SERVERPROPERTY(‘PRODUCTVERSION‘) AS VERSION

Get the Service Pack installed on SQL Server


SELECT SERVERPROPERTY(‘PRODUCTLEVEL‘) AS SERVICEPACK

Thursday, January 20, 2011

SCOPE_IDENTITY, IDENT_CURRENT, and @@IDENTITY not working with Linked Server or Remote server ???

Hello Friends,


I have faced a problem using SCOPE_IDENTITY, IDENT_CURRENT, and @@IDENTITY with Linked server.

Let me explain with example as below

Question: 

We have set of applications which are running on SQL 2000, due to some reason we need to migrate sub set of applications to SQL 2008.
Now the few applications running on SQL 2008 and few on SQL 2000, applications running on SQL 2008 using some of databases which lie on SQL 2000 with Linked server

Now the problem is the some triggers and stored procedures which need to insert the values generated from SQL 2008 to SQL 2000 databases using functions SCOPE_IDENTITY, IDENT_CURRENT, and @@IDENTITY are not working in this scenario.

We are fixing this problem by writing another select statement for selecting identity based on unique parameters in that scope.

We are not aware why this is happening and if there is any solution available.


Answer:


The scope of the @@IDENTITY function is current session on the local server on which it is executed. This function cannot be applied to remote or linked servers. To obtain an identity value on a different server, execute a stored procedure on that remote or linked server and have that stored procedure (which is executing in the context of the remote or linked server) gather the identity value and return it to the calling connection on the local server.

Same for SCOPE_IDENTITY, IDENT_CURRENT also......

If anybody has any idea, please share as comment…


Saturday, January 15, 2011

Bullzip FREE PDF Printer

Hello Friends

I have tried the Utility Bullzip PDF Printer, it really helpful for me….
That’s why I am sharing with you all …

Introduction

The Bullzip PDF Printer works as a Microsoft Windows printer and allows you to write PDF documents from virtually any Microsoft Windows application.
This program is FREEWARE with limitations, which means that it is FREE for personal and commercial use up to 10 users. It does not contain any advertising or popups. For commercial applications with more that 10 users there is a commercial version of the product available at www.biopdf.com.

Features

  • Print to PDF from almost any Windows program.
  • Runs on Microsoft Windows 2000/XP/XP x64/2003/2003 x64/Vista/Vista x64/2008/Windows 7.
  • Supports 64-bit operating systems.
  • Direct output to the same file each time or prompt for destination.
  • Control if the printer should ask if you want to see the resulting PDF document.
  • Control output and prompts programmatically.
  • Setup can run unattended.
  • Graphical user interface.
  • Password protect PDF documents.
  • 128/40 bit encryption.
  • Quality settings (screen, printer, ebook, prepress).
  • Set document properties.
  • Watermark text, size, rotation, and transparency.
  • Superimpose/background documents.
  • Appending/prepending documents.
  • User interface control.
  • Command line interface to all settings.
  • COM/ActiveX interface for programmatic control.
  • Support for Citrix MetaFrame
  • Support for Windows Terminal Server
  • Multiple output types supported: BMP, JPEG, PCX, PDF, PNG, and TIFF.
Download URL :  http://www.bullzip.com/products/pdf/info.php

    Reference URL 

    Saturday, January 8, 2011

    SQL SERVER 2008 – Enable xp_cmdshell


    ---- To allow advanced options to be changed.
    EXEC sp_configure ‘show advanced options’, 1
    GO
    —- To update the currently configured value for advanced options.
    RECONFIGURE
    GO
    —- To enable the feature.
    EXEC sp_configure ‘xp_cmdshell’, 1
    GO
    —- To update the currently configured value for this feature.
    RECONFIGURE
    GO

     
    Alternative way

    1. Click the Start button.
    2. Select All Programs.
    3. Navigate to the Microsoft SQL Server 2008 folder.
    4. Right Click on Server name then click facets options
    5. In the Facets Option choose Surface Area Configuration in dropdown
    6. At the bottom of the window, mark True for xp_cmdshell.
    7. Click OK.