<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Rich&#039;s Blog &#187; sql</title>
	<atom:link href="http://www.techish.net/tag/sql/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.techish.net</link>
	<description>The stuff I get myself into...</description>
	<lastBuildDate>Mon, 06 Feb 2012 17:02:26 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Get ALL table and column descriptions in MSSQL</title>
		<link>http://www.techish.net/2012/02/get-all-table-and-column-descriptions-in-mssql/</link>
		<comments>http://www.techish.net/2012/02/get-all-table-and-column-descriptions-in-mssql/#comments</comments>
		<pubDate>Thu, 02 Feb 2012 21:01:54 +0000</pubDate>
		<dc:creator>Rich Kreider</dc:creator>
				<category><![CDATA[Windows]]></category>
		<category><![CDATA[mssql]]></category>
		<category><![CDATA[ms_description]]></category>
		<category><![CDATA[sql]]></category>

		<guid isPermaLink="false">http://www.techish.net/?p=1740</guid>
		<description><![CDATA[Get MS_Description from all tables AND columns in a database. Suh-weet. SELECT u.name + '.' + t.name AS [table], td.value AS [table_desc], c.name AS [column], cd.value AS [column_desc] FROM sysobjects t INNER JOIN sysusers u ON u.uid = t.uid LEFT &#8230; <a href="http://www.techish.net/2012/02/get-all-table-and-column-descriptions-in-mssql/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Get MS_Description from all tables AND columns in a database.  Suh-weet.</p>
<pre>SELECT          u.name + '.' + t.name AS [table],
            td.value AS [table_desc],
                c.name AS [column],
                cd.value AS [column_desc]
FROM            sysobjects t
INNER JOIN  sysusers u
    ON          u.uid = t.uid
LEFT OUTER JOIN sys.extended_properties td
    ON          td.major_id = t.id
    AND         td.minor_id = 0
    AND         td.name = 'MS_Description'
INNER JOIN  syscolumns c
    ON          c.id = t.id
LEFT OUTER JOIN sys.extended_properties cd
    ON          cd.major_id = c.id
    AND         cd.minor_id = c.colid
    AND         cd.name = 'MS_Description'
WHERE t.type = 'u'
--ORDER BY    t.name, c.colorder
ORDER BY [table], [column] ASC -- for my own use
</pre>
<p>Source:  <a href="http://stackoverflow.com/a/887414" target="_blank">http://stackoverflow.com/a/887414</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.techish.net/2012/02/get-all-table-and-column-descriptions-in-mssql/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>SQL Performance Monitoring</title>
		<link>http://www.techish.net/2012/01/sql-performance-monitoring/</link>
		<comments>http://www.techish.net/2012/01/sql-performance-monitoring/#comments</comments>
		<pubDate>Thu, 26 Jan 2012 16:13:26 +0000</pubDate>
		<dc:creator>Rich Kreider</dc:creator>
				<category><![CDATA[Windows]]></category>
		<category><![CDATA[counters]]></category>
		<category><![CDATA[monitoring]]></category>
		<category><![CDATA[perfmon]]></category>
		<category><![CDATA[performance]]></category>
		<category><![CDATA[sql]]></category>

		<guid isPermaLink="false">http://www.techish.net/?p=1699</guid>
		<description><![CDATA[I have read numerous articles all over the &#8216;net regarding performance counters to monitor, etc. This is a snapshot of a typical performance monitoring session I use to track down performance issues or review the system at any given point. &#8230; <a href="http://www.techish.net/2012/01/sql-performance-monitoring/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>I have read numerous articles all over the &#8216;net regarding performance counters to monitor, etc.</p>
<p>This is a snapshot of a typical performance monitoring session I use to track down performance issues or review the system at any given point.</p>
<div id="attachment_1700" class="wp-caption alignnone" style="width: 773px"><a href="http://www.techish.net/wp-content/uploads//2012/01/2012-01-26_111532.png"><img class="size-full wp-image-1700 colorbox-1699" title="2012-01-26_111532" src="http://www.techish.net/wp-content/uploads//2012/01/2012-01-26_111532.png" alt="" width="763" height="513" /></a><p class="wp-caption-text">SQL and System Performance Counters</p></div>
<p>&nbsp;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.techish.net/2012/01/sql-performance-monitoring/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>SQLIO Scripts and Graphs</title>
		<link>http://www.techish.net/2012/01/sqlio-scripts-and-graphs/</link>
		<comments>http://www.techish.net/2012/01/sqlio-scripts-and-graphs/#comments</comments>
		<pubDate>Tue, 24 Jan 2012 23:27:51 +0000</pubDate>
		<dc:creator>Rich Kreider</dc:creator>
				<category><![CDATA[Windows]]></category>
		<category><![CDATA[performance]]></category>
		<category><![CDATA[sql]]></category>
		<category><![CDATA[sqlio]]></category>

		<guid isPermaLink="false">http://www.techish.net/?p=1685</guid>
		<description><![CDATA[One of probably hundreds of SQL scripts out there. This is what I made and use&#8230; and I like it. There are a lot of other scripts out there that are available and even an SQLIO GUI.  Here are a &#8230; <a href="http://www.techish.net/2012/01/sqlio-scripts-and-graphs/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>One of probably hundreds of SQL scripts out there. This is what I made and use&#8230; and I like it.</p>
<p>There are a lot of other scripts out there that are available and even an SQLIO GUI.  Here are a few I looked at myself.</p>
<p><a href="https://github.com/SQLServerIO/SQLIOToolSet" target="_blank">SQLIOToolSet</a><br />
<a href="http://sourceforge.net/projects/sqliogui/" target="_blank">SQLIO GUI</a> (<a href="http://www.techish.net/wp-content/uploads//2012/01/2012-01-24_182258.png" target="_blank">screenshot</a>)<br />
<a href="http://blog.ashdar-partners.com/2008/05/parsing-sqlio-output-with-powershell.html" target="_blank">SQLIO.Scripts</a></p>
<p>My script is a basic DOS batch file that automates collecting statistics on a few different drives when you&#8217;re testing.  You need to make sure you have created the %TESTFILE% on the root of the drives you want to test.  I create, and I suspect most others do as well, a testfile.dat on the root of each drive I test.  <strong>You&#8217;ll need to create this before running the script or it will break!</strong></p>
<p>If you want to extend this script, it&#8217;s easy.  All the testing is put into a function called RUN_BENCHMARK which is called and passed a drive letter argument.  So if you want to add more tests, feel free.  Just mimic the existing code in that stanza and you should be ok.</p>
<div id="attachment_1686" class="wp-caption alignnone" style="width: 672px"><a href="http://www.techish.net/wp-content/uploads//2012/01/2012-01-24_181944.png"><img class="size-full wp-image-1686 colorbox-1685" title="2012-01-24_181944" src="http://www.techish.net/wp-content/uploads//2012/01/2012-01-24_181944.png" alt="" width="662" height="327" /></a><p class="wp-caption-text">SQLIO Batch Script</p></div>
<p>&nbsp;</p>
<div id="attachment_1695" class="wp-caption alignnone" style="width: 674px"><a href="http://www.techish.net/wp-content/uploads//2012/01/2012-01-24_191326.png"><img class="size-full wp-image-1695 colorbox-1685" title="2012-01-24_191326" src="http://www.techish.net/wp-content/uploads//2012/01/2012-01-24_191326.png" alt="" width="664" height="497" /></a><p class="wp-caption-text">Finish SQLIO Benchmarking</p></div>
<div id="attachment_1689" class="wp-caption alignnone" style="width: 765px"><a href="http://www.techish.net/wp-content/uploads//2012/01/2012-01-24_183001.png"><img class="size-full wp-image-1689 colorbox-1685" title="2012-01-24_183001" src="http://www.techish.net/wp-content/uploads//2012/01/2012-01-24_183001.png" alt="" width="755" height="456" /></a><p class="wp-caption-text">SQLIOResults Combined Disk IOPS Graph</p></div>
<pre>@echo off
setlocal

: This script will benchmark a HDD using SQLIO and store results in the
: RESULTS_LOGFILE_NAME%_%X.txt where X is the drive letter(s) benchmarked
: in the current path and TIME is the timestamp the script was run.

: YOU MUST HAVE CREATED THE %TESTFILE% ON EACH DRIVE.

: Set duration of each test in seconds
set DURATION=30
: Set the buffering.  N=none, Y=all, H=hdwr, S=sfwr
set BUFFERING=H
: Set latencies from (S=system, P=processor) timer
set LATENCY=S
: Filename of test file created already.  You can specify a full path if needed.  If spaces
: exist in path or name, use quotes.
set TESTFILE=testfile.dat
: The log file name (prepend) - log file is stored in the same location this script is run
: from.  You could specifiy a path if you wanted.
set RESULTS_LOGFILE_NAME=%COMPUTERNAME%_%TIME::=%_results
: Drive(s) to run the tests on.  Separate each drive with a comma.
set TEST_DRIVES=E,F,G
: Set the log to either 1-combine or 0-separate.  If separated, a file will be generated
: for each TEST_DRIVES disk.
set COMBINE_LOG=1

: I should do some error checking, but I'm not going to.
: Future plans:

IF ["%TEST_DRIVES%"]==[] call:MissingDrive &#038; goto EOF

cls
color 1F
echo Benchmark of drive(s) %TEST_DRIVES% start:  %DATE% %TIME%
echo.
echo.
echo This will take some time.  The background will become green once the
echo benchmarking completes.  Go grab some coffee and read up on the latest
echo news of the world.
echo.
echo.

for /D %%D in (%TEST_DRIVES%) do (call:RUN_BENCHMARK %%D)
GOTO END

:RUN_BENCHMARK
IF [%1]==[] call:MissingDrive

IF [%COMBINE_LOG%]==[1] (
set APPEND=COMBINED
) ELSE (
set APPEND=%1
)

echo Benchmark [%1] begin:  %DATE% %TIME%
echo [%1] RANDOM WRITES (64K)
sqlio -d%1 -B%BUFFERING% -kW -frandom -t1 -o1 -s%DURATION% -b64 -L%LATENCY% %TESTFILE% >>%RESULTS_LOGFILE_NAME%_%APPEND%.txt
sqlio -d%1 -B%BUFFERING% -kW -frandom -t2 -o1 -s%DURATION% -b64 -L%LATENCY% %TESTFILE% >>%RESULTS_LOGFILE_NAME%_%APPEND%.txt
sqlio -d%1 -B%BUFFERING% -kW -frandom -t4 -o1 -s%DURATION% -b64 -L%LATENCY% %TESTFILE% >>%RESULTS_LOGFILE_NAME%_%APPEND%.txt
sqlio -d%1 -B%BUFFERING% -kW -frandom -t8 -o1 -s%DURATION% -b64 -L%LATENCY% %TESTFILE% >>%RESULTS_LOGFILE_NAME%_%APPEND%.txt
echo [%1] RANDOM READS (64K)
sqlio -d%1 -B%BUFFERING% -kR -frandom -t1 -o1 -s%DURATION% -b64 -L%LATENCY% %TESTFILE% >>%RESULTS_LOGFILE_NAME%_%APPEND%.txt
sqlio -d%1 -B%BUFFERING% -kR -frandom -t2 -o1 -s%DURATION% -b64 -L%LATENCY% %TESTFILE% >>%RESULTS_LOGFILE_NAME%_%APPEND%.txt
sqlio -d%1 -B%BUFFERING% -kR -frandom -t4 -o1 -s%DURATION% -b64 -L%LATENCY% %TESTFILE% >>%RESULTS_LOGFILE_NAME%_%APPEND%.txt
sqlio -d%1 -B%BUFFERING% -kR -frandom -t8 -o1 -s%DURATION% -b64 -L%LATENCY% %TESTFILE% >>%RESULTS_LOGFILE_NAME%_%APPEND%.txt
sqlio -d%1 -B%BUFFERING% -kR -frandom -t8 -o2 -s%DURATION% -b64 -L%LATENCY% %TESTFILE% >>%RESULTS_LOGFILE_NAME%_%APPEND%.txt
sqlio -d%1 -B%BUFFERING% -kR -frandom -t8 -o4 -s%DURATION% -b64 -L%LATENCY% %TESTFILE% >>%RESULTS_LOGFILE_NAME%_%APPEND%.txt
sqlio -d%1 -B%BUFFERING% -kR -frandom -t8 -o8 -s%DURATION% -b64 -L%LATENCY% %TESTFILE% >>%RESULTS_LOGFILE_NAME%_%APPEND%.txt
sqlio -d%1 -B%BUFFERING% -kR -frandom -t8 -o16 -s%DURATION% -b64 -L%LATENCY% %TESTFILE% >>%RESULTS_LOGFILE_NAME%_%APPEND%.txt
sqlio -d%1 -B%BUFFERING% -kR -frandom -t8 -o32 -s%DURATION% -b64 -L%LATENCY% %TESTFILE% >>%RESULTS_LOGFILE_NAME%_%APPEND%.txt
sqlio -d%1 -B%BUFFERING% -kR -frandom -t8 -o64 -s%DURATION% -b64 -L%LATENCY% %TESTFILE% >>%RESULTS_LOGFILE_NAME%_%APPEND%.txt
sqlio -d%1 -B%BUFFERING% -kR -frandom -t8 -o128 -s%DURATION% -b64 -L%LATENCY% %TESTFILE% >>%RESULTS_LOGFILE_NAME%_%APPEND%.txt
echo [%1] SEQUENTIAL READS (64K)
sqlio -d%1 -B%BUFFERING% -kR -fsequential -t1 -o1 -s%DURATION% -b64 -L%LATENCY% %TESTFILE% >>%RESULTS_LOGFILE_NAME%_%APPEND%.txt
sqlio -d%1 -B%BUFFERING% -kR -fsequential -t2 -o1 -s%DURATION% -b64 -L%LATENCY% %TESTFILE% >>%RESULTS_LOGFILE_NAME%_%APPEND%.txt
sqlio -d%1 -B%BUFFERING% -kR -fsequential -t4 -o1 -s%DURATION% -b64 -L%LATENCY% %TESTFILE% >>%RESULTS_LOGFILE_NAME%_%APPEND%.txt
sqlio -d%1 -B%BUFFERING% -kR -fsequential -t8 -o1 -s%DURATION% -b64 -L%LATENCY% %TESTFILE% >>%RESULTS_LOGFILE_NAME%_%APPEND%.txt
sqlio -d%1 -B%BUFFERING% -kR -fsequential -t8 -o2 -s%DURATION% -b64 -L%LATENCY% %TESTFILE% >>%RESULTS_LOGFILE_NAME%_%APPEND%.txt
sqlio -d%1 -B%BUFFERING% -kR -fsequential -t8 -o4 -s%DURATION% -b64 -L%LATENCY% %TESTFILE% >>%RESULTS_LOGFILE_NAME%_%APPEND%.txt
sqlio -d%1 -B%BUFFERING% -kR -fsequential -t8 -o8 -s%DURATION% -b64 -L%LATENCY% %TESTFILE% >>%RESULTS_LOGFILE_NAME%_%APPEND%.txt
sqlio -d%1 -B%BUFFERING% -kR -fsequential -t8 -o16 -s%DURATION% -b64 -L%LATENCY% %TESTFILE% >>%RESULTS_LOGFILE_NAME%_%APPEND%.txt
sqlio -d%1 -B%BUFFERING% -kR -fsequential -t8 -o32 -s%DURATION% -b64 -L%LATENCY% %TESTFILE% >>%RESULTS_LOGFILE_NAME%_%APPEND%.txt
sqlio -d%1 -B%BUFFERING% -kR -fsequential -t8 -o64 -s%DURATION% -b64 -L%LATENCY% %TESTFILE% >>%RESULTS_LOGFILE_NAME%_%APPEND%.txt
sqlio -d%1 -B%BUFFERING% -kR -fsequential -t8 -o128 -s%DURATION% -b64 -L%LATENCY% %TESTFILE% >>%RESULTS_LOGFILE_NAME%_%APPEND%.txt
echo [%1] SEQUENTIAL WRITES (8K blocks to mimic SQL Logfiles)
sqlio -d%1 -B%BUFFERING% -kW -fsequential -t1 -o1 -s%DURATION% -b8 -L%LATENCY% %TESTFILE% >>%RESULTS_LOGFILE_NAME%_%APPEND%.txt
sqlio -d%1 -B%BUFFERING% -kW -fsequential -t2 -o1 -s%DURATION% -b8 -L%LATENCY% %TESTFILE% >>%RESULTS_LOGFILE_NAME%_%APPEND%.txt
sqlio -d%1 -B%BUFFERING% -kW -fsequential -t4 -o1 -s%DURATION% -b8 -L%LATENCY% %TESTFILE% >>%RESULTS_LOGFILE_NAME%_%APPEND%.txt
sqlio -d%1 -B%BUFFERING% -kW -fsequential -t8 -o1 -s%DURATION% -b8 -L%LATENCY% %TESTFILE% >>%RESULTS_LOGFILE_NAME%_%APPEND%.txt
sqlio -d%1 -B%BUFFERING% -kW -fsequential -t8 -o2 -s%DURATION% -b8 -L%LATENCY% %TESTFILE% >>%RESULTS_LOGFILE_NAME%_%APPEND%.txt
sqlio -d%1 -B%BUFFERING% -kW -fsequential -t8 -o4 -s%DURATION% -b8 -L%LATENCY% %TESTFILE% >>%RESULTS_LOGFILE_NAME%_%APPEND%.txt
sqlio -d%1 -B%BUFFERING% -kW -fsequential -t8 -o8 -s%DURATION% -b8 -L%LATENCY% %TESTFILE% >>%RESULTS_LOGFILE_NAME%_%APPEND%.txt
sqlio -d%1 -B%BUFFERING% -kW -fsequential -t8 -o16 -s%DURATION% -b8 -L%LATENCY% %TESTFILE% >>%RESULTS_LOGFILE_NAME%_%APPEND%.txt
sqlio -d%1 -B%BUFFERING% -kW -fsequential -t8 -o32 -s%DURATION% -b8 -L%LATENCY% %TESTFILE% >>%RESULTS_LOGFILE_NAME%_%APPEND%.txt
sqlio -d%1 -B%BUFFERING% -kW -fsequential -t8 -o64 -s%DURATION% -b8 -L%LATENCY% %TESTFILE% >>%RESULTS_LOGFILE_NAME%_%APPEND%.txt
sqlio -d%1 -B%BUFFERING% -kW -fsequential -t8 -o128 -s%DURATION% -b8 -L%LATENCY% %TESTFILE% >>%RESULTS_LOGFILE_NAME%_%APPEND%.txt
echo Benchmark [%1] complete:  %DATE% %TIME%
echo.
echo.
GOTO EOF

:MissingDrive
color CF
echo Missing drive.  Specify %%TEST_DRIVE%% variable please.
goto EOF

:END
color 2F
echo Benchmark of drive(s) [%TEST_DRIVES%] completed:  %DATE% %TIME%

endlocal

:EOF</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.techish.net/2012/01/sqlio-scripts-and-graphs/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>SQL Show Jobs that Will Run</title>
		<link>http://www.techish.net/2012/01/sql-show-jobs-that-will-run/</link>
		<comments>http://www.techish.net/2012/01/sql-show-jobs-that-will-run/#comments</comments>
		<pubDate>Wed, 18 Jan 2012 22:05:50 +0000</pubDate>
		<dc:creator>Rich Kreider</dc:creator>
				<category><![CDATA[Windows]]></category>
		<category><![CDATA[sql]]></category>
		<category><![CDATA[sysjobschedules]]></category>
		<category><![CDATA[tsql]]></category>

		<guid isPermaLink="false">http://www.techish.net/?p=1677</guid>
		<description><![CDATA[This will show jobs that will run. I lost the link I found this at. Eventually, I need to add a few columns to report scheduling information, etc. This is a nice start though. USE msdb ;WITH CTE AS (SELECT &#8230; <a href="http://www.techish.net/2012/01/sql-show-jobs-that-will-run/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>This will show jobs that will run.  I lost the link I found this at.  Eventually, I need to add a few columns to report scheduling information, etc.  This is a nice start though.</p>
<pre>USE msdb
;WITH CTE AS (SELECT schedule_id, job_id, RIGHT('0'+CAST(next_run_time AS VARCHAR(6)),6) AS next_run_time, next_run_date
FROM sysjobschedules)
SELECT A.name Job_Name,
'Will be running today at '+
SUBSTRING(CONVERT(VARCHAR(10), CASE WHEN SUBSTRING (CONVERT(VARCHAR(10),next_run_time) , 1 ,2) > 12
THEN SUBSTRING (CONVERT(VARCHAR(10),next_run_time),1,2) -12
ELSE SUBSTRING (CONVERT(VARCHAR(10),next_run_time),1,2) END),1,2)
+':'+SUBSTRING (CONVERT(VARCHAR(10), next_run_time),3,2)
+':'+SUBSTRING (CONVERT(VARCHAR(10), next_run_time ),5,2) 'Scheduled At'
FROM sysjobs A ,CTE B
WHERE A.job_id = B.job_id
AND SUBSTRING(CONVERT(VARCHAR(10),next_run_date) , 5,2) +'/'+
SUBSTRING(CONVERT(VARCHAR(10),next_run_date) , 7,2) +'/'+
SUBSTRING(CONVERT(VARCHAR(10),next_run_date),1,4) = CONVERT(VARCHAR(10),GETDATE(),101)
AND (SUBSTRING( CONVERT(VARCHAR(10),
CASE WHEN SUBSTRING (CONVERT(VARCHAR(10),next_run_time) , 1 ,2) > 12
THEN SUBSTRING (CONVERT(VARCHAR(10),next_run_time) , 1 ,2) -12
ELSE SUBSTRING (CONVERT(VARCHAR(10),next_run_time) , 1 ,2) END),1,2)
+':'+SUBSTRING (CONVERT(VARCHAR(10), next_run_time ),3,2)
+':'+SUBSTRING (CONVERT(VARCHAR(10), next_run_time ),5,2)) >
SUBSTRING (CONVERT( VARCHAR(30) , GETDATE(),9),13,7)</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.techish.net/2012/01/sql-show-jobs-that-will-run/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Check Fragmentation on Objects in SQL Database</title>
		<link>http://www.techish.net/2012/01/check-fragmentation-on-objects-in-sql-database/</link>
		<comments>http://www.techish.net/2012/01/check-fragmentation-on-objects-in-sql-database/#comments</comments>
		<pubDate>Wed, 18 Jan 2012 20:16:37 +0000</pubDate>
		<dc:creator>Rich Kreider</dc:creator>
				<category><![CDATA[Windows]]></category>
		<category><![CDATA[fragmentation]]></category>
		<category><![CDATA[sql]]></category>

		<guid isPermaLink="false">http://www.techish.net/?p=1675</guid>
		<description><![CDATA[tsql so I can remember in the future. declare @db_id int declare @object_id int set @db_id = DB_ID('EMR') set @object_id = 0 select  db_name(@db_id) as [database], object_id, object_name(object_id, @db_id) as object_name, index_id, avg_fragmentation_in_percent, page_count from sys.dm_db_index_physical_stats(@db_id, null, null, null, 'LIMITED') &#8230; <a href="http://www.techish.net/2012/01/check-fragmentation-on-objects-in-sql-database/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>tsql so I can remember in the future.</p>
<pre>declare @db_id int
declare @object_id int
set @db_id = DB_ID('EMR')
set @object_id = 0
select  db_name(@db_id) as [database], object_id, object_name(object_id, @db_id) as object_name,
index_id,
avg_fragmentation_in_percent,
page_count
from sys.dm_db_index_physical_stats(@db_id, null, null, null, 'LIMITED')
where page_count &gt; 1000
and
avg_fragmentation_in_percent &gt; 35
order by avg_fragmentation_in_percent desc</pre>
<pre>database                                                                                                                         object_id   object_name                                                                                                                      index_id    avg_fragmentation_in_percent page_count
-------------------------------------------------------------------------------------------------------------------------------- ----------- -------------------------------------------------------------------------------------------------------------------------------- ----------- ---------------------------- --------------------
EMR                                                                                                                              1091587027  ARCH_HXDIAGNOSIS                                                                                                                 1           35.2092352092352             1386</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.techish.net/2012/01/check-fragmentation-on-objects-in-sql-database/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

