<?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; SQL Server</title>
	<atom:link href="http://www.bahramov.com/category/sql-server/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 Service Pack 1 Released</title>
		<link>http://www.bahramov.com/2009/04/08/sql-server-2008-service-pack-1-released/#utm_source=feed&amp;utm_medium=feed&amp;utm_campaign=feed</link>
		<comments>http://www.bahramov.com/2009/04/08/sql-server-2008-service-pack-1-released/#comments</comments>
		<pubDate>Wed, 08 Apr 2009 09:52:37 +0000</pubDate>
		<dc:creator>Zaur Bahramov</dc:creator>
				<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[SQL Server SP1]]></category>

		<guid isPermaLink="false">http://www.bahramov.com/2009/04/08/sql-server-2008-service-pack-1-released/</guid>
		<description><![CDATA[
Today Microsoft Released Service Pack 1 for SQL Server 2008
Some of the changes include:

SQL Server 2008 SP1 has made it easier and more efficient to deploy and manage service packs. By adding the ability to Slipstream, SQL Server 2008 and SP1 can be installed simultaneously. This decreases the total time for an installation, including a [...]]]></description>
			<content:encoded><![CDATA[</p>
<p>Today Microsoft Released Service Pack 1 for SQL Server 2008</p>
<p>Some of the changes include:</p>
<ul>
<li>SQL Server 2008 SP1 has made it easier and more efficient to deploy and manage service packs. By adding the ability to Slipstream, SQL Server 2008 and SP1 can be installed simultaneously. This decreases the total time for an installation, including a fewer number of reboots.      </li>
<li>Service Pack Uninstall allows administrators to uninstall the service pack separately from the database release.      </li>
<li>Report Builder 2.0 Click-Once deployment. Up till now, Report Builder 2.0 was only available as a separate install on the client machines. Now .NET’s Click-Once technology is used so that users can run Report Builder without having to install it first through a setup file locally.      </li>
<li>In addition to the a roll-up of previous cumulative updates, SP1 includes quick fix engineering updates and minor fixes in response to requests reported through the SQL Server community. There are no new feature updates in this service pack. </li>
</ul>
<p> <span id="more-274"></span>
<ul>SQL Server 2008 SP1 has in total 300 fixes included, with the majority being minor tweaks. If you compare this to the SQL Server 2005 SP1, which contained 2’500 fixes, you really see that SQL Server 2008 is a very stable release.</ul>
<p><u>Download information:</u></p>
<p><a href="http://www.microsoft.com/downloads/details.aspx?displaylang=en&amp;FamilyID=66ab3dbb-bf3e-4f46-9559-ccc6a4f9dc19">Microsoft SQL Server Service Pack 1</a> (build 10.00.2531)     <br /><a href="http://www.microsoft.com/downloads/details.aspx?displaylang=en&amp;FamilyID=01af61e6-2f63-4291-bcad-fd500f6027ff">Microsoft® SQL Server® 2008 Express Edition Service Pack 1</a> (build 10.00.2531)     <br /><a href="http://support.microsoft.com/kb/968369">List of the bugs that are fixed in SQL Server 2008 Service Pack 1</a> </p>
<p><u>Other related downloads an links:</u></p>
<ul>
<li><a href="http://www.microsoft.com/downloads/info.aspx?na=40&amp;p=1&amp;SrcDisplayLang=en&amp;SrcCategoryId=&amp;SrcFamilyId=01af61e6-2f63-4291-bcad-fd500f6027ff&amp;u=http%3a%2f%2fgo.microsoft.com%2ffwlink%2f%3fLinkID%3d120193">Home page for Microsoft SQL Server</a> </li>
<li><a href="http://www.microsoft.com/downloads/info.aspx?na=40&amp;p=2&amp;SrcDisplayLang=en&amp;SrcCategoryId=&amp;SrcFamilyId=01af61e6-2f63-4291-bcad-fd500f6027ff&amp;u=http%3a%2f%2fgo.microsoft.com%2ffwlink%2f%3fLinkId%3d87843">Samples and Sample Databases</a> </li>
<li><a href="http://www.microsoft.com/downloads/info.aspx?na=40&amp;p=3&amp;SrcDisplayLang=en&amp;SrcCategoryId=&amp;SrcFamilyId=01af61e6-2f63-4291-bcad-fd500f6027ff&amp;u=http%3a%2f%2fgo.microsoft.com%2ffwlink%2f%3fLinkID%3d12318">SQL Server Developer Center</a> </li>
<li><a href="http://go.microsoft.com/fwlink/?LinkId=56089">SQL Server 2008 forums on MSDN</a> </li>
<li><a href="http://technet.microsoft.com/en-us/sqlserver/bb671410.aspx">SQL Server TechCenter</a></li>
</ul>
<p>&#160;</p>
<ul>
<li><a href="http://www.codeplex.com/MSFTDBProdSamples">SQL Server 2008 Product Samples </a></li>
<li><a href="http://www.microsoft.com/sqlserver/2008/en/us/default.aspx">SQL Server 2008 Product Site</a></li>
<li><a href="http://www.deitel.com/ResourceCenters/Microsoft/SQLServer2008/tabid/2906/Default.aspx">SQL Server 2008 Resources</a></li>
<li><a href="http://connect.microsoft.com/sqlserver">SQL Server on Microsoft Connect</a></li>
<li><a href="http://www.microsoft.com/sqlserver/2008/en/us/white-papers.aspx">SQL Server 2008 Whitepapers</a></li>
</ul>
<p>&#160;</p>
<ul>
<li><a href="http://www.microsoft.com/downloads/info.aspx?na=45&amp;p=1&amp;SrcDisplayLang=en&amp;SrcCategoryId=&amp;SrcFamilyId=01af61e6-2f63-4291-bcad-fd500f6027ff&amp;u=details.aspx%3ffamilyid%3d765433F7-0983-4D7A-B628-0A98145BCB97%26displaylang%3den">Microsoft SQL Server 2008 Books Online (January 2009)</a> </li>
<li><a href="http://www.microsoft.com/downloads/info.aspx?na=45&amp;p=2&amp;SrcDisplayLang=en&amp;SrcCategoryId=&amp;SrcFamilyId=01af61e6-2f63-4291-bcad-fd500f6027ff&amp;u=details.aspx%3ffamilyid%3dB33D2C78-1059-4CE2-B80D-2343C099BCB4%26displaylang%3den"><strong>Microsoft SQL Server 2008 Feature Pack, April 2009</strong></a> </li>
<li><a href="http://www.microsoft.com/downloads/info.aspx?na=45&amp;p=3&amp;SrcDisplayLang=en&amp;SrcCategoryId=&amp;SrcFamilyId=01af61e6-2f63-4291-bcad-fd500f6027ff&amp;u=details.aspx%3ffamilyid%3d66AB3DBB-BF3E-4F46-9559-CCC6A4F9DC19%26displaylang%3den">SQL Server 2008 Service Pack 1</a> </li>
<li><a href="http://www.microsoft.com/downloads/info.aspx?na=45&amp;p=2&amp;SrcDisplayLang=en&amp;SrcCategoryId=&amp;SrcFamilyId=01af61e6-2f63-4291-bcad-fd500f6027ff&amp;u=details.aspx%3ffamilyid%3dB33D2C78-1059-4CE2-B80D-2343C099BCB4%26displaylang%3den">Microsoft SQL Server 2008 Feature Pack, April 2009</a></li>
</ul>
<p>&#160;</p>
<ul>
<li><a href="http://go.microsoft.com/fwlink/?linkid=32168">Microsoft .NET Framework Version 2.0 Redistributable Package (x86)</a></li>
<li><a href="http://go.microsoft.com/fwlink/?LinkID=55734">Microsoft .NET Framework Version 2.0 Redistributable Package (x64</a>)</li>
<li><a href="http://go.microsoft.com/fwlink/?LinkId=70187">Microsoft .NET Framework Version 2.0 Redistributable Package (ia64)</a></li>
</ul>
<p>&#160;</p>
<ul>
<li><a href="http://www.microsoft.com/downloads/details.aspx?FamilyID=802d0632-5de7-4efd-ae43-ebe3fc078886">Microsoft SQL Server 2008 Upgrade Advisor, April 2009</a></li>
<li><a href="http://www.microsoft.com/downloads/details.aspx?FamilyID=dbddc9b6-6e19-4d4b-9309-13f62901b0d5">Microsoft SQL Server 2008 Reporting Services Report Builder 2.0, April 2009</a></li>
<li><a href="http://www.microsoft.com/downloads/details.aspx?FamilyID=58edd0e4-255b-4361-bd1e-e530d5aab78f">Microsoft SQL Server 2008 Reporting Services Add-in for Microsoft SharePoint Technologies, April 2009</a></li>
<li><a href="http://www.microsoft.com/downloads/details.aspx?FamilyID=af070f2c-46f4-47b6-b7bf-48979b999aeb">Microsoft SQL Server 2008 Data Mining Add-ins for Microsoft Office 2007, April 2009</a></li>
<li><a href="http://go.microsoft.com/fwlink/?LinkId=123373">Windows Installer 4.5</a></li>
</ul>
<p>&#160;</p>
<ul>
<li><a href="http://www.microsoft.com/express/">Visual Studio 2008 and SQL Server 2008 Express Editions Homepage</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.bahramov.com/2009/04/08/sql-server-2008-service-pack-1-released/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Creating a compressed SQL Server Database backup</title>
		<link>http://www.bahramov.com/2009/03/19/creating-a-compressed-sql-server-database-backup/#utm_source=feed&amp;utm_medium=feed&amp;utm_campaign=feed</link>
		<comments>http://www.bahramov.com/2009/03/19/creating-a-compressed-sql-server-database-backup/#comments</comments>
		<pubDate>Thu, 19 Mar 2009 18:23:25 +0000</pubDate>
		<dc:creator>Zaur Bahramov</dc:creator>
				<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[batch]]></category>
		<category><![CDATA[scheduled tasks]]></category>

		<guid isPermaLink="false">http://www.bahramov.com/?p=72</guid>
		<description><![CDATA[In this post I will describe how to create a compressed backup of any SQL Server database in Windows. This is especially useful if you have Express or MSDE edition of SQL Server where there&#8217;s no SQL Agent. Let’s look a this example:

First we will create a folder, where we want to keep or database [...]]]></description>
			<content:encoded><![CDATA[<p>In this post I will describe how to create a compressed backup of any SQL Server database in Windows. This is especially useful if you have Express or MSDE edition of SQL Server where there&#8217;s no SQL Agent. Let’s look a this example:</p>
<ol>
<li>First we will create a folder, where we want to keep or database backups. Let&#8217;s call it C:\DbBackup.</li>
<li>Now, we’ll create a sql script that will backup our database. I will use Northwind database in this example. The created backup file will have the name Northwind_[current date]. bak Open a Notepad and paste the following T-SQL code:</li>
<pre class="brush: sql">-- Create backup of NorthWind Database
-- add current date to the file name and
-- save it inside C:\DbBackup folder
--
DECLARE @str NVARCHAR(255)
SET @str=N&#039;C:\DbBackup\Northwind_&#039;+CONVERT(VARCHAR, GETDATE(), 105)+&#039;.bak&#039;
BACKUP DATABASE Northwind TO DISK=@str</pre>
<li>Save file as NorthwindBackup.sql</li>
</ol>
<p><span id="more-72"></span><br />
Another thing that we want to do is to compress the backup file so that it takes less space on our hard drive. There’re many software out there both commercial, like <a href="http://www.rarlabs.com" target="_blank">WinRAR</a>, <a href="http://www.winzip.com">WinZIP </a>and free – <a href="http://www.7-zip.org/">7-Zip</a>. Also, you can use the COMPRESS.EXE utility from Windows NT/2000/ZP/2003 Resource Kit available for download from Microsoft site, to create a compressed archive. In this post I will show how to create archive with Compress.exe and Rar.exe utilities.</p>
<p>Create a new text file and write the following code [if using Compress.exe]:</p>
<pre class="brush: php">sqlcmd -E -i NorthwindBackup.sql -o Result.txt
compress.exe -Z -R NorthWind_*.bak NorthWind_*.zip
ren *.ba_ *.zip del *.bak *.zi_</pre>
<p>Save the file as NorthWindBackup.bat in C:\DbBackup.</p>
<p>OR</p>
<p>Create a new text file and write the following code [if using rar.exe]:</p>
<pre class="brush: php">sqlcmd -E -i NorthwindBackup.sql -o Result.txt
rar.exe a -df -inul -ag[dd_mm_yyyy] C:\DbBackup\NorthWind.rar C:\DbBackup\*.bak</pre>
<p>Save the file as NorthWindBackup.bat in C:\DbBackup.</p>
<p>When you run the NorthWindBackup.bat file it will first pass the NorthWindBackup.sql script to ‘<a href="http://technet.microsoft.com/library/ms162773.aspx">sqlcmd.exe</a>’. <a href="http://technet.microsoft.com/library/ms162773.aspx">sqlcmd.exe</a>- is a command line utility of Microsoft SQL Server 2005/2008 and is available in all versions. If you are using a Microsoft SQL Server 2000 then you will have to use <a href="http://technet.microsoft.com/library/ms162806.aspx">osql.exe</a> instead of sqlcmd.exe. The usage syntax of these utilities is very similar and you can read more about their usage in BOL (<a href="http://technet.microsoft.com/library/ms162773.aspx" target="_blank">sqlcmd syntax</a> and <a href="http://technet.microsoft.com/library/ms162806.aspx" target="_blank">osql syntax</a>). In my example utility starts with the default SQL Server parameters and the result is written to Result.txt. After that the backup file is compressed and the uncompressed backup file is deleted.</p>
<p>Further, you will need to create a Scheduled Task that will execute the NorthWindBackup.bat at certain time. For this reason you may use the <a href="http://support.microsoft.com/kb/308569" target="_blank">Windows Scheduled Task</a> from visual interface or create a task directly from the command line interface of  <a href="http://technet.microsoft.com/en-us/library/cc772785.aspx" target="_blank">Schtasks.exe</a> utility.</p>
<p>Here&#8217;s a command that will create a Scheduled Task to be run every day at 8:00 PM from Local System account:</p>
<pre class="brush: plain">schtasks /create /tn &quot;NorthWindBackup&quot; /tr c:\DbBackup\NorthWindBackupR.bat /sc daily /st 20:00:00 /ed 12/12/2010 /ru &quot;NT AUTHORITY\SYSTEM&quot;</pre>
<p>Sample files can be downloaded here: <a href="http://bahramov.com/wp-content/uploads/2009/03/DbBackup.zip"><img src="http://www.bahramov.com/images/icons/winzip7064.png" alt="Zip" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.bahramov.com/2009/03/19/creating-a-compressed-sql-server-database-backup/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>SQL Web Assistant: Could not open the output file.</title>
		<link>http://www.bahramov.com/2009/03/19/sql-web-assistant-could-not-open-the-output-file/#utm_source=feed&amp;utm_medium=feed&amp;utm_campaign=feed</link>
		<comments>http://www.bahramov.com/2009/03/19/sql-web-assistant-could-not-open-the-output-file/#comments</comments>
		<pubDate>Thu, 19 Mar 2009 15:03:53 +0000</pubDate>
		<dc:creator>Zaur Bahramov</dc:creator>
				<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[sp_makewebtask]]></category>
		<category><![CDATA[SQL]]></category>

		<guid isPermaLink="false">http://www.bahramov.com/?p=66</guid>
		<description><![CDATA[Error Message:
Msg 16821, Level 11, State 1, Procedure sp_makewebtask, Line 131
SQL Web Assistant: Could not open the output file.
____________________________
Script completed with errors

Description:
This error message appears when you try to call the procedure sp_makewebtask but the output file cannot be opened.
Consequences:
The T-SQL statement can be parsed, but causes the error at runtime.
Resolution:
Errors of the Severity Level [...]]]></description>
			<content:encoded><![CDATA[<p><strong>Error Message:</strong><br />
<code><span style="color: #ff0000">Msg 16821, Level 11, State 1, Procedure sp_makewebtask, Line 131<br />
SQL Web Assistant: Could not open the output file.<br />
____________________________<br />
Script completed with errors</span><br />
</code></p>
<p><strong>Description:</strong><br />
This error message appears when you try to call the procedure sp_makewebtask but the output file cannot be opened.</p>
<p><strong>Consequences:</strong><br />
The T-SQL statement can be parsed, but causes the error at runtime.</p>
<p><strong>Resolution:</strong><br />
Errors of the Severity Level 11 are generated by the user and are corrigible by the user. The statement cannot be executed this way. You must specify a valid and accessible path. <span style="text-decoration: underline;">Also you have to make sure that the Service Logon account for SQL Server has appropriate rights to write to the specified location.<br />
</span></p>
<p><strong>Versions:</strong><br />
All versions of SQL Server.</p>
<p><strong>Example(s):</strong></p>
<pre class="brush: sql">
-- In this example we try to call the sp_makewebtask procedure
-- to output the result to a file on drive A:\. As our machine
-- does not have such a drive, the error is raised.

EXEC sp_makewebtask &#039;A:\test.html&#039;,&#039;SELECT * FROM Northwind.dbo.Orders&#039; </pre>
<p><strong>Remarks:</strong></p>
<p>How to change the SQL Server or SQL Server Agent service account without using SQL Enterprise Manager in SQL Server 2000 or SQL Server Configuration Manager in SQL Server 2005:  <a href="http://support.microsoft.com/kb/283811" target="_blank">http://support.microsoft.com/kb/283811</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.bahramov.com/2009/03/19/sql-web-assistant-could-not-open-the-output-file/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
