<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://sqlblog.com/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Search results matching tags 'Administration' and 'T-SQL'</title><link>http://sqlblog.com/search/SearchResults.aspx?o=DateDescending&amp;tag=Administration,T-SQL&amp;orTags=0</link><description>Search results matching tags 'Administration' and 'T-SQL'</description><dc:language>en-US</dc:language><generator>CommunityServer 2.1 SP2 (Build: 61129.1)</generator><item><title>Backup Meta-Data</title><link>http://sqlblog.com/blogs/buck_woody/archive/2010/03/30/backup-meta-data.aspx</link><pubDate>Tue, 30 Mar 2010 14:46:00 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:23870</guid><dc:creator>BuckWoody</dc:creator><description>&lt;P&gt;I'm working on a PowerShell script to show me the trending durations of my backup activities. The first thing I need is the data, so I looked at the Standard Reports in SQL Server Management Studio, and found a report that suited my needs, so I pulled out the script that it runs and modified it to this T-SQL Script. &lt;/P&gt;
&lt;P&gt;A few words here - you need to be in the MSDB database for this to run, and you can add a WHERE clause to limit to a database, timeframe, type of backup, whatever. For that matter, I won't use all of the data in this query in my PowerShell script, but it gives me lots of avenues to graph:&lt;/P&gt;
&lt;P&gt;&lt;FONT color=#009900&gt;SELECT distinct t1.name AS 'DatabaseName'&lt;/FONT&gt;&lt;/P&gt;
&lt;P style="MARGIN:0in;FONT-FAMILY:Calibri;FONT-SIZE:11pt;"&gt;&lt;FONT color=#009900&gt;,(datediff( ss,&lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp; &lt;/SPAN&gt;t3.backup_start_date, t3.backup_finish_date)) AS 'DurationInSeconds'&lt;/FONT&gt;&lt;/P&gt;
&lt;P style="MARGIN:0in;FONT-FAMILY:Calibri;FONT-SIZE:11pt;"&gt;&lt;FONT color=#009900&gt;,t3.user_name AS 'UserResponsible'&lt;/FONT&gt;&lt;/P&gt;
&lt;P style="MARGIN:0in;FONT-FAMILY:Calibri;FONT-SIZE:11pt;"&gt;&lt;FONT color=#009900&gt;,t3.name AS backup_name&lt;/FONT&gt;&lt;/P&gt;
&lt;P style="MARGIN:0in;FONT-FAMILY:Calibri;FONT-SIZE:11pt;"&gt;&lt;FONT color=#009900&gt;,t3.description&lt;/FONT&gt;&lt;/P&gt;
&lt;P style="MARGIN:0in;FONT-FAMILY:Calibri;FONT-SIZE:11pt;"&gt;&lt;FONT color=#009900&gt;,t3.backup_start_date&lt;/FONT&gt;&lt;/P&gt;
&lt;P style="MARGIN:0in;FONT-FAMILY:Calibri;FONT-SIZE:11pt;"&gt;&lt;FONT color=#009900&gt;,t3.backup_finish_date&lt;/FONT&gt;&lt;/P&gt;
&lt;P style="MARGIN:0in;FONT-FAMILY:Calibri;FONT-SIZE:11pt;"&gt;&lt;FONT color=#009900&gt;,CASE WHEN t3.type = 'D' THEN 'Database'&lt;/FONT&gt;&lt;/P&gt;
&lt;P style="MARGIN:0in;FONT-FAMILY:Calibri;FONT-SIZE:11pt;"&gt;&lt;FONT color=#009900&gt;WHEN t3.type = 'L' THEN 'Log'&lt;/FONT&gt;&lt;/P&gt;
&lt;P style="MARGIN:0in;FONT-FAMILY:Calibri;FONT-SIZE:11pt;"&gt;&lt;FONT color=#009900&gt;WHEN t3.type = 'F' THEN 'FileOrFilegroup'&lt;/FONT&gt;&lt;/P&gt;
&lt;P style="MARGIN:0in;FONT-FAMILY:Calibri;FONT-SIZE:11pt;"&gt;&lt;FONT color=#009900&gt;WHEN t3.type = 'G' THEN 'DifferentialFile'&lt;/FONT&gt;&lt;/P&gt;
&lt;P style="MARGIN:0in;FONT-FAMILY:Calibri;FONT-SIZE:11pt;"&gt;&lt;FONT color=#009900&gt;WHEN t3.type = 'P' THEN 'Partial'&lt;/FONT&gt;&lt;/P&gt;
&lt;P style="MARGIN:0in;FONT-FAMILY:Calibri;FONT-SIZE:11pt;"&gt;&lt;FONT color=#009900&gt;WHEN t3.type = 'Q' THEN 'DifferentialPartial'&lt;/FONT&gt;&lt;/P&gt;
&lt;P style="MARGIN:0in;FONT-FAMILY:Calibri;FONT-SIZE:11pt;"&gt;&lt;FONT color=#009900&gt;END AS 'BackupType'&lt;/FONT&gt;&lt;/P&gt;
&lt;P style="MARGIN:0in;FONT-FAMILY:Calibri;FONT-SIZE:11pt;"&gt;&lt;FONT color=#009900&gt;,t3.backup_size AS 'BackupSizeKB' &lt;/FONT&gt;&lt;/P&gt;
&lt;P style="MARGIN:0in;FONT-FAMILY:Calibri;FONT-SIZE:11pt;"&gt;&lt;FONT color=#009900&gt;,t6.physical_device_name&lt;/FONT&gt;&lt;/P&gt;
&lt;P style="MARGIN:0in;FONT-FAMILY:Calibri;FONT-SIZE:11pt;"&gt;&lt;FONT color=#009900&gt;,CASE WHEN t6.device_type = 2 THEN 'Disk'&lt;/FONT&gt;&lt;/P&gt;
&lt;P style="MARGIN:0in;FONT-FAMILY:Calibri;FONT-SIZE:11pt;"&gt;&lt;FONT color=#009900&gt;WHEN t6.device_type = 102 THEN 'Disk'&lt;/FONT&gt;&lt;/P&gt;
&lt;P style="MARGIN:0in;FONT-FAMILY:Calibri;FONT-SIZE:11pt;"&gt;&lt;FONT color=#009900&gt;WHEN t6.device_type = 5 THEN 'Tape'&lt;/FONT&gt;&lt;/P&gt;
&lt;P style="MARGIN:0in;FONT-FAMILY:Calibri;FONT-SIZE:11pt;"&gt;&lt;FONT color=#009900&gt;WHEN t6.device_type = 105 THEN 'Tape'&lt;/FONT&gt;&lt;/P&gt;
&lt;P style="MARGIN:0in;FONT-FAMILY:Calibri;FONT-SIZE:11pt;"&gt;&lt;FONT color=#009900&gt;END AS 'DeviceType'&lt;/FONT&gt;&lt;/P&gt;
&lt;P style="MARGIN:0in;FONT-FAMILY:Calibri;FONT-SIZE:11pt;"&gt;&lt;FONT color=#009900&gt;,t3.recovery_model&lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp; &lt;/SPAN&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P style="MARGIN:0in;FONT-FAMILY:Calibri;FONT-SIZE:11pt;"&gt;&lt;FONT color=#009900&gt;FROM sys.databases t1 &lt;/FONT&gt;&lt;/P&gt;
&lt;P style="MARGIN:0in 0in 0in 0.375in;FONT-FAMILY:Calibri;FONT-SIZE:11pt;"&gt;&lt;FONT color=#009900&gt;INNER JOIN backupset t3 &lt;/FONT&gt;&lt;/P&gt;
&lt;P style="MARGIN:0in 0in 0in 0.75in;FONT-FAMILY:Calibri;FONT-SIZE:11pt;"&gt;&lt;FONT color=#009900&gt;ON (t3.database_name = t1.name )&lt;SPAN style="mso-spacerun:yes;"&gt;&amp;nbsp; &lt;/SPAN&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P style="MARGIN:0in 0in 0in 0.375in;FONT-FAMILY:Calibri;FONT-SIZE:11pt;"&gt;&lt;FONT color=#009900&gt;LEFT OUTER JOIN backupmediaset t5 &lt;/FONT&gt;&lt;/P&gt;
&lt;P style="MARGIN:0in 0in 0in 0.75in;FONT-FAMILY:Calibri;FONT-SIZE:11pt;"&gt;&lt;FONT color=#009900&gt;ON ( t3.media_set_id = t5.media_set_id ) &lt;/FONT&gt;&lt;/P&gt;
&lt;P style="MARGIN:0in 0in 0in 0.375in;FONT-FAMILY:Calibri;FONT-SIZE:11pt;"&gt;&lt;FONT color=#009900&gt;LEFT OUTER JOIN backupmediafamily t6 &lt;/FONT&gt;&lt;/P&gt;
&lt;P style="MARGIN:0in 0in 0in 0.75in;FONT-FAMILY:Calibri;FONT-SIZE:11pt;"&gt;&lt;FONT color=#009900&gt;ON ( t6.media_set_id = t5.media_set_id ) &lt;/FONT&gt;&lt;/P&gt;
&lt;P style="MARGIN:0in;FONT-FAMILY:Calibri;FONT-SIZE:11pt;"&gt;&lt;FONT color=#009900&gt;ORDER BY backup_start_date DESC&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;I'll munge this into my Excel PowerShell chart script tomorrow.&lt;/P&gt;
&lt;P style="MARGIN:0in 0in 0pt;mso-margin-top-alt:auto;mso-margin-bottom-alt:auto;" class=MsoNormal&gt;&lt;FONT face=Calibri&gt;&lt;B&gt;&lt;I style="mso-bidi-font-style:normal;"&gt;&lt;SPAN style="COLOR:maroon;FONT-SIZE:10pt;mso-bidi-font-size:11.0pt;mso-bidi-font-family:Calibri;mso-ansi-language:EN;"&gt;Script Disclaimer, for people who need to be told this sort of thing: &lt;/SPAN&gt;&lt;/I&gt;&lt;/B&gt;&lt;B&gt;&lt;I style="mso-bidi-font-style:normal;"&gt;&lt;SPAN style="COLOR:maroon;FONT-SIZE:10pt;mso-bidi-font-family:Calibri;mso-ansi-language:EN;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/I&gt;&lt;/B&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P style="MARGIN:0in 0in 0pt;" class=MsoNormal&gt;&lt;I style="mso-bidi-font-style:normal;"&gt;&lt;SPAN style="COLOR:maroon;FONT-SIZE:10pt;mso-bidi-font-family:Calibri;mso-ansi-language:EN;"&gt;&lt;FONT face=Calibri&gt;Never trust any script, including those that you find here, until you understand exactly what it does and how it will act on your systems. Always check the script on a test system or Virtual Machine, not a production system. Yes, there are always multiple ways to do things, and this script may not work in every situation, for everything. It’s just a script, people. All scripts on this site are performed by a professional stunt driver on a closed course. Your mileage may vary. Void where prohibited. Offer good for a limited time only. Keep out of reach of small children. Do not operate heavy machinery while using this script. If you experience blurry vision, indigestion or diarrhea&amp;nbsp;during the operation of this script, see a physician immediately.&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/I&gt;&lt;/P&gt;</description></item><item><title>System Variables, Stored Procedures or Functions for Meta Data</title><link>http://sqlblog.com/blogs/buck_woody/archive/2010/03/11/system-variables-stored-procedures-or-functions-for-meta-data.aspx</link><pubDate>Thu, 11 Mar 2010 13:42:22 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:23190</guid><dc:creator>BuckWoody</dc:creator><description>&lt;p&gt;Whenever you want to know something about SQL Server’s configuration, whether that’s the Instance itself or a database, you have a few options.&lt;/p&gt;  &lt;p&gt;If you want to know “dynamic” data, such as how much memory or CPU is consumed or what a particular query is doing, you should be using the Dynamic Management Views (DMVs) that you can read about here: &lt;a href="http://msdn.microsoft.com/en-us/library/ms188754.aspx"&gt;http://msdn.microsoft.com/en-us/library/ms188754.aspx&lt;/a&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;But if you’re looking for how much memory is installed on the server, the version of the Instance, the drive letters of the backups and so on, you have other choices.&lt;/p&gt;  &lt;p&gt;The first of these are system variables. You access these with a SELECT statement, and they are useful when you need a discrete value for use, say in another query or to put into a table. You can read more about those here: &lt;a href="http://msdn.microsoft.com/en-us/library/ms173823.aspx"&gt;http://msdn.microsoft.com/en-us/library/ms173823.aspx&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;You also have a few stored procedures you can use. These often bring back a lot more data, pre-formatted for the screen. You access these with the EXECUTE syntax. It is a bit more difficult to take the data they return and get a single value or place the results in another table, but it is possible. You can read more about those here: &lt;a href="http://msdn.microsoft.com/en-us/library/ms187961.aspx"&gt;http://msdn.microsoft.com/en-us/library/ms187961.aspx&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;Yet another option is to use a system function, which you access with a SELECT statement, which also brings back a discrete value that you can use in a test or to place in another table. You can read about those here: &lt;a href="http://msdn.microsoft.com/en-us/library/ms187812.aspx"&gt;http://msdn.microsoft.com/en-us/library/ms187812.aspx&lt;/a&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;By the way, many of these constructs simply query from tables in the &lt;strong&gt;master &lt;/strong&gt;or &lt;strong&gt;msdb &lt;/strong&gt;databases for the Instance or the &lt;em&gt;system tables&lt;/em&gt; in a user database. You can get much of the information there as well, and there are even system views in each database to show you the meta-data dealing with structure – more on that here: &lt;a href="http://msdn.microsoft.com/en-us/library/ms186778.aspx"&gt;http://msdn.microsoft.com/en-us/library/ms186778.aspx&lt;/a&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;Some of these choices are the only way to get at a certain piece of data. But others overlap – you can use one or the other, they both come back with the same data. So, like many Microsoft products, you have multiple ways to do the same thing. And that’s OK – just research what each is used for and how it’s intended to be used, and you’ll be able to select (pun intended) the right choice. &lt;/p&gt;</description></item></channel></rss>