Monday, June 7, 2010

Execute UPDATE STATISTICS for all SQL Server Databases

Guys,

Today we will write a simple script which will generate UPDATE STATISTICS for all the database on current SQL Server. Statistics in SQL Server refers specifically to information that the server collects about the distribution of data in columns and indexes. This data is used by the query optimizer to determine the plan of attack for returning results when you run a query. While in the majority of cases SQL Server takes care of this statistical recordkeeping for you automatically, it's useful to have some understanding of what's going on, and to know when you might need to intervene.


















Automatic Statistics
By default, SQL Server databases automatically create and update statistics. Although you can disable this (by setting a property of the database), you should almost certainly leave it on. SQL Server needs these statistics to do a good job with query processing, and it's likely to be smarter than you about what and when to update. The information that gets stored includes:

  • The number of rows and pages occupied by a table's data
  • The time that statistics were last updated
  • The average length of keys in a column
  • Histograms showing the distribution of data in a column
  • String summaries that are used when performing LIKE queries on character data
SQL Server maintains statistics on index and key columns of all of your tables - in other words, the columns that the query processor is able to use in various ways in queries depending on the data that they contain.

SQL Server's engine will update the statistic when:

  • When data is initially added to an empty table
  • The table had > 500 records when statistics were last collected and the lead column of the statistics object has now increased by 500 records since that collection date
  • The table had < 500 records when statistics were last collected and the lead column of the statistics object has now increased by 500 records + 20% of the row count from the previous statistics collection date
Below is a simple code that should work on all SQL Versions

Set nocount on

DECLARE @minId int, @maxId int
DECLARE @DB Nvarchar(100)

Create table #tmp
(
ID int Identity,
Name varchar(100)
)

INSERT INTO #tmp
SELECT [name] 
FROM master..sysdatabases 
WHERE [name] NOT IN ('model', 'tempdb') 
ORDER BY [name] 

Select @minId = 1, @maxId = count(1) from #tmp

While @minId <= @maxId
Begin
SELECT 'Use ' + name + CHAR(13) + 'Exec sp_UpdateStats ' from #tmp Where Id = @minId
Set @minId+=1
END

drop table #tmp

This code yields following results:


Use AdventureWorks
Exec sp_UpdateStats

Use AdventureWorksDW
Exec sp_UpdateStats

Use LearningCT
Exec sp_UpdateStats

Use master
Exec sp_UpdateStats

Use msdb
Exec sp_UpdateStats

Use Northwind
Exec sp_UpdateStats

Use ReportServer$MSSQL2008
Exec sp_UpdateStats

Use ReportServer$MSSQL2008TempDB
Exec sp_UpdateStats

Use SensitiveDB
Exec sp_UpdateStats

Use testdb
Exec sp_UpdateStats

Now copy this text & paste it into a query window in SQL Server Management Studio, then execute it.

When you execute the code, you will see the output like this:



















This shows which all indexes are updated.

Happy SQL Coding

Thursday, May 27, 2010

Download Defensive Database Programming e-book

Guys,



Recently, Alex Kuznetsov has written a book "Defensive Database Programming". You can download it free from Red Gate

Here are the contents of the Book:


Chapter 1: Basic Defensive Database Programming Techniques
Chapter 2: Code Vulnerabilities due to SQL Server Misconceptions
Chapter 3: Surviving Changes to Database Objects
Chapter 4: When Upgrading Breaks Code
Chapter 5: Reusing T-SQL Code
Chapter 6: Common Problems with Data Integrity
Chapter 7: Advanced Use of Constraints
Chapter 8: Defensive Error Handling

The paid versions of this book contain two additional chapters: Chapter 9, Surviving Concurrent Queries and Chapter 10, Surviving Concurrent Modifications. See the Introduction for further details.




Its a very interesting book. Download it now & start reading. If you face any problem with download, let me know.

Happy SQL Coding

Friday, May 7, 2010

Invitation to The Future of Productivity Launch at Marina Bay Sands, 26 May











On May 26, Microsoft Launches The Future Of Productivity

Your connected enterprise depends on you. However, the continuous onslaught of support incidents, project mplementation, and system updates can stretch you and your team to the limit. Microsoft productivity tools can help you deal with any situation, so that your IT infrastructure runs at optimum conditions. That means being able to access and analyze data easily, coordinate team efforts seamlessly, and automate more administrative tasks, so you can concentrate on the tasks that really matter.

On May 26, Microsoft breaks new ground with the launch of innovative software that is ready for the work of today and tomorrow.  Come to the Future of Productivity Launch at the much anticipated Marina Bay Sands, and discover how to connect and empower your people to attain competitive advantage:
With Singapore’s focus on productivity as a key economic strategy, the time is right to explore new and innovative solutions that will impact employee motivation, boost work productivity, and accelerate business growth.

Come to the Future of Productivity Launch!

In today’s 24x7 world, information workers require the right productivity tools to support them in achieving great results. Register for this event and discover how to perform smarter and increase your effectiveness!
Happening at the new Marina Bay Sands Integrated Resort

