bet365 UK

wordpress joomla template

sys.dm_db_stats_properties DMV

Written by VidhyaSagar on . Posted in General

Service pack 1 for SQL Server 2012 has been released on 9th Nov 2012. It took couple of weeks for me to install it in our servers. Before I settle down I got another notification from Microsoft that Cumulative Update 1 has been released for SP1. So I started analyzing what they missed major in SP1 and finally I found a article by Aaron. There are many new features and fixes are released with Service pack 1. One of the feature with this release is stats DMF sys.dm_db_stats_properties and I started playing with it. Later I came to know that this DMF is already released with SQL Server 2008 R2 SP2 however it’s not released with SQL Server 2012 RTM, only god knows why its not accompanied with 2012 RTM. sys.dm_db_stats_properties DMF accepts two parameter as input. You need to provide object id and stats id as input, you can get these information using sys.stats DMV. Use the query below to get the information.
USE DBNAME
GO
select object_id ,name,stats_id
from sys.stats where object_id = object_id ('TABLENAME')
stats_dmf_1 Once you get the details, feed it to the DMF as shown below
USE DBNAME
GO
select OBJECT_NAME (object_id) 'Object Name'
,stats_id
,last_updated
,rows
,rows_sampled
,steps
,unfiltered_rows
,modification_counter
from  sys.dm_db_stats_properties(OBJECTID,STATSID)-- You can get these informations from sys.stats dmv
stats_dmf_2 You will get the results and the column description is below

ColumnName

Description

Object_ID ID of the object. In the query above I’ve made it to return the object name
Stats_ID ID of the Statistics
Last_Updated Last when statistics is updated
Rows No of rows in the table when statistics is updated
Rows_sampled No of rows sampled during last update
Steps No of steps in histogram. Histogram step information is not returned in this DMF.
Unfiltered_Rows This is for filtered index. No of rows when you update the statistics for filtered index
Modification_Counter Total number of modification for the column sinced last update
You could get all these information plus additional information if you use DBCC SHOW_STATISTICS.
USE DBNAME
GO
DBCC SHOW_STATISTICS('TABLENAME','STATSNAME’)
stats_dmf_3

If you could see you will be able to get density information, range key values and all the steps for histogram. I wonder why Microsoft added this DMF? I hope you can’t use DBCC command in select statement however you can use this DMF there, this is the only place I could see its useful. They should provide some value addition with this DMF, lets say we need a column which should tell you whether update is required for the stat or else it should give you information something like average_percentage_fragmentation in index statistics so abased on that we can dynamically update the stats. Hopefully we will get some column with these details in future. So if you aren’t aware of this DMF then it’s time for you to try it.

VN:F [1.9.22_1171]
Rating: 0.0/5 (0 votes cast)
VN:F [1.9.22_1171]
Rating: 0 (from 0 votes)

Tags: , , , , ,

Trackback from your site.

Leave a comment

*

Recent Comments

Engin Ardıç

|

Thank you for nice article! That’s so helpful for me.

VidhyaSagar

|

Sure will plan something when you come here

Mohamed Kabiruddin

|

Hi Vidhysagar & Team,
I am happy to hear that the SQL Server User Group in Chennai is active and going strong. I came across your blog and wanted to attend one of your user group meetings.

I am basically a Chennai-ite and work as a Microsoft BI Consultant in Australia. I am an active member of PASS SQL Team in Australia and have also presented for PASS SQL Saturdays in Australia. I visit Chennai almost every year for holidays and I would love to attend one your sessions. I am happy to speak on any particular topic of interest and discuss case studies on some of the projects and the industry in Australia as well.

I recently presented on “Agile BI with SQL Server 2012″ for PASS. I am coming down to Chennai this August 2013 for a fortnight. Please feek free to get in touch.

Cheers,
Mohamed Kabiruddin

admin

|

@aj — Both the scripts are same. In my example I’m passing the output value to a variable. In your example you aren’t passing it instead you make the task failure or success.

ajssis

|

You are creating a lot of extra steps that are not required in the Script task. You fail to see the line right after your code that is
Dts.TaskResult = (int)ScriptResults.Success;

The opposite of this is
Dts.TaskResult = (int)ScriptResults.Failure;

The code you should be using is
// Check if the file exists
if (File.Exists((string)(Dts.Variables["FilePath"].Value)))
{
Dts.TaskResult = (int)ScriptResults.Success;
}
else
{
Dts.TaskResult = (int)ScriptResults.Failure;
}

If the file exists then the Script task result will be “Success”. If the file does not exist the Script task results will be fail.

Then all you do is set the Success direction flow (the green line) to go to your data flow task. If the result is Failure then the Failure direction flow (the red line) will go to your Update error task. Be sure to RIGHT-CLICK the direction flow and select “Failure” from the pop-up menu.

The best bonus by bet365 Ελλάδα 100% for new user.

Full Joomla 3.0 Theme free theme.