SQL Server security best practice

Security! This is the word comes in mind of every concerned person when it come...

Change the Collation Settings in MS SQL Server

This post will show you how to change the collation settings in MS SQL Server for specific database...

Resolve collation conflict

In this post I will show you how you can resolve collation conflict error...

Book: SQL Server 2008 High Availability

In this book I have tried to cover every single piece of information that might requires for installing and configuring SQL Server HA option like Clustering, Replication, Log Shipping and Database Mirroring...

Why to recompile Stored Procedure

Generally, we create views and stored procedures (proc here after) ...

2/28/2011

Cannot resolve the collation conflict


Recently when I was referring to SQL Server Forums I saw a question that reads like:
I get an error  Cannot resolve the collation conflict between "Latin1_General_CI_AI" and "SQL_Latin1_General_CP1_CI_AS" in the equal to operation.
image
What is a Collation?
In simple words Collation is the set of rules that ensure proper use of characters for Language or Alphabet. Here are some recommendation from books online about choosing collation:
    • Select a BINARY2 collation if binary code point based ordering is acceptable.
    • Select a Windows collation for consistent comparison across data types.
    • Use a new 100-level collation for better linguistic sorting support.
    • If you plan to migrate a database to the upgraded instance of SQL Server, select the collation that matches your existing collation of the database.
Solution:
The error that we are referring here shown up because the two databases have different collation for some reason, now, to overcome this issue one may use COLLATE clause, but do remember that COLLATE clause will work with CHAR,VARCHAR,TEXT, NCHAR, NVARCHAR and NTEXT data type.
The Syntax :
SELECT * 
FROM 
SYS.databases SD
JOIN
SOMEDB.DBO.SOMETBL JC    
ON 
SD.database_id  = JC.DBID  COLLATE Latin1_General_CI_AI
Here are some external resource for further reading




http://msdn.microsoft.com/en-us/library/ms143508.aspx>




http://blogs.msdn.com/b/qingsongyao/archive/2008/08/25/sql-server-2008-katmai-s-new-collations.aspx
photo credit: mdanys via photopin cc

1/31/2011

Tip for Backing up User Databases

We all take a database backup as a first resort to recover from a damage occur during the disaster / server crash / for any other reason if require to recover or restore our data back to its previous stat as it was before the database server was crashed!! And for this we schedule a job or make use of database maintenance plan which will take a database backup be it Full / Differential or Log, and we all take a special care and consideration when we design the backup strategy!!

But what happened if one fine day when you need your database backup file to work well and it doesn’t!! What if it is corrupted!! And you have only a Full backup for that day?

Today I am going to discuss about the script that I have posted in the download section couple of days back; the script will not only perform a full database backup of all user databases but it will also verify the validation of the backup file!  It's a must to have a database backup strategy where in we do not keep multiple copies of database backup  and if one have one or two days retention policy. 

declare @int int ,@dbname varchar(22),@maxdbid int
declare @int int ,@dbname varchar(22),@maxdbid int
declare @bkpath varchar(25),@path varchar(50)
select @maxdbid= max(dbid) from master..sysdatabases
set @int = 0
set @bkpath='C:\SQLDB\backup\'
USE master
while (@int < @maxdbid)
begin
set @dbname = (select [name] from master..sysdatabases where dbid=@int and status!=1073807392)  
if (@dbname != 'tempdb') 
 begin
  select @int as 'DBID',@dbname as 'Database'  
  select @path=@bkpath+@dbname+CONVERT(VARCHAR(12),GETDATE(),112)
  BACKUP DATABASE @dbname TO DISK = @path  
  print @path
  print @bkpath
  restore verifyonly from disk=@path
  end  
 set @int = @int + 1  
 continue 
 break
end

Check the line # 17, restore verifyonly from disk = @path is the line that will help us to overcome above issue. This is not a hidden code lying in a secret place somewhere but this is something that we may have missed in our code – I know most of you have already using this option for your database backup validation, how many of you are using this option? Or out of curiosity any other option!!

PS: This code is the very basic code that I have wrote initially, you may modify and use the script according to your requirement without any obligation.
Your suggestions welcome!

Regards
- Hemantgiri S. Goswami

1/25/2011

SQL Server 2008 High Availability – A Book