To support Singapore’s drive for greater efficiency, Microsoft launches a suite of productivity tools for today’s information workers. Join us for a one day event as we showcase the latest from Microsoft. Learn how to adopt time-saving measures, remove barriers to communication, and achieve organisational productivity gains.

Highlights:

  • Learn through live demos on how Microsoft solutions work together to optimize the Business Productivity Infrastructure
  • Hear from peers and partners who are already seeing benefits to their business by leveraging the Future of Productivity solutions.
  • Experience the latest products and offerings at the Solutions Showcase brought to you by Microsoft’s ecosystem of partners
  • The event will commence with a keynote morning session, followed by breakout track sessions in the afternoon:

 

Click here to view the full agenda and register for the event now!



Hurry up & Register Now!!!!!!!!!!!!!!!!!!!!!!!!!!!!

Entrepreneurial dreams with Microsoft Cloud Services contest

Hi Guys,

Microsoft is running a contest on AZURE. Here are the details of the content.



Click here to register:

Microsoft Web Camp in Singapore on June 4 and 5

Hello Everyone,

Are you interested in learning how new innovations in Microsoft's Web Platform and developer tools like ASP.NET 4 and Visual Studio 2010 can make you a more productive web developer?

If you're currently working with PHP, Ruby, ASP or older versions of ASP.NET and want to hear how you can create amazing websites more easily, then register for a Web Camp near you today!

Microsoft's Web Camps are free, two-day events that allow you to learn and build on the Microsoft Web Platform. At camp, you will hear from Microsoft experts on the latest components of the platform, including ASP.NET Web Forms, ASP.NET MVC, jQuery, Entity Framework, IIS, Visual Studio 2010 and much more.

Web Camps also provide the opportunity to get hands on with labs and get creative by building in teams. All this with Microsoft experts on hand to guide you through.

The goal for Web Camps is to give you a jumpstart training on building rich web applications using the latest innovations from the Microsoft Web Platform.

















Location: Microsoft Auditorium, Level 21 NTUC Centre, One Marina Boulevard.
Microsoft Singapore

Here’s the planned AGENDA for Day 1 of the event:

08:30-09:00am - Arrival and Beverages

09:00-09:15am - Welcome and agenda for the event

09:15-10:30am - A Lap around the Microsoft Web Platform and ASP.NET Overview

The Web Camp begins with a lap around the Microsoft Web Platform and tools, exploring its components and how they work together allowing you to quickly create powerful standards-based Websites that offer rich end-user experiences. We'll also learn how the Web Platform Installer makes installing and platform and exciting applications super simple.

We'll also take a look at ASP.NET and how it offers developers a choice when building rich, standards-based web applications with ASP.NET Web Forms and/or ASP.NET MVC.

10.30-10.45am - Break

10.45-12:00pm - Building a rich web application

Part 1: Getting started with MVC & Entity Framework

This is the first of three sessions in which we will walk through building a simple application. We'll learn how easy and powerful the Microsoft Web Platform and how it is greater than the sum of its parts.

In Part 1, we'll get started building our application in Visual Studio 2010, ASP.NET MVC and the Entity Framework. To start we will learn some of the fundamentals of ASP.NET MVC including the Model-View-Controller approach and how it works. Next, we will learn how the Entity Framework makes creating data-driven web applications really easy by providing a powerful ORM that we can leverage throughout our application.

12:00-01:00pm - Lunch

01:00-02:15pm - Building a rich web application

Part 2: Deeper into MVC and new features

With our application’s data layer in place, in Part 2 we'll learn how our data models are used throughout ASP.NET MVC and make it easy to wire up data to business logic and UI to quickly get it up and running. We'll explore how new features in ASP.NET MVC 2 simplify data validation and where HTML Helpers make coding against our model easier with templated and strongly-typed helpers. In addition, as our application grows in size and complexity we want to ensure the code is well organized and also reusable – we can use new features like Areas and RenderPartial in ASP.NET MVC 2 for this. We’ll also touch on a few new features in Visual Studio 2010 that help us be more productive when finding and using our code.

02:15-03:30pm - Building a rich web application

Part 3: jQuery and simplified web application deployment

In Part 3, we will explore techniques to add “sizzle” to your web application on the client-side with jQuery and its powerful selection engine, network stack and animations. All of this is made possible by ASP.NET MVC on the server side and we’ll also take a look at how the two work together with JSONResult and how we can use jQuery for validation too. With the application taking shape, we’ll learn how to take the pain away from deployment with Visual Studio 2010 and Web Deploy including new features like publishing profiles, multiple configuration settings and options for database migration that make life simple.

03:30-03:45pm - Break

03:45-04:30pm - Getting the most out of IIS with IIS Extensions and wrap up for the day.

To wrap up the day, we'll explore how to get the most of IIS with IIS Extensions like the SEO Toolkit, URL Rewriter and Database Manager and also give an overview of programs like WebsiteSpark that provide tools and servers for no upfront cost.

04:30-05:00pm - Ask the expert Questions

05:00-06:00pm - InstallFest and Day 2 Agenda

Day 2 is available to get our hands dirty with labs (to be installed on your own laptop) and also to work building apps in teams. The best apps at the end of the day will win prizes!

To view complete agenda, click here


If you want to attend, then click here to Register now: