<?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>Bahramov's Personal Blog &#187; T-SQL</title>
	<atom:link href="http://www.bahramov.com/tag/t-sql/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.bahramov.com</link>
	<description>Computers, databases, networks and virtualization</description>
	<lastBuildDate>Wed, 28 Apr 2010 12:24:28 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=abc</generator>
		<item>
		<title>T-SQL: Find logical name and physical location of system databases</title>
		<link>http://www.bahramov.com/2009/11/03/t-sql-find-logical-name-and-physical-location-of-system-databases/#utm_source=feed&amp;utm_medium=feed&amp;utm_campaign=feed</link>
		<comments>http://www.bahramov.com/2009/11/03/t-sql-find-logical-name-and-physical-location-of-system-databases/#comments</comments>
		<pubDate>Tue, 03 Nov 2009 14:01:04 +0000</pubDate>
		<dc:creator>Zaur Bahramov</dc:creator>
				<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[T-SQL]]></category>
		<category><![CDATA[SQL]]></category>

		<guid isPermaLink="false">http://www.bahramov.com/2009/11/03/t-sql-find-logical-name-and-physical-location-of-system-databases/</guid>
		<description><![CDATA[The following T-SQL statements will print the logical name and physical location of system database files:
USE master;
GO
SELECT name, physical_name AS CurrentLocation, state_desc
FROM sys.master_files
WHERE database_id = DB_ID(N'master')

SELECT name, physical_name AS CurrentLocation, state_desc
FROM sys.master_files
WHERE database_id = DB_ID(N'tempdb')

SELECT name, physical_name AS CurrentLocation, state_desc
FROM sys.master_files
WHERE database_id = DB_ID(N'model')

SELECT name, physical_name AS CurrentLocation, state_desc
FROM sys.master_files
WHERE database_id = DB_ID(N'msdb')

Result:

]]></description>
			<content:encoded><![CDATA[<p>The following T-SQL statements will print the logical name and physical location of system database files:</p>
<pre class="code"><span style="color: blue">USE master</span><span style="color: gray">;
</span><span style="color: blue">GO
SELECT </span>name<span style="color: gray">, </span>physical_name <span style="color: blue">AS </span>CurrentLocation<span style="color: gray">, </span>state_desc
<span style="color: blue">FROM </span><span style="color: green">sys</span><span style="color: gray">.</span><span style="color: green">master_files
</span><span style="color: blue">WHERE </span>database_id <span style="color: gray">= </span><span style="color: magenta">DB_ID</span><span style="color: gray">(</span><span style="color: red">N'master'</span><span style="color: gray">)

</span><span style="color: blue">SELECT </span>name<span style="color: gray">, </span>physical_name <span style="color: blue">AS </span>CurrentLocation<span style="color: gray">, </span>state_desc
<span style="color: blue">FROM </span><span style="color: green">sys</span><span style="color: gray">.</span><span style="color: green">master_files
</span><span style="color: blue">WHERE </span>database_id <span style="color: gray">= </span><span style="color: magenta">DB_ID</span><span style="color: gray">(</span><span style="color: red">N'tempdb'</span><span style="color: gray">)

</span><span style="color: blue">SELECT </span>name<span style="color: gray">, </span>physical_name <span style="color: blue">AS </span>CurrentLocation<span style="color: gray">, </span>state_desc
<span style="color: blue">FROM </span><span style="color: green">sys</span><span style="color: gray">.</span><span style="color: green">master_files
</span><span style="color: blue">WHERE </span>database_id <span style="color: gray">= </span><span style="color: magenta">DB_ID</span><span style="color: gray">(</span><span style="color: red">N'model'</span><span style="color: gray">)

</span><span style="color: blue">SELECT </span>name<span style="color: gray">, </span>physical_name <span style="color: blue">AS </span>CurrentLocation<span style="color: gray">, </span>state_desc
<span style="color: blue">FROM </span><span style="color: green">sys</span><span style="color: gray">.</span><span style="color: green">master_files
</span><span style="color: blue">WHERE </span>database_id <span style="color: gray">= </span><span style="color: magenta">DB_ID</span><span style="color: gray">(</span><span style="color: red">N'msdb'</span><span style="color: gray">)
</span></pre>
<p><strong>Result:</strong></p>
<p><a href="http://www.bahramov.com/wp-content/uploads/2009/11/image.png#utm_source=feed&amp;utm_medium=feed&amp;utm_campaign=feed" title="image"><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://www.bahramov.com/wp-content/uploads/2009/11/image_thumb.png" width="600" height="300" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.bahramov.com/2009/11/03/t-sql-find-logical-name-and-physical-location-of-system-databases/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>SQL Server 2008 Full-Text Search &#8211; Getting list of system stopwords</title>
		<link>http://www.bahramov.com/2009/11/01/sql-server-2008-full-text-search-getting-list-of-system-stopwords/#utm_source=feed&amp;utm_medium=feed&amp;utm_campaign=feed</link>
		<comments>http://www.bahramov.com/2009/11/01/sql-server-2008-full-text-search-getting-list-of-system-stopwords/#comments</comments>
		<pubDate>Sun, 01 Nov 2009 14:12:50 +0000</pubDate>
		<dc:creator>Zaur Bahramov</dc:creator>
				<category><![CDATA[T-SQL]]></category>
		<category><![CDATA[Full-Text Search]]></category>
		<category><![CDATA[SQL Server 2008]]></category>

		<guid isPermaLink="false">http://www.bahramov.com/2009/11/01/sql-server-2008-full-text-search-getting-list-of-system-stopwords/</guid>
		<description><![CDATA[This will get the list of all languages supported by the SQL Server 2008 Full-Text Search:



Code Snippet


 &#8211; to determine run_value corresponding to locale [LCID - LoCale IDentifier]
SELECT lcid, name FROM sys.fulltext_languages



Result: 
lcid&#160;&#160;&#160;&#160;&#160;&#160;&#160; name   &#8212;&#8212;&#8212;&#8211; &#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;    5124&#160;&#160;&#160;&#160;&#160;&#160;&#160; Chinese (Macau SAR)    4100&#160;&#160;&#160;&#160;&#160;&#160;&#160; Chinese (Singapore)    3098&#160;&#160;&#160;&#160;&#160;&#160;&#160; [...]]]></description>
			<content:encoded><![CDATA[<p>This will get the list of all languages supported by the SQL Server 2008 Full-Text Search:</p>
</p>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:c1963708-2d99-43d1-a3a8-2b597b89c14e" class="wlWriterEditableSmartContent">
<div style="border: #000080 1px solid; font-family: 'Courier New', Courier, Monospace; font-size: 10pt">
<div style="background: #000080; color: #fff; font-family: Verdana, Tahoma, Arial, sans-serif; font-weight: bold; padding: 2px 5px">Code Snippet</div>
<div style="background: #ddd; max-height: 300px; overflow: auto">
<ol style="background: #ffffff; margin: 0 0 0 2em; padding: 0 0 0 5px;">
<li> <span style="color:#008000">&#8211; to determine run_value corresponding to locale [LCID - LoCale IDentifier]</span></li>
<li style="background: #f3f3f3"><span style="color:#0000ff">SELECT</span> lcid<span style="color:#808080">,</span> name <span style="color:#0000ff">FROM</span> <span style="color:#008000">sys</span><span style="color:#808080">.</span><span style="color:#008000">fulltext_languages</span></li>
</ol></div>
</p></div>
</p></div>
<p>Result: </p>
<p>lcid&#160;&#160;&#160;&#160;&#160;&#160;&#160; name   <br />&#8212;&#8212;&#8212;&#8211; &#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;    <br />5124&#160;&#160;&#160;&#160;&#160;&#160;&#160; Chinese (Macau SAR)    <br />4100&#160;&#160;&#160;&#160;&#160;&#160;&#160; Chinese (Singapore)    <br />3098&#160;&#160;&#160;&#160;&#160;&#160;&#160; Serbian (Cyrillic)    <br />3082&#160;&#160;&#160;&#160;&#160;&#160;&#160; Spanish    <br />3076&#160;&#160;&#160;&#160;&#160;&#160;&#160; Chinese (Hong Kong SAR, PRC)    <br />2074&#160;&#160;&#160;&#160;&#160;&#160;&#160; Serbian (Latin)    <br />2070&#160;&#160;&#160;&#160;&#160;&#160;&#160; Portuguese    <br />…………….    <br />1036&#160;&#160;&#160;&#160;&#160;&#160;&#160; French    <br />1033&#160;&#160;&#160;&#160;&#160;&#160;&#160; English    <br />1031&#160;&#160;&#160;&#160;&#160;&#160;&#160; German    <br />1028&#160;&#160;&#160;&#160;&#160;&#160;&#160; Traditional Chinese    <br />1027&#160;&#160;&#160;&#160;&#160;&#160;&#160; Catalan    <br />1026&#160;&#160;&#160;&#160;&#160;&#160;&#160; Bulgarian    <br />1025&#160;&#160;&#160;&#160;&#160;&#160;&#160; Arabic    <br />76&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; 76    <br />69&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; 69    <br />25&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; 25    <br />13&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; 13    <br />1&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; 1    <br />0&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; Neutral </p>
<p>(53 row(s) affected)</p>
<p>The following query will bring the list of system stopwords corresponding to the English locale:</p>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:75f02bb9-09ed-44e6-aa0d-1f3c49d6dd80" class="wlWriterEditableSmartContent">
<div style="border: #000080 1px solid; font-family: 'Courier New', Courier, Monospace; font-size: 10pt">
<div style="background: #000080; color: #fff; font-family: Verdana, Tahoma, Arial, sans-serif; font-weight: bold; padding: 2px 5px">Code Snippet</div>
<div style="background: #ddd; max-height: 300px; overflow: auto">
<ol style="background: #ffffff; margin: 0 0 0 2em; padding: 0 0 0 5px;">
<li> <span style="color:#008000">&#8211; list all stopwords corresponding to 1033 locale [English]</span></li>
<li style="background: #f3f3f3"><span style="color:#0000ff">SELECT</span> <span style="color:#808080">*</span> <span style="color:#0000ff">FROM</span> <span style="color:#008000">sys</span><span style="color:#808080">.</span>fulltext_system_stopwords</li>
<li>&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:#0000ff">WHERE</span> language_id <span style="color:#808080">=</span> 1033</li>
</ol></div>
</p></div>
</p></div>
<p>&#160;</p>
<p>When this query is run 154 records containing system stopwords will be returned.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.bahramov.com/2009/11/01/sql-server-2008-full-text-search-getting-list-of-system-stopwords/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Determine Free Disk Space in SQL Server with T-SQL Code</title>
		<link>http://www.bahramov.com/2009/03/18/determine-free-disk-space-in-sql-server-with-t-sql-code/#utm_source=feed&amp;utm_medium=feed&amp;utm_campaign=feed</link>
		<comments>http://www.bahramov.com/2009/03/18/determine-free-disk-space-in-sql-server-with-t-sql-code/#comments</comments>
		<pubDate>Wed, 18 Mar 2009 21:29:17 +0000</pubDate>
		<dc:creator>Zaur Bahramov</dc:creator>
				<category><![CDATA[T-SQL]]></category>
		<category><![CDATA[SQL Server]]></category>

		<guid isPermaLink="false">http://www.bahramov.com/?p=61</guid>
		<description><![CDATA[From: www.mssqltips.com
Problem
At our organization we need to check for a minimum amount of free space before proceeding with some processes that run on SQL Server 2000, 2005 and 2008 SQL Server instances. Do you know of a way to find out the free disk space and then fail the process if it does not meet [...]]]></description>
			<content:encoded><![CDATA[<p>From: <a href="http://www.mssqltips.com/tip.asp?tip=1706">www.mssqltips.com</a></p>
<hr /><span style="text-decoration: underline;"><strong>Problem<br />
</strong></span>At our organization we need to check for a minimum amount of free space before proceeding with some processes that run on SQL Server 2000, 2005 and 2008 SQL Server instances. Do you know of a way to find out the free disk space and then fail the process if it does not meet the minimum requirements?  Can you provide some sample code?</p>
<p><span style="text-decoration: underline;"><strong>Solution<br />
</strong></span>Checking for free disk space before proceeding with a process is a wise move if disk space is tight or a high percentage of the drive is needed for the process.  It is disconcerting to have a process run for hours only to fail towards the end of the process due to insufficient disk space.  Although a few different options are available to check for disk space (CLR, WMI, PowerShell, etc.) in SQL Server, let&#8217;s see how we can use the xp_fixeddrives extended stored procedure which is available in SQL Server 2000 to 2008.</p>
<hr /><em>Sample Stored Procedure to Assess the Free Disk Space on a SQL Server Disk Drive</em></p>
<p>In the sample stored procedure below, it is accepting a parameter for the minimum amount of megabytes (MB) free on a specific disk drive, then executing the master.sys.xp_fixeddrives extended stored procedure into a temporary table.  Once the data is in the temporary table the current amount of free disk space is compared to the minimum amount of free disk space to determine if the process should continue or raise an error.<br />
<span id="more-61"></span><br />
One item to keep in mind is that between SQL Server 2000 and SQL Server 2005/2008 the owner for the xp_fixeddrives extended stored procedure changed.  In SQL Server 2000, xp_fixeddrives was owned by dbo and in SQL Server 2005/2008 the owner is sys.  Due to this ownership change, two stored procedures are provided below.  One for SQL Server 2005/2008 and a second for SQL Server 2000.</p>
<div>
<pre><em><strong>*** NOTE *** - SQL Server 2008 and 2005 Version</strong></em></pre>
</div>
<pre class="brush: sql">
CREATE PROCEDURE dbo.spExec_SufficientDiskSpace @MinMBFree int, @Drive char(1) AS
/*
----------------------------------------------------------------------------
-- Object Name: dbo.spExec_SufficientDiskSpace
-- Project: Admin Scripts
-- Business Process: Monthly Sales Reports
-- Purpose: Validate sufficient disk space
-- Detailed Description: Validate sufficient disk space based on based on the
-- @MBfree and @Drive parameters
-- Database: Admin
-- Dependent Objects: master.sys.xp_fixeddrives
-- Called By: Admin Scripts
-- Upstream Systems: Unknown
-- Downstream Systems: Unknown
--
--------------------------------------------------------------------------------------
-- Rev | CMR | Date Modified | Developer | Change Summary
--------------------------------------------------------------------------------------
-- 001 | N\A | 03.05.2009 | MSSQLTips | Original code
--
*/

SET NOCOUNT ON

-- 1 - Declare variables
DECLARE @MBfree int
DECLARE @CMD1 varchar(1000)

-- 2 - Initialize variables
SET @MBfree = 0
SET @CMD1 = &#039;&#039;

-- 3 - Create temp tables
CREATE TABLE #tbl_xp_fixeddrives
(Drive varchar(2) NOT NULL,
[MB free] int NOT NULL)

-- 4 - Populate #tbl_xp_fixeddrives
INSERT INTO #tbl_xp_fixeddrives(Drive, [MB free])
EXEC master.sys.xp_fixeddrives

-- 5 - Initialize the @MBfree value
SELECT @MBfree = [MB free]
FROM #tbl_xp_fixeddrives
WHERE Drive = @Drive

-- 6 - Determine if sufficient fre space is available
IF @MBfree &gt; @MinMBFree
BEGIN
RETURN
END
ELSE
BEGIN
RAISERROR (&#039;*** ERROR *** - Insufficient disk space.&#039;, 16, 1)
END

-- 7 - DROP TABLE #tbl_xp_fixeddrives
DROP TABLE #tbl_xp_fixeddrives

SET NOCOUNT OFF
GO
</pre>
<div>
<pre><em><strong>*** NOTE *** - SQL Server 2000 Version</strong></em></pre>
</div>
<pre class="brush: sql">CREATE PROCEDURE dbo.spExec_SufficientDiskSpace @MinMBFree int, @Drive char(1) AS
/*
----------------------------------------------------------------------------
-- Object Name: dbo.spExec_SufficientDiskSpace
-- Project: Admin Scripts
-- Business Process: Monthly Sales Reports
-- Purpose: Validate sufficient disk space
-- Detailed Description: Validate sufficient disk space based on based on the
-- @MBfree and @Drive parameters
-- Database: Admin
-- Dependent Objects: master.sys.xp_fixeddrives
-- Called By: Admin Scripts
-- Upstream Systems: Unknown
-- Downstream Systems: Unknown
--
--------------------------------------------------------------------------------------
-- Rev | CMR | Date Modified | Developer | Change Summary
--------------------------------------------------------------------------------------
-- 001 | N\A | 03.05.2009 | MSSQLTips | Original code
--
*/

SET NOCOUNT ON

-- 1 - Declare variables
DECLARE @MBfree int
DECLARE @CMD1 varchar(1000)

-- 2 - Initialize variables
SET @MBfree = 0
SET @CMD1 = &#039;&#039;

-- 3 - Create temp tables
CREATE TABLE #tbl_xp_fixeddrives
(Drive varchar(2) NOT NULL,
[MB free] int NOT NULL)

-- 4 - Populate #tbl_xp_fixeddrives
INSERT INTO #tbl_xp_fixeddrives(Drive, [MB free])
EXEC master.dbo.xp_fixeddrives

-- 5 - Initialize the @MBfree value
SELECT @MBfree = [MB free]
FROM #tbl_xp_fixeddrives
WHERE Drive = @Drive

-- 6 - Determine if sufficient fre space is available
IF @MBfree &gt; @MinMBFree
BEGIN
RETURN
END
ELSE
BEGIN
RAISERROR (&#039;*** ERROR *** - Insufficient disk space.&#039;, 16, 1)
END

-- 7 - DROP TABLE #tbl_xp_fixeddrives
DROP TABLE #tbl_xp_fixeddrives

SET NOCOUNT OFF

GO</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.bahramov.com/2009/03/18/determine-free-disk-space-in-sql-server-with-t-sql-code/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