I have no words to explain my excitement and happiness to share news with you all - my book on SQL Server 2008 High Availability is published!!
I have started authoring this book in May 2010 and as the time passes and gradually I move to the final chapter of the book, I was feeling like aha finally it is done!!! – Do you think so, it was this easy?
No, every publication house has their own set of rules to be followed while authoring a book and a process to be followed before the chapter or entire book is ready to be published i.e. 1st edit, 2nd edit of the chapter until final edit and the Packt Publication is no exception.
Since this is the first time I was authoring book I was having little or no idea about authoring a book. The editors from Packt Publication helped me a lot by helping me time to time with proper answers to my queries. I must admit that I could not be able to complete this book without support and encouragement from my family including my 2 year old daughter Dhruti.
I hope that you all will enjoy reading and learning from this book as I did while authoring and contributed my little part for the growth of my beloved SQL Server J
Let me tell you about this book:
1223EN_MockupCover The term High Availability means that the servers or systems that host or run the business-critical applications should be highly available 24 X 7. As the word it-self defines how important it is to make these applications and data available for end-users as well as business users, if this data is not available for a short time, it will be a big problem for both sets of users. Imagine a bank spread across the country and having a huge customer base. One fine day, their server crashes! If the bank relies only on backups, then it might end up losing approximately 15 to 30 minutes of data, depending on the backup strategy. Now the HA options related to SQL Server such as clustering, replication, log shipping, and database mirroring will help overcome this situation.
In this book I have tried to cover every single piece of information that might requires for installing and configuring SQL Server HA option like Clustering, Replication, Log Shipping and Database Mirroring, below are the chapters:
Chapter 1: Understanding Windows Domains, Domain Users, and SQL Server Security
Chapter 2: Implementing Clustering
Chapter 3: Snapshot Replication
Chapter 4: Transactional Replication
Chapter 5: Merge Replication
Chapter 6: Peer-to-Peer Replication
Chapter 7: Log Shipping
Chapter 8: Database Mirroring
Appendix A: Troubleshooting
Appendix B: External References
If you are interested to read more about the detailed / contents of each chapter you may find them here https://www.packtpub.com/toc/microsoft-sql-server-2008-high-availability-table-contents
And, here is the link for the sample chapter https://www.packtpub.com/sites/default/files/1223-chapter-1-understanding-windows-domains-domain.pdf

Regards
Hemantgiri S. Goswami

1/21/2011

Download SQL Server Training Kit

Couple of months back I have wrote a blog article about the availability of Microsoft SQL Server Developer Training Kit which is very helpful resource for the SQL Server Developers, trainers and professionals to understand the improvements comes with the release of SQL Server 2008.
Recently, 18th January 2011 Microsoft has released the updated version of Microsoft SQL Server Developer Training Kit which has
  • # 31 Presentations (includes Slide decks, videos and transcripts)
  • # 27 Demos (includes installer scripts, videos and transcripts)
  • # 12 hands on labs (includes installer scripts)
The main highlight of the updated version is – BI Solution, yes you read it right. The version of developer training kit has the units for BI Solutions like:
  • Build your first Microsoft BI Solution with SQL Server 2008 R2
  • Introduction to BI Modelling Techniques
And all of this are free!!
Download the updated version of SQL Server Developer Training kit from here –> http://www.microsoft.com/downloads/en/details.aspx?displaylang=en&FamilyID=fffaad6a-0153-4d41-b289-a3ed1d637c0d
You may want to check the complete list of what is included in SQL Server Developer Training Kit and System Requirements before you begin download. 
Regards
Hemantgiri S. Goswami

1/19/2011

Download Section for Script and free ebook

Dear Readers,


Good News!!


I have created a new section on this site from where you can download various scripts I have created and uploaded on my community website. Currently you can download scripts for:


  • To Find Missing Index
  • To get various SQL Server Property details
  • To search a given word from a string
  • Script which will take backup and verifies the backup set as well
  • Script which will give you an idea on how to perform transaction in smaller chunks
You may find them all at http://www.sql-server-citation.com/p/downloads.html, and I promise that I will surely upload some more scripts in coming future.

Regards
Hemantgiri S. Goswami | http://www.sql-server-citation.com/

1/01/2011

welcome 2011

Dear Readers,

Wishing you all very happy and prosperous new year, may the new day bring you joy and happiness

11/16/2010

Community Techday | Surat | 28th November 2010

We are very pleased to announce Community Techday at Surat on 28th November 2010. We try to bring you the new products 

SQL Server is very popular and widely used RDBMS system in the SME and large Enterprises segment around the world for storing and managing their business critical data. Numerous applications are developed today with n-tier technologies, but they can be never be without database behind it. Recently Microsoft has announced the new version of SQL Server - SQL Server 2008 R2.

SharePoint 2010 is the business collaboration platform for enterprise and the web, Sharepoint makes it easier for people to work together. One can setup websites and manage their documents with few mouse clicks!!!

Windows 7 is a cool new version of Microsoft Windows for personal computers, including home and business desktops and laptops.

During this event we will learn the new features that are introduced with the new version of SQL Server 2008 R2, Sharepoint 2010 and Windows 7.  I would request you to kindly mark your calendar for Community Techday, 28th November 2010 in Surat.

You will have to visit the home page or the event page of the Surat User Group and get yourself register for free!!
Note: Feel free to share this detail to your friends and colleagues, Community Techday is the free event you don’t have to pay any fees to attend this event.

11/12/2010

What is new in SQL Server - Denali

Dear Readers, I have a great news to share with you all!! 


A much awaited future version of SQL Server is announced - "Denali". This version has some new salient features like:

  • SQL Server AlwaysOn -  A new feature that will provide maximum uptime with simplify HA deployment, this feature will also supports new availability group option to improve availability of mission critical databases by supporting multiple secondary servers.
  • Column-Based Query Accelerator -  Increase query performance by ~10x 
  • IT Administration - Enhancements in server roles to manage separation of duties, and auditing will be available for all the editions.
  • Beyond Relational - FileTable, 2D Spatial support 
  • Juneau - A tool for Developers : Developers can easily work using new tool "Juneau", this will help developers to developing databases, BI and web solutions. It also provides environment for Declarative Database Definition, Dynamically Editing Existing Database
  • BI Enhancement: Drag and Drop interface
  • Analytic Enhancement: Analytics performance can be enhanced from the desktop to data center through in-memory column store technology
  • Data Integration Management: Denali introduces two component - Data Quality Services for knowledge driven data cleansing and Impact Analysis and lineage which will ensure that the right data is delivered to the right users and the right time.
You may find more information at http://www.microsoft.com/sqlserver/en/us/product-info/future-editions.aspx and if you like to review the new version of SQL Server you may, download Denali at - http://go.microsoft.com/fwlink/?LinkID=205500&clcid=0x409

11/02/2010

How to Upgrade SQL Server

Couple of days back I have wrote an article on common issues we face while upgrading, and two methods to follow while upgrading SQL Server, this article also gives you some basic steps we need to follow post upgrades.  Here is an excerpts of the article:
Upgrading the SQL Server version can have a major impact the applications using the databses. For example, from SQL Server 2005 onwards you are required to use  col IS NULL instead of Col = NULL and so any applications using the later will break. Using  Upgrade Advisor for SQL Server is a good start for any SQL Server however we still need to address the entire  process of upgrading SQL Server to a new version. So What is the process  we should follow while upgrading SQL Server? Read full story....


-- Hemantgiri S. Goswami | www.sql-server-citation.com

8/10/2010

Download MS SQL Server 2008 R2 Management Pack

Recently Microsoft has released MS SQL Server 2008 R2 Management Pack, it can monitor the Microsoft SQL Server components such as database engine, databases and SQL Server agents. MS SQL Server 2008 R2 Management Pack has few enhancements in this release including:

  • Simplified and streamlined customer configuration and deployment
  • Lower cost of operation due to improved health model and reduced false alarms
  • Meets low-privilege constraints needed for financial and medical industries
  • New rules, monitors, and knowledge improvments
  • Easy deployment
  • Discover and monitor SQL Server 2005, SQL Server 2008 and SQL Server 2008R2

You can download the SQL Server Management Pack here - Link

Hemantgiri S. Goswami |  www.sql-server-citation.com

7/09/2010

Download SQL Server Developers Training Kit for free

There are tons of useful resources available for SQL Server but the link I am going to share with all of you today is really the greatest amongst - it's a SQL Server Developers Training Kit. Yes, MS has made the updated version available for we all and the best part is - it's free.

The key benefits are:
  • How to build applications with unique and new features available in SQL Server 2008 and SQL Server 2008 R2
  • It contains #55 videos, # 32 presentations, #39 demos and #24 hands-on-labs
  • Content for SQL Server beginner developers
Doesn't it seems a bundle full of great resource on SQL Server 2008? Here is the complete list of what it includes if you still wants to check before you download it from here.

Regards
Hemantgiri S. Goswami

6/23/2010

Download SQL Server 2008 R2 Best Practices Analyzer

Recencly Microsoft has released the Best Practices Analyzer (BPA) for SQL Server 2008 R2. BPA is a tool which helps Administrators to audit there local and remote SQL Server instances sagainst system events, logins, permissions and metadata for recommendation if it doesn't follow MS best practices for SQL Server.

But, you have to have pre-requsite installed on your system before you install BPA for SQL Server 2008 R2, they are:

Note: There are some issues reported related to installing, you may find the work around by Adam W. Saxton and in the Insturction section.

4/20/2010

Download free eBook on SQL Server 2008 R2

In this quarter Microsoft Press has gift a free eBook on "Introduction to SQL Server 2008 R2", a book written by Microsoft SQL Server MVP Ross Mistry and Stacia Misner.

This book has 10 Chapters and 216 pages which covers
  • Enhancements in SQL Server 2008 R2
  • Multi Server Administration
  • Data Tier Application
  • HA and Virtualization Enhancements
  • Server Consolidation and Monitoring 
  • Data Warehousing
  • Master Data Services
  • Event Processing with StreamInsigh
  • SSRS Enhancements
  • Self-Service Analysis using PowerPivot
Isn't this list looking great? I just have downloaded this book in PDF format, alternatively you can download this book in XPS format as well.

2/24/2010

Virtualization – a way to reduce IT Costs!


A month ago I and my friend were discussing IT budget, and it becomes very interesting when we started discussing virtualization. Let me brief you the case: with the growing business usage of IT infrastructure increases and that increases the usage of energy and space. Apart from this, there is another side; are those resources getting utilized at optimum level? Well, at some cases yes but in most of the cases it doesn't - source.
One would think if this really requires? I would say, yes, it is required. Let's take an example here; company Ax Inc is managing its 200 servers at its datacenter at Bangalore. Let's say a single server which utilized at 60% consumes 350 watts, now let us calculate -:
UnitRateAmount
Up to 1002.90290
101 to 2003.60360
201 to 3004.20420
301 to 4004.45222.5
Above 4014.70-- NA --
Bill generated for single server
1292.5
                                   (Figure 1)
Further, calculating this amount for 200 servers would make 258500/- INR per month (US$ 5609.45 per month, as of 23-Feb-2010 according to CurrenciesDirect). If we also consider the bill for cooling systems and miscellaneous expenses it would be much more. In addition, add licensing costs, resources which manage and maintain this IT Infrastructure will add some extra burden.

Is there a solution for this? Yes, there is a solution for this – Virtualization. Virtualization is great technology which helps us to utilize our IT infrastructure at the max and lower down the costs. You must be wondering how this can be possible, and if it is; how to implement this solution!!!  As I said above, our discussion was turned very interesting – the solutions are to implement "Virtualization". Virtualization – a methodology of dividing the resources of a computer into multiple execution environments, by applying one or more concepts or technologies such as hardware and software partitioning , time-sharing, partial or complete machine simulation, emulation, quality of services, and many other.
There are bunch of benefits that are attached to with implementing Virtualization, and related product i.e. lowering power consumption, ease of deployment, maintenance and updates, and consolidation. Let me brief you about each.

Lowering power consumption: As I shown you in the above calculation in figure 1, 200 servers would generate whooping electricity bill - 31,02,000/- (2585000*12) annually. This is just an example and that to without considering cooling system.

Now, if you have hardware with Hyper-V you will be able to have your multiple servers on it. You can even host with Linux. And, naturally with lower numbers of servers your electricity bill goes down significantly.

Ease of Deployment: With the use of Microsoft Virtual Server Manager, System Center Virtual Machine Manager you will be able to optimized your physical and virtual resources.
  • Centralized virtual machine deployment and management
  • Intelligent placement of virtual machines
  • Integrated performance and resource optimization
  • Fast physical to virtual and virtual to virtual conversion
  • Leverage and extend existing storage infrastructure
  • Scriptable using PowerShell
  • Live migration
  • Hot add/remove of VHDs, pass-through disks
  • Server consolidation
Maintenance and Updates: The real beauty is that it makes administrator's life easy. With the use of System Center Configuration Manager and Operation Manager you will be able to easily do our maintenance and updates easily.
  • Comprehensive application and service level monitoring
  • Update management
  • Software distribution
  • Operating system deployment
  • Ease of Backup
Conclusion: Virtualization helps a lot to save energy by consuming less power, save resources, and make IT administrator's life easy by server consolidation, deployment of patches and updates and even migration. As I have said in my previous post about embedding security to your product or piece of code, you may have the same tight security mechanism implemented with Virtualization- refer the document. Microsoft's own websites like MSDN and TechNet which has 1~3 million hits a day runs 100% on Hyper – V.
Cumulatively all this effort saves a lots of money by reducing IT costs, this makes real sense to me because it makes my life easy and as IT cost is down my client is happy with the solution.

Further reading:

Videos:

Virtual Labs:


References:
http://www.mybengaluru.com/resources/2248-Bangalore-Electricity-Tariff-Hike.aspx
http://www.spec.org/power_ssj2008/docs/SPECpower-Methodology.pdf

2/18/2010