<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/rss2full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><rss 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/" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" version="2.0"><channel><title>Ashish's Blog On SQL Server</title><link>http://beyondrelational.com/blogs/ashish/default.aspx</link><description>This Blog is About SQL Server Technolgy</description><dc:language>en</dc:language><generator>CommunityServer 2008.5 SP1 (Build: 31106.3070)</generator><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/rss+xml" href="http://feeds.feedburner.com/AshishsBlog" /><feedburner:info uri="ashishsblog" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><item><title>SSIS File Operations – Copy File, Move File, Rename File and Delete File</title><link>http://feedproxy.google.com/~r/AshishsBlog/~3/2to7eCkX54U/ssis-file-operations-copy-file-move-file-rename-file-and-delete-file.aspx</link><pubDate>Tue, 31 Aug 2010 07:00:00 GMT</pubDate><guid isPermaLink="false">6e5011fa-7db5-4df3-bb79-9085c1d333b3:7499</guid><dc:creator>Ashish Gilhotra</dc:creator><slash:comments>0</slash:comments><wfw:commentRss>http://beyondrelational.com/blogs/ashish/rsscomments.aspx?PostID=7499</wfw:commentRss><comments>http://beyondrelational.com/blogs/ashish/archive/2010/08/31/ssis-file-operations-copy-file-move-file-rename-file-and-delete-file.aspx#comments</comments><description>&lt;p&gt;In the &lt;a href="http://beyondrelational.com/blogs/ashish/archive/2010/04/25/loading-data-from-text-files-to-sql-server-tables-csv-files-tab-separated-files-or-fixed-column-length-files.aspx"&gt;previous post&lt;/a&gt; we saw that how to &lt;a href="http://beyondrelational.com/blogs/ashish/archive/2010/04/01/getting-started-with-ssis-executing-a-sql-server-query-or-stored-procedure-from-ssis.aspx"&gt;Load data from Text files to SQL Server Tables&lt;/a&gt; and successfully created a package which loads data in to SQL Server table from a flat file. In this post today we will see SSIS File Operations – Copy File, Move File, Rename File and Delete File. Several times we need to do some &lt;em&gt;file operations&lt;/em&gt; like &lt;em&gt;copy, move, delete or rename&lt;/em&gt; file while performing the integration tasks. In SSIS we can accomplish these by &lt;em&gt;File System Task&lt;/em&gt; control. The &lt;em&gt;File System Task &lt;/em&gt;control is used for performing operations on files and directories such as move, create, delete, rename file and directories. We will see each and every operation separately.&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;Create SSIS Project&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;First we need to create an &lt;em&gt;SSIS Project&lt;/em&gt; before starting with &lt;em&gt;SSIS File Operations, y&lt;/em&gt;ou can create a SSIS Project by looking in to this &lt;a href="http://bit.ly/9wdPZT"&gt;previous SSIS post&lt;/a&gt;. Let’s say we created an SSIS project as &lt;em&gt;FileOperations.&lt;/em&gt;&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;&lt;font color="#800000" size="3"&gt;Copy File:&lt;/font&gt;&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;We can copy file from one place to another with the help of SSIS. We will look into the whole process of copy file from one place to another in this section, for this you need a New Package in your project which you can create easily by looking into &lt;a href="http://bit.ly/9wdPZT"&gt;my pervious SSIS post&lt;/a&gt;. Now we have a SSIS project named &lt;em&gt;FIleOperations, &lt;/em&gt;it is the time to create a package in our SSIS project. Add a new package and name it as &lt;em&gt;CopyFile.&lt;/em&gt;&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;&lt;em&gt;Adding File System Task in Your Package&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;Now we have a package and it is time to add &lt;em&gt;File System Task &lt;/em&gt;to your package, to add File System Task control to the package go to &lt;em&gt;control flow times in toolbox and double click on File System Tasks &lt;/em&gt;or &lt;em&gt;drag and drop &lt;/em&gt;it in your package(See the image below)&lt;em&gt;.&lt;/em&gt;&lt;/p&gt;  &lt;p&gt;&lt;a href="http://beyondrelational.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/ashish/copy1_5F00_3FF36CC6.png"&gt;&lt;img style="border-right-width:0px;display:inline;border-top-width:0px;border-bottom-width:0px;border-left-width:0px;" title="copy1" border="0" alt="copy1" src="http://beyondrelational.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/ashish/copy1_5F00_thumb_5F00_6A622E94.png" width="458" height="351" /&gt;&lt;/a&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;&lt;em&gt;Configuring File System Task&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;Now we have &lt;em&gt;File System Task control &lt;/em&gt;added to your package and we can configure it. To configure right click on the control and choose edit(See the image below).&lt;/p&gt;  &lt;p&gt;&lt;a href="http://beyondrelational.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/ashish/copy2_5F00_225E3F6F.png"&gt;&lt;img style="border-right-width:0px;display:inline;border-top-width:0px;border-bottom-width:0px;border-left-width:0px;" title="copy2" border="0" alt="copy2" src="http://beyondrelational.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/ashish/copy2_5F00_thumb_5F00_5318F92D.png" width="458" height="230" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;After that you will be navigated to a new window named &lt;em&gt;File System Task Editor &lt;/em&gt;in which you have to configure the &lt;em&gt;File System Task(See the image below).&lt;/em&gt;&lt;/p&gt;  &lt;p&gt;&lt;a href="http://beyondrelational.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/ashish/copy3_5F00_02FB4D02.png"&gt;&lt;img style="border-right-width:0px;display:inline;border-top-width:0px;border-bottom-width:0px;border-left-width:0px;" title="copy3" border="0" alt="copy3" src="http://beyondrelational.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/ashish/copy3_5F00_thumb_5F00_365C31C0.png" width="458" height="437" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;The options on File system task editor are as below.&lt;/p&gt;  &lt;ol&gt;   &lt;li&gt;IsDestinationPathVariable : Destination path is stored as variable or not. &lt;/li&gt;    &lt;li&gt;DestinationConnection : File Connection or vairable. &lt;/li&gt;    &lt;li&gt;OverwriteDestination : Overwrite if file exists with same name. True/False &lt;/li&gt;    &lt;li&gt;Name : name you want to give. &lt;/li&gt;    &lt;li&gt;Description : Little description &lt;/li&gt;    &lt;li&gt;Operation : Choose copy file. &lt;/li&gt;    &lt;li&gt;IsSourcePathVariable : Source path is stored as variable or not. &lt;/li&gt;    &lt;li&gt;SourceConnection : File Connetion or variable. &lt;/li&gt; &lt;/ol&gt;  &lt;p&gt;Here we have to choose operation as &lt;em&gt;Copy File &lt;/em&gt;choose &lt;em&gt;OverwriteDestination as True and IsDestinationPathVariable and IsSourcePathVariable as False. &lt;/em&gt;Now we have to configure Source and destination connections.&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;Configuring Source and Destination Connections&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;Now we have to configure source and destination connections.&lt;/p&gt;  &lt;p&gt;&lt;em&gt;Source Connection : &lt;/em&gt;In &lt;em&gt;File System Task Editor &lt;/em&gt;navigate to &lt;em&gt;SourceConnection&lt;/em&gt; Tab and choose &lt;em&gt;New Connection(Se&lt;em&gt;e&lt;/em&gt; the image below).&lt;/em&gt;&lt;/p&gt;  &lt;p&gt;&lt;em&gt;&lt;a href="http://beyondrelational.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/ashish/copy4_5F00_274A7448.png"&gt;&lt;img style="border-right-width:0px;display:inline;border-top-width:0px;border-bottom-width:0px;border-left-width:0px;" title="copy4" border="0" alt="copy4" src="http://beyondrelational.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/ashish/copy4_5F00_thumb_5F00_3DA0198D.png" width="458" height="96" /&gt;&lt;/a&gt;&amp;#160;&lt;/em&gt;&lt;/p&gt;  &lt;p&gt;Now you will be navigated to new window named &lt;em&gt;File Connection Manager Editor &lt;/em&gt;where you have to configure your source connection. Choose &lt;em&gt;Existing FIle &lt;/em&gt;as &lt;em&gt;Usage Type &lt;/em&gt;and provide fully qualified path for file which you want to copy to other location(See the image below).&lt;/p&gt;  &lt;p&gt;&lt;a href="http://beyondrelational.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/ashish/copy5_5F00_0347345D.png"&gt;&lt;img style="border-right-width:0px;display:inline;border-top-width:0px;border-bottom-width:0px;border-left-width:0px;" title="copy5" border="0" alt="copy5" src="http://beyondrelational.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/ashish/copy5_5F00_thumb_5F00_750B4C1D.png" width="458" height="206" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;&lt;em&gt;Destination Connection :&lt;/em&gt; Once you done with your &lt;em&gt;SourceConnection&lt;/em&gt; you have to configure Destination Connection. Go to &lt;em&gt;DestinationConnection &lt;/em&gt;tab and choose &lt;em&gt;New Connection(See the image below).&lt;/em&gt;&lt;/p&gt;  &lt;p&gt;&lt;a href="http://beyondrelational.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/ashish/copy6_5F00_5D09FC66.png"&gt;&lt;img style="border-right-width:0px;display:inline;border-top-width:0px;border-bottom-width:0px;border-left-width:0px;" title="copy6" border="0" alt="copy6" src="http://beyondrelational.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/ashish/copy6_5F00_thumb_5F00_214CF464.png" width="458" height="112" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;Now you will be navigated to new window named &lt;em&gt;File Connection Manager Editor &lt;/em&gt;where you have to configure your destination connection(See the image below).&lt;/p&gt;  &lt;p&gt;&lt;a href="http://beyondrelational.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/ashish/copy7_5F00_09B7D7A2.png"&gt;&lt;img style="border-right-width:0px;display:inline;border-top-width:0px;border-bottom-width:0px;border-left-width:0px;" title="copy7" border="0" alt="copy7" src="http://beyondrelational.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/ashish/copy7_5F00_thumb_5F00_5B60E2A5.png" width="458" height="206" /&gt;&lt;/a&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;Here we also have to provide &lt;em&gt;Usage Type &amp;amp; Folder &lt;/em&gt;as in Usage Type we choose &lt;em&gt;Existing Folder &lt;/em&gt;so we have to provide the destination folder where we want to have a copy of file.&lt;/p&gt;  &lt;p&gt;Now you done with both Source and Destination connection and your final &lt;em&gt;File System Task Editor &lt;/em&gt;looks like this(See the image below).&lt;/p&gt;  &lt;p&gt;&lt;a href="http://beyondrelational.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/ashish/copy8_5F00_6A2DA92E.png"&gt;&lt;img style="border-right-width:0px;display:inline;border-top-width:0px;border-bottom-width:0px;border-left-width:0px;" title="copy8" border="0" alt="copy8" src="http://beyondrelational.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/ashish/copy8_5F00_thumb_5F00_22050EB4.png" width="458" height="437" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;Click &lt;em&gt;OK&lt;/em&gt;&amp;#160; and you are done with your &lt;em&gt;Copy File Task. &lt;/em&gt;Save it and execute package as we did in &lt;a href="http://beyondrelational.com/blogs/ashish/archive/2010/04/01/getting-started-with-ssis-executing-a-sql-server-query-or-stored-procedure-from-ssis.aspx" target="_blank"&gt;previous post&lt;/a&gt; and this will copy specific file from one place to another.&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;&lt;font color="#800000" size="3"&gt;Rename File: &lt;/font&gt;&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;You done with Copy File, we will see the &lt;em&gt;Rename File&lt;/em&gt; operation next. This operation will rename any file to the another name you want, for this we need to create a package named &lt;em&gt;Rename. &lt;/em&gt;Once you have package added to your project open it and drag and drop &lt;em&gt;File System Task &lt;/em&gt;control to your package as we did earlier in this post. Now we will configure that file system task to rename files. For this you have to right click on the package and choose &lt;em&gt;Edit &lt;/em&gt;as we did earlier in this post. This will open up &lt;em&gt;File System Task Editor, &lt;/em&gt;we have to configure that editor to rename files(See the image below).&lt;/p&gt;  &lt;p&gt;We will choose Operation as &lt;em&gt;Rename File(See the image below).&lt;/em&gt;&lt;/p&gt;  &lt;p&gt;&lt;a href="http://beyondrelational.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/ashish/Rename1_5F00_3F3268D1.png"&gt;&lt;img style="border-right-width:0px;display:inline;border-top-width:0px;border-bottom-width:0px;border-left-width:0px;" title="Rename1" border="0" alt="Rename1" src="http://beyondrelational.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/ashish/Rename1_5F00_thumb_5F00_37A98A15.png" width="458" height="365" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;Now we have to configure &lt;em&gt;Source and Destination Connection &lt;/em&gt;for &lt;em&gt;Rename File System Task.&lt;/em&gt;&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;Configure Source and Destination Connection :&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;&lt;em&gt;Source Connection : &lt;/em&gt;In &lt;em&gt;File System Task Editor &lt;/em&gt;navigate to &lt;em&gt;SourceConnection&lt;/em&gt; Tab and choose &lt;em&gt;New Connection(See the image below).&lt;/em&gt;&lt;/p&gt;  &lt;p&gt;&lt;a href="http://beyondrelational.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/ashish/copy4_5F00_34C2C198.png"&gt;&lt;img style="border-right-width:0px;display:inline;border-top-width:0px;border-bottom-width:0px;border-left-width:0px;" title="copy4" border="0" alt="copy4" src="http://beyondrelational.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/ashish/copy4_5F00_thumb_5F00_58EAACD8.png" width="458" height="97" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;Now you will be navigated to a new window named &lt;em&gt;File Connection Manager Editor&lt;/em&gt; and here you have to configure your &lt;em&gt;SourceConnection &lt;/em&gt;choose &lt;em&gt;Existing File &lt;/em&gt;as &lt;em&gt;Usage Type&lt;/em&gt; and provide &lt;em&gt;Fully Qualified Path&lt;/em&gt; in &lt;em&gt;File&lt;/em&gt;(See the image below).&lt;/p&gt;  &lt;p&gt;&lt;a href="http://beyondrelational.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/ashish/Rename2_5F00_11938E25.png"&gt;&lt;img style="border-right-width:0px;display:inline;border-top-width:0px;border-bottom-width:0px;border-left-width:0px;" title="Rename2" border="0" alt="Rename2" src="http://beyondrelational.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/ashish/Rename2_5F00_thumb_5F00_0357A5E6.png" width="458" height="206" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;click &lt;em&gt;Ok&lt;/em&gt; and your are done with your &lt;em&gt;SourceConnection&lt;/em&gt;.&lt;/p&gt;  &lt;p&gt;&lt;em&gt;Destination Connection : &lt;/em&gt;Once you are done with your &lt;em&gt;SourceConnection&lt;/em&gt; you have to configure Destination Connection where you want your renamed file, for this navigate to &lt;em&gt;DestinationConnection &lt;/em&gt;Tab and choose &lt;em&gt;New Connection(See the image below).&lt;/em&gt;&lt;/p&gt;  &lt;p&gt;&lt;a href="http://beyondrelational.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/ashish/copy6_5F00_73B96395.png"&gt;&lt;img style="border-right-width:0px;display:inline;border-top-width:0px;border-bottom-width:0px;border-left-width:0px;" title="copy6" border="0" alt="copy6" src="http://beyondrelational.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/ashish/copy6_5F00_thumb_5F00_230AD920.png" width="458" height="112" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;Now you will be navigated to new window named &lt;em&gt;File Connection Manager Editor&lt;/em&gt; and here you have to configure your &lt;em&gt;DestinationConnection &lt;/em&gt;choose &lt;em&gt;Create File &lt;/em&gt;as &lt;em&gt;Usage Type &lt;/em&gt;and provide &lt;em&gt;Fully Qualified Path&lt;/em&gt; in &lt;em&gt;File(See the image below).&lt;/em&gt;&lt;/p&gt;  &lt;p&gt;&lt;a href="http://beyondrelational.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/ashish/Rename3_5F00_2E5745FE.png"&gt;&lt;img style="border-right-width:0px;display:inline;border-top-width:0px;border-bottom-width:0px;border-left-width:0px;" title="Rename3" border="0" alt="Rename3" src="http://beyondrelational.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/ashish/Rename3_5F00_thumb_5F00_7BF6032F.png" width="458" height="206" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;Click &lt;em&gt;Ok &lt;/em&gt;and you are done with your &lt;em&gt;DestinationConnection.&lt;/em&gt;&lt;/p&gt;  &lt;p&gt;Now you will be navigated back to &lt;em&gt;File System Task Editor &lt;/em&gt;here click ok and you are done with your &lt;em&gt;Rename File Task. &lt;/em&gt;You can run this package as shown in &lt;a href="http://beyondrelational.com/blogs/ashish/archive/2010/04/01/getting-started-with-ssis-executing-a-sql-server-query-or-stored-procedure-from-ssis.aspx" target="_blank"&gt;previous post&lt;/a&gt; and you will get new file with name &lt;em&gt;Renamed.txt &lt;/em&gt;at your destination path.&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;&lt;font color="#800000" size="3"&gt;Move File :&lt;/font&gt;&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;In this Move File Task we will see how to move files from one location to another location. For this we have to add a package name &lt;em&gt;Move &lt;/em&gt;in our project and add &lt;em&gt;File System Task Control &lt;/em&gt;to your package by Drag &amp;amp; Drop from &lt;em&gt;ToolBox. &lt;/em&gt;Once you have File System Task added to your project you have to configure this to move file by &lt;em&gt;right click and choose edit on File System Task &lt;/em&gt;as we did earlier in this post(See the image below).&lt;/p&gt;  &lt;p&gt;&lt;a href="http://beyondrelational.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/ashish/move1_5F00_081A0E08.png"&gt;&lt;img style="border-right-width:0px;display:inline;border-top-width:0px;border-bottom-width:0px;border-left-width:0px;" title="move1" border="0" alt="move1" src="http://beyondrelational.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/ashish/move1_5F00_thumb_5F00_477A5249.png" width="458" height="365" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;Now after this we need to configure &lt;em&gt;Source and Destination Connection &lt;/em&gt;as we did earlier in this post.&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;Configure Source and Destination Connection :&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;&lt;em&gt;Source Connection : &lt;/em&gt;In &lt;em&gt;File System Task Editor &lt;/em&gt;navigate to &lt;em&gt;SourceConnection&lt;/em&gt; Tab and choose &lt;em&gt;New Connection(See the image below).&lt;/em&gt;&lt;/p&gt;  &lt;p&gt;&lt;a href="http://beyondrelational.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/ashish/copy4_5F00_39630F16.png"&gt;&lt;img style="border-right-width:0px;display:inline;border-top-width:0px;border-bottom-width:0px;border-left-width:0px;" title="copy4" border="0" alt="copy4" src="http://beyondrelational.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/ashish/copy4_5F00_thumb_5F00_3AC731E8.png" width="458" height="97" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;Now you will be navigated to a new window named &lt;em&gt;File Connection Manager Editor&lt;/em&gt; and here you have to configure your &lt;em&gt;SourceConnection &lt;/em&gt;choose &lt;em&gt;Existing File &lt;/em&gt;as &lt;em&gt;Usage Type&lt;/em&gt; and provide &lt;em&gt;Fully Qualified Path&lt;/em&gt; in &lt;em&gt;File&lt;/em&gt;(See the image below).&lt;/p&gt;  &lt;p&gt;&lt;a href="http://beyondrelational.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/ashish/move2_5F00_492CED27.png"&gt;&lt;img style="border-right-width:0px;display:inline;border-top-width:0px;border-bottom-width:0px;border-left-width:0px;" title="move2" border="0" alt="move2" src="http://beyondrelational.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/ashish/move2_5F00_thumb_5F00_01DA27E6.png" width="458" height="206" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;click &lt;em&gt;Ok&lt;/em&gt; and your are done with your &lt;em&gt;SourceConnection&lt;/em&gt;.&lt;/p&gt;  &lt;p&gt;&lt;em&gt;Destination Connection : &lt;/em&gt;Once you are done with your &lt;em&gt;SourceConnection&lt;/em&gt; you have to configure &lt;em&gt;Destination Connection &lt;/em&gt;where you want to move file, for this navigate to &lt;em&gt;DestinationConnection &lt;/em&gt;Tab and choose &lt;em&gt;New Connection(See the image below).&lt;/em&gt;&lt;/p&gt;  &lt;p&gt;&lt;a href="http://beyondrelational.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/ashish/copy6_5F00_03833B5E.png"&gt;&lt;img style="border-right-width:0px;display:inline;border-top-width:0px;border-bottom-width:0px;border-left-width:0px;" title="copy6" border="0" alt="copy6" src="http://beyondrelational.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/ashish/copy6_5F00_thumb_5F00_04E75E30.png" width="458" height="112" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;Now you will be navigated to new window named &lt;em&gt;File Connection Manager Editor&lt;/em&gt; and here you have to configure your &lt;em&gt;DestinationConnection &lt;/em&gt;choose &lt;em&gt;Existing Folder &lt;/em&gt;as &lt;em&gt;Usage Type &lt;/em&gt;and provide &lt;em&gt;Folder Path&lt;/em&gt; in &lt;em&gt;File(See the image below).&lt;/em&gt;&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;&lt;em&gt;&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;&lt;/p&gt;  &lt;p&gt;&lt;/p&gt;  &lt;p&gt;&lt;/p&gt;  &lt;p&gt;&lt;/p&gt;  &lt;p&gt;&lt;/p&gt;  &lt;p&gt;&lt;/p&gt;  &lt;p&gt;&lt;/p&gt;  &lt;p&gt;&lt;/p&gt;  &lt;p&gt;&lt;/p&gt;  &lt;p&gt;&lt;a href="http://beyondrelational.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/ashish/move3_5F00_28634737.png"&gt;&lt;img style="border-right-width:0px;display:inline;border-top-width:0px;border-bottom-width:0px;border-left-width:0px;" title="move3" border="0" alt="move3" src="http://beyondrelational.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/ashish/move3_5F00_thumb_5F00_611081F5.png" width="458" height="206" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;Click &lt;em&gt;Ok &lt;/em&gt;and you are done with your &lt;em&gt;DestinationConnection.&lt;/em&gt;&lt;/p&gt;  &lt;p&gt;Now you will be navigated back to &lt;em&gt;File System Task Editor &lt;/em&gt;here click ok and you are done with your &lt;em&gt;Move File Task. &lt;/em&gt;You can run this package as shown in &lt;a href="http://beyondrelational.com/blogs/ashish/archive/2010/04/01/getting-started-with-ssis-executing-a-sql-server-query-or-stored-procedure-from-ssis.aspx" target="_blank"&gt;previous post&lt;/a&gt; and you will get a new file at &lt;em&gt;DestinationConnection and &lt;/em&gt;deleted &lt;em&gt;from SourceConnection&lt;/em&gt;.&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;&lt;font color="#800000" size="3"&gt;Delete File: &lt;/font&gt;&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;&lt;em&gt;Delete File Task&amp;#160; &lt;/em&gt;is used to delete specific file from the specific location. For this we need to create a new package by name &lt;em&gt;delete&lt;/em&gt;&amp;#160; in our sample project and add &lt;em&gt;File System Task &lt;/em&gt;control to your package by &lt;em&gt;Drag &amp;amp; Drop it from ToolBox&lt;/em&gt;. Once you have &lt;em&gt;File System Task &lt;/em&gt;added to your package &lt;em&gt;Right Click on File System Task and choose Edit&lt;/em&gt; to configure it to delete files from a specific location. Now we get &lt;em&gt;File System Task Editor&lt;/em&gt; window on our screen choose &lt;em&gt;Delete File&lt;/em&gt; as &lt;em&gt;operation &lt;/em&gt;in &lt;em&gt;File System Task Editor&lt;/em&gt; window(See the image below).&lt;/p&gt;  &lt;p&gt;&lt;a href="http://beyondrelational.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/ashish/Delete1_5F00_6FDD487E.png"&gt;&lt;img style="border-right-width:0px;display:inline;border-top-width:0px;border-bottom-width:0px;border-left-width:0px;" title="Delete1" border="0" alt="Delete1" src="http://beyondrelational.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/ashish/Delete1_5F00_thumb_5F00_7A9D3084.png" width="458" height="365" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;Now we have to configure &lt;em&gt;Source Connection &lt;/em&gt;for this from where we like to delete files.&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;Configure Source Connection :&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;Go to &lt;em&gt;SourceConnection &lt;/em&gt;tab in &lt;em&gt;File System Task Editor&lt;/em&gt; and choose &lt;em&gt;New Connection(See the image below).&lt;/em&gt;&lt;/p&gt;  &lt;p&gt;&lt;a href="http://beyondrelational.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/ashish/copy4_5F00_250E8304.png"&gt;&lt;img style="border-right-width:0px;display:inline;border-top-width:0px;border-bottom-width:0px;border-left-width:0px;" title="copy4" border="0" alt="copy4" src="http://beyondrelational.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/ashish/copy4_5F00_thumb_5F00_0D76D591.png" width="458" height="97" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;Now you will be navigated to a new window named &lt;em&gt;File Connection Manager Editor&lt;/em&gt; and here you have to configure your &lt;em&gt;SourceConnection &lt;/em&gt;choose &lt;em&gt;Existing File &lt;/em&gt;as &lt;em&gt;Usage Type&lt;/em&gt; and provide &lt;em&gt;Fully Qualified Path&lt;/em&gt; in &lt;em&gt;File&lt;/em&gt;(See the image below).&lt;/p&gt;  &lt;p&gt;&lt;a href="http://beyondrelational.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/ashish/Delete2_5F00_336F1698.png"&gt;&lt;img style="border-right-width:0px;display:inline;border-top-width:0px;border-bottom-width:0px;border-left-width:0px;" title="Delete2" border="0" alt="Delete2" src="http://beyondrelational.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/ashish/Delete2_5F00_thumb_5F00_53208111.png" width="458" height="206" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;Click &lt;em&gt;Ok &lt;/em&gt;and you are done with &lt;em&gt;SourceConnection &lt;/em&gt;and navigated back to &lt;em&gt;File System Task Editor, &lt;/em&gt;Click &lt;em&gt;Ok &lt;/em&gt;here and you are done with your &lt;em&gt;Delete File Task &lt;/em&gt;run this package as shown in &lt;a href="http://beyondrelational.com/blogs/ashish/archive/2010/04/01/getting-started-with-ssis-executing-a-sql-server-query-or-stored-procedure-from-ssis.aspx" target="_blank"&gt;previous post&lt;/a&gt; and the targeted file will be deleted from the path specified in &lt;em&gt;SourceConnection.&lt;/em&gt;&lt;/p&gt;  &lt;p&gt;In this post we looked in to different File Operations(Copy, Rename, Move and Delete File). If you are facing any problems or you have any question regarding these file operations let me know by posting a comment, I will try to resolve it at the soonest.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://beyondrelational.com/aggbug.aspx?PostID=7499" width="1" height="1"&gt;&lt;img src="http://feeds.feedburner.com/~r/AshishsBlog/~4/2to7eCkX54U" height="1" width="1"/&gt;</description><category domain="http://beyondrelational.com/blogs/ashish/archive/tags/SQL-Server/default.aspx">SQL-Server</category><category domain="http://beyondrelational.com/blogs/ashish/archive/tags/SSIS/default.aspx">SSIS</category><category domain="http://beyondrelational.com/blogs/ashish/archive/tags/BRH/default.aspx">BRH</category><category domain="http://beyondrelational.com/blogs/ashish/archive/tags/BI/default.aspx">BI</category><category domain="http://beyondrelational.com/blogs/ashish/archive/tags/_2300_BI/default.aspx">#BI</category><category domain="http://beyondrelational.com/blogs/ashish/archive/tags/_2300_SQLServer/default.aspx">#SQLServer</category><feedburner:origLink>http://beyondrelational.com/blogs/ashish/archive/2010/08/31/ssis-file-operations-copy-file-move-file-rename-file-and-delete-file.aspx</feedburner:origLink></item><item><title>Loading data from text files to SQL Server Tables – CSV Files, Tab Separated Files or Fixed Column Length Files</title><link>http://feedproxy.google.com/~r/AshishsBlog/~3/D9Qwv2JK9Qw/loading-data-from-text-files-to-sql-server-tables-csv-files-tab-separated-files-or-fixed-column-length-files.aspx</link><pubDate>Sun, 25 Apr 2010 15:59:00 GMT</pubDate><guid isPermaLink="false">6e5011fa-7db5-4df3-bb79-9085c1d333b3:4818</guid><dc:creator>Ashish Gilhotra</dc:creator><slash:comments>6</slash:comments><wfw:commentRss>http://beyondrelational.com/blogs/ashish/rsscomments.aspx?PostID=4818</wfw:commentRss><comments>http://beyondrelational.com/blogs/ashish/archive/2010/04/25/loading-data-from-text-files-to-sql-server-tables-csv-files-tab-separated-files-or-fixed-column-length-files.aspx#comments</comments><description>&lt;p&gt;In the &lt;a href="http://beyondrelational.com/blogs/ashish/archive/2010/04/01/getting-started-with-ssis-executing-a-sql-server-query-or-stored-procedure-from-ssis.aspx"&gt;previous post&lt;/a&gt; we looked in &lt;em&gt;How to Execute SQL Query or Store Procedure from SSIS&lt;/em&gt; and successfully created a package which execute SQL Query or Procedure on targeted SQL Server with the help of this. In this post we look in &lt;em&gt;How to Load Data from text Files to SQL Server, &lt;/em&gt;in daily life several time we need to load data in SQL Server tables, we can achieve this with the help of SSIS. We look into the detailed process of loading data from text files to SQL Server tables.&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;Load Data From Text File to SQL Server Tables&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;We can load data from text files in to SQL Server tables with the help of &lt;em&gt;Data Flow Task Control. &lt;/em&gt;We will see how to use Data Flow Task in detail. Before that you need to create a project or a new package in existing project, you can create a new project or add a new package to project as shown in the &lt;a href="http://beyondrelational.com/blogs/ashish/archive/2010/04/01/getting-started-with-ssis-executing-a-sql-server-query-or-stored-procedure-from-ssis.aspx"&gt;previous post&lt;/a&gt;.&lt;/p&gt;  &lt;p&gt;So you can add a new package in your SSIS project as shown in previous post, now you have a new package in your project name it as &lt;em&gt;loaddata.&lt;/em&gt;&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;Adding Data Flow Task Control to Package&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;Now you have a package so this is time to add &lt;em&gt;Data Flow Task &lt;/em&gt;to your package, to add Data Flow Task control to the package, double click on the item or just drag and drop item from from the toolbox to your package window.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://beyondrelational.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/ashish/1_5F00_4EA0E6FE.png"&gt;&lt;img title="1" style="border-top-width:0px;display:inline;border-left-width:0px;border-bottom-width:0px;border-right-width:0px;" height="342" alt="1" src="http://beyondrelational.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/ashish/1_5F00_thumb_5F00_725F2FFA.png" width="297" border="0" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;Now you have Data Flow Task control on your package window the item will show up on the package like this (see the below image)&lt;/p&gt;  &lt;p&gt;&lt;a href="http://beyondrelational.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/ashish/2_5F00_034CE7F0.png"&gt;&lt;img title="2" style="border-top-width:0px;display:inline;border-left-width:0px;border-bottom-width:0px;border-right-width:0px;" height="133" alt="2" src="http://beyondrelational.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/ashish/2_5F00_thumb_5F00_4723ACF8.png" width="454" border="0" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;&lt;strong&gt;Configuring Data Flow Task&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;&lt;/p&gt;  &lt;p&gt;Now we have &lt;i&gt;Data Flow Task &lt;/i&gt;added in your package, the next step is to configure Data Flow Task. To configure &lt;i&gt;Data Flow Task &lt;/i&gt;right click on the control and choose edit option to configure the control.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://beyondrelational.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/ashish/20_5F00_48F69370.png"&gt;&lt;img title="20" style="border-top-width:0px;display:inline;border-left-width:0px;border-bottom-width:0px;border-right-width:0px;" height="212" alt="20" src="http://beyondrelational.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/ashish/20_5F00_thumb_5F00_6A75C2FF.png" width="454" border="0" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;You will see a new window opened at your screen and you are navigated to &lt;em&gt;Data Flow &lt;/em&gt;tab within your current package (as shown in below image).&lt;/p&gt;  &lt;p&gt;&lt;a href="http://beyondrelational.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/ashish/3_5F00_12AA8CC3.png"&gt;&lt;img title="3" style="border-top-width:0px;display:inline;border-left-width:0px;border-bottom-width:0px;border-right-width:0px;" height="96" alt="3" src="http://beyondrelational.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/ashish/3_5F00_thumb_5F00_7708917D.png" width="454" border="0" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;Now we have a blank &lt;i&gt;Data Flow Task &lt;/i&gt;and we have to configure it to load data from a &lt;i&gt;text/csv&lt;/i&gt; file and insert it into an SQL Server table. For this we have to configure &lt;i&gt;Data Flow Task, &lt;/i&gt;and we need to setup a source connection for &lt;i&gt;Flat File &lt;/i&gt;and a destination connection for &lt;i&gt;OLE DB.&lt;/i&gt;&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;Setting up an Flat File Source&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;To configure a &lt;i&gt;Flat File Source, &lt;/i&gt;go to the toolbox and under the Data&lt;i&gt; Flow Sources&lt;/i&gt; list you can find &lt;i&gt;Flat File Source. &lt;/i&gt;To add the Flat file Source to the package, double click on the control or simply drag and drop it to the package.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://beyondrelational.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/ashish/14_5F00_63E9F582.png"&gt;&lt;img title="14" style="border-top-width:0px;display:inline;border-left-width:0px;border-bottom-width:0px;border-right-width:0px;" height="228" alt="14" src="http://beyondrelational.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/ashish/14_5F00_thumb_5F00_75C91A00.png" width="304" border="0" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;Now you have to configure Flat File Source, for configuring &lt;em&gt;Flat File Source &lt;/em&gt;right click on &lt;em&gt;Flat File Source control&lt;/em&gt; and choose edit and you will get a window name &lt;em&gt;Flat File Source Editor&lt;/em&gt;( image as shown below).&lt;/p&gt;  &lt;p&gt;&lt;a href="http://beyondrelational.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/ashish/5_5F00_56A88DD1.png"&gt;&lt;img title="5" style="border-top-width:0px;display:inline;border-left-width:0px;border-bottom-width:0px;border-right-width:0px;" height="478" alt="5" src="http://beyondrelational.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/ashish/5_5F00_thumb_5F00_25AB6DD5.png" width="454" border="0" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;Now you have to create a new flat file connection, for this click on the New button on the Flat File Source Editor (as shown in the image above) and you will see a new window named &lt;i&gt;Flat File Connection Manager Editor &lt;/i&gt;(as shown in image below).&lt;/p&gt;  &lt;p&gt;&lt;a href="http://beyondrelational.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/ashish/13_5F00_1B7C6419.png"&gt;&lt;img title="13" style="border-top-width:0px;display:inline;border-left-width:0px;border-bottom-width:0px;border-right-width:0px;" height="464" alt="13" src="http://beyondrelational.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/ashish/13_5F00_thumb_5F00_659C9060.png" width="454" border="0" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;You have to create a new connection with the help of this &lt;em&gt;Flat File Connection Manager Editor &lt;/em&gt;you have to fill following information in General tab to configure it correctly.&lt;/p&gt;  &lt;p&gt;Connection Manager Name : &lt;em&gt;Name of the connection.      &lt;br /&gt;&lt;/em&gt;Description : &lt;em&gt;Description(anything you want to write).      &lt;br /&gt;&lt;/em&gt;File Name : &lt;em&gt;Here gives the path of the file in file system.      &lt;br /&gt;&lt;/em&gt;Locale : &lt;em&gt;Default Value.      &lt;br /&gt;&lt;/em&gt;Code Page : &lt;em&gt;Default Value.      &lt;br /&gt;&lt;/em&gt;Format : &lt;em&gt;Choose Delimited(you have options Delimited, Fixed width, Ragged right choose appropriate, in our case delimited.)      &lt;br /&gt;&lt;/em&gt;Text Qualifier : &lt;em&gt;“(In our case)      &lt;br /&gt;&lt;/em&gt;Header row delimiter : &lt;em&gt;{CR}{LF} (default).      &lt;br /&gt;&lt;/em&gt;Header rows to skip : &lt;em&gt;0 (if you want to skip some rows you can put it there like 2 or 10 or whatever).      &lt;br /&gt;&lt;/em&gt;Column names in first row : &lt;em&gt;Leave it uncheck.&lt;/em&gt;&lt;/p&gt;  &lt;p&gt;&lt;/p&gt;  &lt;p&gt;&lt;/p&gt;  &lt;p&gt;&lt;/p&gt;  &lt;p&gt;&lt;/p&gt;  &lt;p&gt;&lt;/p&gt;  &lt;p&gt;Fill up the following connection and click on &lt;em&gt;Columns Tab &lt;/em&gt;you will see the columns of your file in this tab, you can also change many properties of your columns go to &lt;em&gt;Advance Tab &lt;/em&gt;and you will options like &lt;em&gt;Data Type, OuputColumnWidth etc. &lt;/em&gt;you can alter them as per need. Now click &lt;em&gt;OK &lt;/em&gt;and you will get &lt;em&gt;Flat File Source Editor&lt;/em&gt; window again just once check the &lt;em&gt;columns tab &lt;/em&gt;and click ok and you are done with configuring Flat File Source.&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;Setting up an OLE DB Destination&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;We have a &lt;i&gt;Flat File Source&lt;/i&gt; from which we can take data from a flat file, now we have to configure a &lt;i&gt;OLD DB Destination &lt;/i&gt;through which we will put our data into &lt;i&gt;SQL Table. &lt;/i&gt;For adding &lt;i&gt;OLE DB Destination&lt;/i&gt; in your &lt;i&gt;Data Flow Task, &lt;/i&gt;go to D&lt;i&gt;ata Flow Destinations&lt;/i&gt; block in the toolbox and locate &lt;i&gt;OLE DB Destination (as shown in image below) &lt;/i&gt;and double click on the control or drag and drop it to your Data Flow Task window.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://beyondrelational.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/ashish/15_5F00_08827373.png"&gt;&lt;img title="15" style="border-top-width:0px;display:inline;border-left-width:0px;border-bottom-width:0px;border-right-width:0px;" height="384" alt="15" src="http://beyondrelational.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/ashish/15_5F00_thumb_5F00_75D00A6C.png" width="354" border="0" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;Now the OLE DB Destination control needs to be configured. To configure the control, right click on the control and choose edit and you will see a new window named &lt;i&gt;OLE DB Destination Editor. &lt;/i&gt;In the&lt;i&gt; Connection Manager tab&lt;/i&gt; of OLE DB Destination control you have to provide information like connection, load method and the table name in which you have to insert data. Click on the &lt;i&gt;New &lt;/i&gt;button and &lt;i&gt;Configure OLE DB Connection Manager &lt;/i&gt;window will open up(see image below) you can create a New Connection or you can choose an existing database connection.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://beyondrelational.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/ashish/16_5F00_3B0D82F8.png"&gt;&lt;img title="16" style="border-top-width:0px;display:inline;border-left-width:0px;border-bottom-width:0px;border-right-width:0px;" height="478" alt="16" src="http://beyondrelational.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/ashish/16_5F00_thumb_5F00_508D5304.png" width="454" border="0" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;In this example we are going to choose already created connection in &lt;a href="http://beyondrelational.com/blogs/ashish/archive/2010/04/01/getting-started-with-ssis-executing-a-sql-server-query-or-stored-procedure-from-ssis.aspx"&gt;previous post&lt;/a&gt; (you can create a new as shown in previous post) or you can alternatively choose to New Connection as Create it as shown in &lt;a href="http://beyondrelational.com/blogs/ashish/archive/2010/04/01/getting-started-with-ssis-executing-a-sql-server-query-or-stored-procedure-from-ssis.aspx"&gt;previous post&lt;/a&gt;.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://beyondrelational.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/ashish/17_5F00_3AC88C09.png"&gt;&lt;img title="17" style="border-top-width:0px;display:inline;border-left-width:0px;border-bottom-width:0px;border-right-width:0px;" height="437" alt="17" src="http://beyondrelational.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/ashish/17_5F00_thumb_5F00_2503C50E.png" width="454" border="0" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;Click &lt;i&gt;ok &lt;/i&gt;after setting up a connection to database. In &lt;i&gt;Data Access Mode &lt;/i&gt;option of &lt;i&gt;OLE DB Destination Editor &lt;/i&gt;choose &lt;i&gt;Table or view- Fast Load. &lt;/i&gt;Now you have to choose table in the database in which you want to insert data if you already have table or view in database in which you want to insert data then you can choose it directly from the dropdown else you have to create a &lt;i&gt;New Table &lt;/i&gt;for this you have to click &lt;i&gt;New &lt;/i&gt;button provided in front of dropdown box after clicking that a &lt;i&gt;Create Table &lt;/i&gt;window will open up, we are using a &lt;i&gt;New Table&lt;/i&gt; in this example (as shown below in image).&lt;/p&gt;  &lt;p&gt;&lt;a href="http://beyondrelational.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/ashish/7_5F00_6151AB5A.png"&gt;&lt;img title="7" style="border-top-width:0px;display:inline;border-left-width:0px;border-bottom-width:0px;border-right-width:0px;" height="446" alt="7" src="http://beyondrelational.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/ashish/7_5F00_thumb_5F00_79E3D95B.png" width="454" border="0" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;Now click &lt;em&gt;Ok. &lt;/em&gt;Now navigate to &lt;em&gt;Mappings&lt;/em&gt; option in &lt;em&gt;OLE DB Destination Editor &lt;/em&gt;here you have to set the mappings between source and destination. Mapping decides which input column is in inserted to which output column. We map input and output columns as shown below in image and click &lt;em&gt;Ok.&lt;/em&gt;&lt;/p&gt;  &lt;p&gt;&lt;a href="http://beyondrelational.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/ashish/21_5F00_48E6B95F.png"&gt;&lt;img title="21" style="border-top-width:0px;display:inline;border-left-width:0px;border-bottom-width:0px;border-right-width:0px;" height="310" alt="21" src="http://beyondrelational.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/ashish/21_5F00_thumb_5F00_1306E5A7.png" width="454" border="0" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;Now you are done column mappings and back on &lt;em&gt;OLE DB Destination Editor &lt;/em&gt;now click &lt;em&gt;Ok &lt;/em&gt;on this window and you are done with configuring &lt;em&gt;OLE DB Destination and so your data flow task, &lt;/em&gt;your final Data Flow Task will looks like as shown below in image.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://beyondrelational.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/ashish/9_5F00_3ACF7C75.png"&gt;&lt;img title="9" style="border-top-width:0px;display:inline;border-left-width:0px;border-bottom-width:0px;border-right-width:0px;" height="272" alt="9" src="http://beyondrelational.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/ashish/9_5F00_thumb_5F00_281D136F.png" width="454" border="0" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;So now you are done with your package just save this package and run it by just right click on your package in solution explorer and click &lt;em&gt;Execute Package. &lt;/em&gt;If your package succeeded than it will look like this( as shown in image below).&lt;/p&gt;  &lt;p&gt;&lt;a href="http://beyondrelational.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/ashish/10_5F00_747737C1.png"&gt;&lt;img title="10" style="border-top-width:0px;display:inline;border-left-width:0px;border-bottom-width:0px;border-right-width:0px;" height="231" alt="10" src="http://beyondrelational.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/ashish/10_5F00_thumb_5F00_28ADF1B9.png" width="454" border="0" /&gt;&lt;/a&gt;&amp;#160; &lt;/p&gt;  &lt;p&gt;You can check the results by querying the newly created table in your database. For this you have to query your newly created table like this&lt;/p&gt;  &lt;pre class="brush:sql"&gt;SELECT * FROM tbl_names&lt;/pre&gt;

&lt;p&gt;and you will find 500 records in your table.&lt;/p&gt;

&lt;p&gt;&lt;a href="http://beyondrelational.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/ashish/22_5F00_2A14A53C.png"&gt;&lt;img title="22" style="border-top-width:0px;display:inline;border-left-width:0px;border-bottom-width:0px;border-right-width:0px;" height="306" alt="22" src="http://beyondrelational.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/ashish/22_5F00_thumb_5F00_5483670A.png" width="454" border="0" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;So in this way you can create a package which takes data from a text file and insert it into an SQL Server table, your file type may be different like you may have &lt;em&gt;CSV, Fixed Width or Tab Separated file&lt;/em&gt; still you can insert data into SQL Server table using this kind of files you just have to choose appropriate file type in &lt;em&gt;Flat File Source.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;If you found any problem in configuring this package or came across to any error, just post that error or problems in comments we will make sure that it will be rectified as soon as possible.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://beyondrelational.com/aggbug.aspx?PostID=4818" width="1" height="1"&gt;&lt;img src="http://feeds.feedburner.com/~r/AshishsBlog/~4/D9Qwv2JK9Qw" height="1" width="1"/&gt;</description><enclosure url="http://beyondrelational.com/cfs-file.ashx/__key/CommunityServer.Components.PostAttachments/00.00.00.48.18/Sample.txt" length="14942" type="text/plain" /><category domain="http://beyondrelational.com/blogs/ashish/archive/tags/MSBI/default.aspx">MSBI</category><category domain="http://beyondrelational.com/blogs/ashish/archive/tags/SSIS/default.aspx">SSIS</category><category domain="http://beyondrelational.com/blogs/ashish/archive/tags/BRH/default.aspx">BRH</category><feedburner:origLink>http://beyondrelational.com/blogs/ashish/archive/2010/04/25/loading-data-from-text-files-to-sql-server-tables-csv-files-tab-separated-files-or-fixed-column-length-files.aspx</feedburner:origLink></item><item><title>Getting started with SSIS – Executing a SQL Server Query or Stored Procedure from SSIS</title><link>http://feedproxy.google.com/~r/AshishsBlog/~3/N9xWs3SStJ4/getting-started-with-ssis-executing-a-sql-server-query-or-stored-procedure-from-ssis.aspx</link><pubDate>Thu, 01 Apr 2010 16:44:00 GMT</pubDate><guid isPermaLink="false">6e5011fa-7db5-4df3-bb79-9085c1d333b3:4371</guid><dc:creator>Ashish Gilhotra</dc:creator><slash:comments>5</slash:comments><wfw:commentRss>http://beyondrelational.com/blogs/ashish/rsscomments.aspx?PostID=4371</wfw:commentRss><comments>http://beyondrelational.com/blogs/ashish/archive/2010/04/01/getting-started-with-ssis-executing-a-sql-server-query-or-stored-procedure-from-ssis.aspx#comments</comments><description>&lt;p&gt;This article is intended to help the people who are beginners to SSIS. In this article we will see what is SSIS? Why we use SSIS ? and how to create a package using BIDS (Business Intelligence Development Studio). The article describes this through an example which will show us how a SQL Server query or Store Procedure can be executed SSIS.&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;What is SSIS&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;SSIS is an ETL (Extract, Transform and Load) process and a component of Microsoft which can be used to perform a broad range of data migration tasks. SSIS lets the user to move data from one data source to another data source. We can also perform numerous other tasks with the help of SSIS. &lt;/p&gt;  &lt;p&gt;&lt;strong&gt;How To Create Your First SSIS Package?&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;We will see How to Create Your First SSIS Package by looking into an example which will walk through us from the opening &lt;em&gt;BIDS (Business Intelligence Development Studio)&lt;/em&gt; to &lt;em&gt;Execute SQL&lt;/em&gt; from SSIS. &lt;/p&gt;  &lt;p&gt;&lt;strong&gt;Creating a SSIS Project&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;For creating a SSIS package you must have &lt;em&gt;SSIS (SQL Server Integration Services)&lt;/em&gt; and &lt;em&gt;BIDS (Business Intelligence Development Studio)&lt;/em&gt; installed on your machine. After installing SSIS and BIDS you can open BIDS. To open BIDS go to the option &lt;em&gt;SQL Server Business Intelligence Development Studio &lt;/em&gt;under &lt;em&gt;Start&amp;gt;&amp;gt;&amp;gt;All Programs&amp;gt;&amp;gt;&amp;gt;Microsoft SQL Server (Edition).&lt;/em&gt;&lt;/p&gt;  &lt;p&gt;&lt;a href="http://beyondrelational.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/ashish/1_5F00_2B0E026D.png"&gt;&lt;img style="border-right-width:0px;display:inline;border-top-width:0px;border-bottom-width:0px;border-left-width:0px;" title="1" border="0" alt="1" src="http://beyondrelational.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/ashish/1_5F00_thumb_5F00_62E2D741.png" width="454" height="152" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;Go to &lt;em&gt;File&amp;gt;&amp;gt;&amp;gt;New&amp;gt;&amp;gt;&amp;gt;Project&lt;/em&gt; from SQL Server Business Intelligence Development Studio (as shown in the below image) to open a new project.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://beyondrelational.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/ashish/2_5F00_543D4CBE.png"&gt;&lt;img style="border-right-width:0px;display:inline;border-top-width:0px;border-bottom-width:0px;border-left-width:0px;" title="2" border="0" alt="2" src="http://beyondrelational.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/ashish/2_5F00_thumb_5F00_05CB4B05.png" width="454" height="139" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;Once you see the &lt;em&gt;New Project &lt;/em&gt;window, select the project type name as &lt;em&gt;Integration Services Project&lt;/em&gt;&amp;#160; and name the project as &lt;em&gt;MyFirstSSIS. &lt;/em&gt;Select the location where you want to save the project by clicking on browse button or just type in the path.Once all information is filled up click on the &lt;em&gt;OK&lt;/em&gt; button to save the project.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://beyondrelational.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/ashish/1_5F00_0BB6E8EA.png"&gt;&lt;img style="border-right-width:0px;display:inline;border-top-width:0px;border-bottom-width:0px;border-left-width:0px;" title="1" border="0" alt="1" src="http://beyondrelational.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/ashish/1_5F00_thumb_5F00_0A77716D.png" width="454" height="409" /&gt;&lt;/a&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;Adding a Package to your Project&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;When the project is saved, the project file will be saved under the specified path. The project will be saved with a default package which will be blank.&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;a href="http://beyondrelational.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/ashish/6_5F00_5057AA41.png"&gt;&lt;img style="border-right-width:0px;display:inline;border-top-width:0px;border-bottom-width:0px;border-left-width:0px;" title="6" border="0" alt="6" src="http://beyondrelational.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/ashish/6_5F00_thumb_5F00_05865416.png" width="454" height="143" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;To add a package in your project &lt;em&gt;right click&lt;/em&gt; on the &lt;em&gt;SSISPackages&lt;/em&gt; node in the solution explorer at the left hand side of window or go to &lt;em&gt;project &lt;/em&gt;option from the menu and select &lt;em&gt;Add SSIS Package. &lt;/em&gt;Name the package you add as &lt;em&gt;MyFirstPackage.&lt;/em&gt;&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;Adding Execute SQL Task in Your Package&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;Now you have a package added to your project and it is time to add the control flow item &lt;em&gt;Execute SQL Task. &lt;/em&gt;Go to &lt;em&gt;view menu &lt;/em&gt;and select &lt;em&gt;Tool Box&lt;/em&gt; option to open the &lt;em&gt;Tool Box &lt;/em&gt;(See the image below)&lt;em&gt;.&lt;/em&gt;&lt;/p&gt;  &lt;p&gt;&lt;a href="http://beyondrelational.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/ashish/11_5F00_1A9C4058.png"&gt;&lt;img style="border-right-width:0px;display:inline;border-top-width:0px;border-bottom-width:0px;border-left-width:0px;" title="11" border="0" alt="11" src="http://beyondrelational.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/ashish/11_5F00_thumb_5F00_7534DD9A.png" width="304" height="406" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;To add the control flow item &lt;em&gt;Execute SQL Task&lt;/em&gt;&amp;#160;&lt;em&gt;to the &lt;/em&gt;package, double click on the item or simply drag and drop the item to your package window. Once the item is added the item will show up on the package (see the below image).&lt;/p&gt;  &lt;p&gt;&lt;a href="http://beyondrelational.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/ashish/7_5F00_06EB7A7D.png"&gt;&lt;img style="border-right-width:0px;display:inline;border-top-width:0px;border-bottom-width:0px;border-left-width:0px;" title="7" border="0" alt="7" src="http://beyondrelational.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/ashish/7_5F00_thumb_5F00_269CE4F6.png" width="454" height="154" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;Now your package with raw &lt;em&gt;Execute SQL Task &lt;/em&gt;will look like this now next step is to configure this &lt;em&gt;Execute SQL Task. &lt;/em&gt;&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;Configuring Execute SQL Task &lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;Now we have to configure the Execute SQL Task control to execute a &lt;em&gt;SQL Query or SQL Store Procedure &lt;/em&gt;from SSIS. To configure &lt;em&gt;Execute SQL Task&lt;/em&gt; right click on the control and choose &lt;em&gt;Edit &lt;/em&gt;option to configure the control.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://beyondrelational.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/ashish/12_5F00_217685E1.png"&gt;&lt;img style="border-right-width:0px;display:inline;border-top-width:0px;border-bottom-width:0px;border-left-width:0px;" title="12" border="0" alt="12" src="http://beyondrelational.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/ashish/12_5F00_thumb_5F00_375FF831.png" width="354" height="175" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;First of all we have to set up the database connection which will be used by this control, to set up the DB connection go to general tab of the properties window and set the connection type as OLE DB. Click on &lt;em&gt;Connection&lt;/em&gt; and select &lt;em&gt;New Connection&lt;/em&gt;&amp;#160; to set up a new connection ( see the below image).&lt;/p&gt;  &lt;p&gt;&lt;a href="http://beyondrelational.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/ashish/5_5F00_7F973DCC.png"&gt;&lt;img style="border-right-width:0px;display:inline;border-top-width:0px;border-bottom-width:0px;border-left-width:0px;" title="5" border="0" alt="5" src="http://beyondrelational.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/ashish/5_5F00_thumb_5F00_299C5D57.png" width="454" height="433" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;Setting up a Connection&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;When you select&amp;#160; the &lt;em&gt;New Connection&lt;/em&gt; the &lt;em&gt;Connection Manager&lt;/em&gt; window will open up, where you have to set up the connection information.&amp;#160; The following are the information need to be set up.&lt;/p&gt;  &lt;p&gt;Provider : Select the one which is default.   &lt;br /&gt;Server Name : The SQL server name on which the query should be executed.    &lt;br /&gt;Authentication Type : The type authentication through which the SQL server needs to be connected, which can be&amp;#160; windows or SQL Server.    &lt;br /&gt;Database name :&amp;#160; Select the database&amp;#160; to which we will query.&amp;#160; If you do not find the database to which you were supposed to make the query on clicking the drop down, check your connection information. &lt;/p&gt;  &lt;p&gt;To insure that the connection information you entered are correct , you can click on &lt;em&gt;Test Connection&lt;/em&gt; button .&lt;/p&gt;  &lt;p&gt;&lt;a href="http://beyondrelational.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/ashish/4_5F00_1680520D.png"&gt;&lt;img style="border-right-width:0px;display:inline;border-top-width:0px;border-bottom-width:0px;border-left-width:0px;" title="4" border="0" alt="4" src="http://beyondrelational.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/ashish/4_5F00_thumb_5F00_45682553.png" width="454" height="472" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;After clicking ok you are done with creating a connection and your &lt;em&gt;New Connection &lt;/em&gt;is ready to use you can see your connection at the bottom of the window in the &lt;em&gt;Connection Manager &lt;/em&gt;(See below image)&lt;em&gt;. &lt;/em&gt;To &lt;em&gt;edit &lt;/em&gt;the connection, &lt;em&gt;right click &lt;/em&gt;on the connection choose &lt;em&gt;edit &lt;/em&gt;or just double click on the connection.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://beyondrelational.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/ashish/6_5F00_7FE33B52.png"&gt;&lt;img style="border-right-width:0px;display:inline;border-top-width:0px;border-bottom-width:0px;border-left-width:0px;" title="6" border="0" alt="6" src="http://beyondrelational.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/ashish/6_5F00_thumb_5F00_51F8794B.png" width="454" height="82" /&gt;&lt;/a&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;Now its time to write the SQL statement to be executed, to write the statement to be executed choose the option &lt;em&gt;SQL Source Type&lt;/em&gt; as &lt;em&gt;Direct Input&lt;/em&gt; and write the SQL statement in the column against the SQL Statement option on the&amp;#160; Execute SQL Task Editor window. For an example we are taking an insert script which will insert a row when we execute the statement. Run the script provided below in your test Database to create a new table. Enter the insert script below against the &lt;em&gt;SQL Statement &lt;/em&gt;in the &lt;em&gt;Execute SQL Task Editor.&lt;/em&gt;&lt;/p&gt;  &lt;pre class="brush:sql"&gt;-- Create Table Run In your Database
CREATE TABLE [dbo].[DateInfo]( 
    [Date] [datetime] NULL, 
    [Year] [int] NULL, 
    [Month] [smallint] NULL, 
    [DayOfYear] [smallint] NULL, 
    [DayOfMonth] [smallint] NULL, 
    [DayOfWeek] [smallint] NULL, 
    [MonthName] [varchar](10) NULL, 
    [DayName] [varchar](10) NULL 
) ON [PRIMARY]&lt;/pre&gt;

&lt;pre class="brush:sql"&gt;--Script to Insert Into table put it at the place of SQLStatement
INSERT INTO DateInfo 
SELECT 
    GETDATE(), 
    DATEPART(YEAR,GETDATE()), 
    DATEPART(MONTH,GETDATE()), 
    DATEPART(DAYOFYEAR,GETDATE()), 
    DATEPART(DAY,GETDATE()), 
    DATEPART(WEEKDAY,GETDATE()), 
    DATENAME(MONTH,GETDATE()), 
    DATENAME(DW,GETDATE())&lt;/pre&gt;

&lt;p&gt;Once you enter the statement, click the OK button on the bottom of Execute SQL Task Editor window and you are done with Configuring Execute SQL Task. Now Save the package and the package is ready to execute. To execute the package go to &lt;i&gt;Solution Explorer &lt;/i&gt;on the right hand side of window &lt;em&gt;Right Click&lt;/em&gt; on the package you created in the example it is &lt;em&gt;MyFirstPackage &lt;/em&gt;and click &lt;em&gt;Execute Package &lt;/em&gt;as shown in the below image.&lt;/p&gt;

&lt;p&gt;&lt;a href="http://beyondrelational.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/ashish/21_5F00_5B1E412D.png"&gt;&lt;img style="border-right-width:0px;display:inline;border-top-width:0px;border-bottom-width:0px;border-left-width:0px;" title="21" border="0" alt="21" src="http://beyondrelational.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/ashish/21_5F00_thumb_5F00_438693BA.png" width="354" height="109" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;If the package successfully runs, you can see that the control turns into green color ( as shown in the below image).&lt;/p&gt;

&lt;p&gt;&lt;a href="http://beyondrelational.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/ashish/5_5F00_6ECC6FDC.png"&gt;&lt;img style="border-right-width:0px;display:inline;border-top-width:0px;border-bottom-width:0px;border-left-width:0px;" title="5" border="0" alt="5" src="http://beyondrelational.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/ashish/5_5F00_thumb_5F00_67439120.png" width="454" height="214" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;To insure that the package executed successfully you can query the table in your database by executing the query below. &lt;/p&gt;

&lt;pre class="brush:sql"&gt;SELECT * FROM DateInfo&lt;/pre&gt;

&lt;p&gt;And here is the result set for the query. You will find a record in your table after the successful execution of package.&lt;/p&gt;

&lt;p&gt;&lt;a href="http://beyondrelational.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/ashish/10_5F00_28742B29.png"&gt;&lt;img style="border-right-width:0px;display:inline;border-top-width:0px;border-bottom-width:0px;border-left-width:0px;" title="10" border="0" alt="10" src="http://beyondrelational.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/ashish/10_5F00_thumb_5F00_67D46F6A.png" width="454" height="92" /&gt;&lt;/a&gt;&amp;#160;&lt;/p&gt;

&lt;p&gt;You can also create a procedure of this insert query as stated below&lt;/p&gt;

&lt;pre class="brush:sql"&gt;CREATE PROC Sp_InsertInfo
AS
	INSERT INTO DateInfo 
	SELECT 
		GETDATE(), 
		DATEPART(YEAR,GETDATE()), 
		DATEPART(MONTH,GETDATE()), 
		DATEPART(DAYOFYEAR,GETDATE()), 
		DATEPART(DAY,GETDATE()), 
		DATEPART(WEEKDAY,GETDATE()), 
		DATENAME(MONTH,GETDATE()), 
		DATENAME(DW,GETDATE())&lt;/pre&gt;

&lt;p&gt;After creating the package you can write &lt;em&gt;Exec Sp_InsertInfo&lt;/em&gt; instead of &lt;em&gt;Insert Statement &lt;/em&gt;in the &lt;em&gt;Execute SQL Task Editor &lt;/em&gt;and click &lt;em&gt;OK &lt;/em&gt;to save the editor. &lt;em&gt;&lt;/em&gt;Now you are done with your Execute SQL Task with the help of Store Procedure now again repeat the package and check data in the table you will get another row in your table.&lt;/p&gt;

&lt;p&gt;So in this way you can create a simple package using &lt;em&gt;Execute SQL Task. &lt;/em&gt;You can execute any other SQL Query or Procedure with the help of Execute SQL Task. We will see many other examples and controls of SSIS in future posts.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://beyondrelational.com/aggbug.aspx?PostID=4371" width="1" height="1"&gt;&lt;img src="http://feeds.feedburner.com/~r/AshishsBlog/~4/N9xWs3SStJ4" height="1" width="1"/&gt;</description><category domain="http://beyondrelational.com/blogs/ashish/archive/tags/MSBI/default.aspx">MSBI</category><category domain="http://beyondrelational.com/blogs/ashish/archive/tags/SSIS/default.aspx">SSIS</category><feedburner:origLink>http://beyondrelational.com/blogs/ashish/archive/2010/04/01/getting-started-with-ssis-executing-a-sql-server-query-or-stored-procedure-from-ssis.aspx</feedburner:origLink></item><item><title>System Procedure sp_configure</title><link>http://feedproxy.google.com/~r/AshishsBlog/~3/2LzwykPRo04/system-procedure-sp-configure.aspx</link><pubDate>Wed, 17 Mar 2010 16:04:00 GMT</pubDate><guid isPermaLink="false">6e5011fa-7db5-4df3-bb79-9085c1d333b3:4176</guid><dc:creator>Ashish Gilhotra</dc:creator><slash:comments>0</slash:comments><wfw:commentRss>http://beyondrelational.com/blogs/ashish/rsscomments.aspx?PostID=4176</wfw:commentRss><comments>http://beyondrelational.com/blogs/ashish/archive/2010/03/17/system-procedure-sp-configure.aspx#comments</comments><description>&lt;p&gt;After a long period of time i am again starting blogging and try to keep it continue.I like to start a series of blog post about system store procedures used in SQL Server.To kick this series out i am picking up sp_configure system procedure.&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;Use of sp_configure&lt;/strong&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;In simple words sp_configure is a process to change or display global settings of current SQL Server.You can see the global settings and change them with the help of this procedure.&lt;/p&gt;  &lt;p&gt;There are many settings of SQL Server which we can see and change. I will provide a details of settings and their uses in detail in later posts.First we see the columns returned by this procedure and their meanings.&lt;/p&gt;  &lt;p&gt;When you run sp_configure you will get following columns:&lt;/p&gt;  &lt;pre&gt;Column        Description
========      ======================================
Name          Name of the configuration option. 
Minimum       Minimum allowed value for the particular 
	      configuration. 
Maximum       Maximum allowed value for the particular
	      configuration. 
config_value  Value which we set by using sp_configure. 
run_value     Value which on which the particular configuration 
	      is currently running(we will see it in detail also).&lt;/pre&gt;

&lt;p&gt;&lt;strong&gt;How to run sp_configure&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Ok so there are many settings on SQL Server which you can change from this procedure so here is the syntax for change the setting.&lt;/p&gt;

&lt;pre class="brush:sql"&gt;USE master;
GO
EXECUTE sp_configure &amp;#39;option name&amp;#39;,&amp;#39;value&amp;#39;;&lt;/pre&gt;

&lt;p&gt;After running that you will get a message like &lt;/p&gt;

&lt;p&gt;“Configuration option ‘option name’ changed from ‘old value’ to ‘new value’. Run the RECONFIGURE statement to install.”&lt;/p&gt;

&lt;p&gt;So as message states we have to run reconfigure statement like this&lt;/p&gt;

&lt;pre class="brush:sql"&gt;USE master;
GO
RECONFIGURE;&lt;/pre&gt;

&lt;p&gt;So in this way you can change your global settings(server level settings) from sp_configure.&lt;/p&gt;

&lt;p&gt;Now lets look in to the details of config_value and run_value. Config_value shows the value which is set by or configured by sp_configure and run_value shows the value on which the configuration is currently running. For making it further clear we look into sys.configurations system view.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;System View sys.configurations:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;sys.configuration is a system view which hold same info as sp_run_configure. SYS.Configurations view have following columns:&lt;/p&gt;

&lt;pre&gt;Column                  Description
================        =====================================
configuration_id        Unique ID for the configuration value.
name                    Name of the configuration option.
value                   Configured value for this option.
minimum                 Minimum allowed value for the configuration
			option.
maximum                 Maximum allowed value for the configuration
			option.
value_in_use            Running value currently in effect for this
			option.
description             Description of the configuration option.
is_dynamic              Decides whether there is need to restart
			services or not.
is_advanced             1 = The variable is displayed only when the
			show advanced option is set.&lt;/pre&gt;

&lt;p&gt;So here is_dynamic column decides whether there is need to restart SQL Server services or not. As if value of is_dynamic is 1 then you just have to run reconfigure statement and you are done there is no need to restart your SQL Server services for this but if your is_dynamic column value is 0 this means &amp;quot;NOT DYNAMIC&amp;quot; and you have to restart your services and after that your settings will take effect. &lt;/p&gt;

&lt;p&gt;When you change any configuration setting so before running &amp;quot;reconfigure&amp;quot; or before starting SQL Server Services you can see the values of &amp;quot;config_value&amp;quot; and &amp;quot;run_value&amp;quot; is different so you can differentiate these two columns as &amp;quot;run_value&amp;quot; is showing the currently running configuration value and &amp;quot;config_value&amp;quot; is showing the value you configured by sp_configure and after restarting SQL Server Services or running &amp;quot;reconfigure&amp;quot; both values will be again same.&lt;/p&gt;

&lt;p&gt;In later posts we will see all the configurations value one by one there uses and effects and many other uses of sp_configure.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://beyondrelational.com/aggbug.aspx?PostID=4176" width="1" height="1"&gt;&lt;img src="http://feeds.feedburner.com/~r/AshishsBlog/~4/2LzwykPRo04" height="1" width="1"/&gt;</description><feedburner:origLink>http://beyondrelational.com/blogs/ashish/archive/2010/03/17/system-procedure-sp-configure.aspx</feedburner:origLink></item><item><title>Temporary Tables and Table Variables An Overview</title><link>http://feedproxy.google.com/~r/AshishsBlog/~3/7DsQfpFraLA/temporary-tables-and-table-variables.aspx</link><pubDate>Fri, 31 Jul 2009 14:50:00 GMT</pubDate><guid isPermaLink="false">6e5011fa-7db5-4df3-bb79-9085c1d333b3:595</guid><dc:creator>Ashish Gilhotra</dc:creator><slash:comments>4</slash:comments><wfw:commentRss>http://beyondrelational.com/blogs/ashish/rsscomments.aspx?PostID=595</wfw:commentRss><comments>http://beyondrelational.com/blogs/ashish/archive/2009/07/31/temporary-tables-and-table-variables.aspx#comments</comments><description>&lt;p&gt;Some days back i was asked about Temp Tables and Table Variables the basic difference why one is better than another one and all, and i am not able to provide a satisfactory reason\answer at that time so this is the time when i studied about a lots about it and i go through several topics, it takes&amp;nbsp; one whole day and night to me to understand some aspects of this and here i am writing a detailed post about Temp Tables and Table Variables which may help some of peoples like me to understand in a better way.&lt;/p&gt;
&lt;p&gt;So going through very basic details let talk about Temporary Tables first. So there are two types of temporary tables &lt;/p&gt;
&lt;p&gt;A.)&amp;nbsp; Local declared with one # Sign (#)    &lt;br /&gt;B.) Global declared with two # Sign (##)&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Both of these tables created by simple &lt;a href="http://msdn.microsoft.com/en-us/library/ms174979.aspx" target="_blank"&gt;CREATE TABLE (BOL)&lt;/a&gt;&amp;nbsp; syntax except that # is used&amp;nbsp; for Local Temporary Tables&amp;nbsp; declaration and ##&amp;nbsp; is used for Global Temporary Tables.&lt;/p&gt;
&lt;p&gt;The Major difference between these two are Local Temporary tables (#) are visible in current connection and Global Temporary Table (##) are visible to all sessions or to the entire instance. You should always check for existence of global temporary table before creating it.&lt;/p&gt;
&lt;p&gt;Let see with an example..&lt;/p&gt;
&lt;p&gt;Open SSMS connect it and now create a Local Temporary table like this.&lt;/p&gt;
&lt;div id="codeSnippetWrapper"&gt;
&lt;div id="codeSnippet" style="border-style:none;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;direction:ltr;line-height:12pt;font-family:&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;text-align:left;"&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;direction:ltr;line-height:12pt;font-family:&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;text-align:left;"&gt;&lt;span style="color:#008000;"&gt;-- Creating Local Temporary Table&lt;/span&gt;&lt;/pre&gt;

&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;direction:ltr;line-height:12pt;font-family:&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;text-align:left;"&gt;&amp;nbsp;&lt;/pre&gt;

&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;direction:ltr;line-height:12pt;font-family:&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;text-align:left;"&gt;&lt;span style="color:#0000ff;"&gt;CREATE&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;TABLE&lt;/span&gt; #LOCALTEST(C1 &lt;span style="color:#0000ff;"&gt;INT&lt;/span&gt;, C2 &lt;span style="color:#0000ff;"&gt;VARCHAR&lt;/span&gt;(50))&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;This will create a temporary table named LOCALTEST now open other SSMS connect it and again retry to create another table with same name but using the new connection and check if it created or not so here it is &amp;hellip;.&lt;/p&gt;
&lt;div id="codeSnippetWrapper"&gt;
&lt;div id="codeSnippet" style="border-style:none;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;direction:ltr;line-height:12pt;font-family:&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;text-align:left;"&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;direction:ltr;line-height:12pt;font-family:&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;text-align:left;"&gt;&lt;span style="color:#008000;"&gt;-- Create Temporary Table with same name &lt;/span&gt;&lt;/pre&gt;

&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;direction:ltr;line-height:12pt;font-family:&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;text-align:left;"&gt;&lt;span style="color:#0000ff;"&gt;CREATE&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;TABLE&lt;/span&gt; #LOCALTEST(C1 &lt;span style="color:#0000ff;"&gt;INT&lt;/span&gt;, C2 &lt;span style="color:#0000ff;"&gt;VARCHAR&lt;/span&gt;(50))&lt;/pre&gt;

&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;direction:ltr;line-height:12pt;font-family:&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;text-align:left;"&gt;&amp;nbsp;&lt;/pre&gt;

&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;direction:ltr;line-height:12pt;font-family:&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;text-align:left;"&gt;&lt;span style="color:#008000;"&gt;-- Try to find out table with &amp;#39;LOCALTEST&amp;#39;  name in TempDb&lt;/span&gt;&lt;/pre&gt;

&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;direction:ltr;line-height:12pt;font-family:&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;text-align:left;"&gt;&amp;nbsp;&lt;/pre&gt;

&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;direction:ltr;line-height:12pt;font-family:&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;text-align:left;"&gt;&lt;span style="color:#0000ff;"&gt;USE&lt;/span&gt; TEMPDB&lt;/pre&gt;

&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;direction:ltr;line-height:12pt;font-family:&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;text-align:left;"&gt;&lt;span style="color:#0000ff;"&gt;GO&lt;/span&gt;&lt;/pre&gt;

&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;direction:ltr;line-height:12pt;font-family:&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;text-align:left;"&gt;&amp;nbsp;&lt;/pre&gt;

&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;direction:ltr;line-height:12pt;font-family:&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;text-align:left;"&gt;&lt;span style="color:#0000ff;"&gt;SELECT&lt;/span&gt; Table_Catalog, Table_Name &lt;span style="color:#0000ff;"&gt;FROM&lt;/span&gt; information_schema.tables&lt;/pre&gt;

&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;direction:ltr;line-height:12pt;font-family:&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;text-align:left;"&gt;&lt;span style="color:#0000ff;"&gt;WHERE&lt;/span&gt; table_name &lt;span style="color:#0000ff;"&gt;like&lt;/span&gt; &lt;span style="color:#006080;"&gt;&amp;#39;%LOCALTEST%&amp;#39;&lt;/span&gt;&lt;/pre&gt;

&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;direction:ltr;line-height:12pt;font-family:&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;text-align:left;"&gt;GO&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;So here is the result set for the above query &lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;a href="http://beyondrelational.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/ashish/P31_5F00_1_5F00_126C9177.jpg"&gt;&lt;img title="P31_1" style="border-top-width:0px;display:inline;border-left-width:0px;border-bottom-width:0px;border-right-width:0px;" alt="P31_1" src="http://beyondrelational.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/ashish/P31_5F00_1_5F00_thumb_5F00_11994CEF.jpg" width="402" border="0" height="160" /&gt;&lt;/a&gt; &lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;So its very clear from the result set that there are two Local Temporary Tables with the same name.&lt;/p&gt;
&lt;p&gt;In order to identify which table is created by which user (in case of same temporary table name), SQL Server suffixes it with the number, you can see that in this image.&lt;/p&gt;
&lt;p&gt;But when you try the same thing with Global Temporary Tables then it will result into an error.&lt;/p&gt;
&lt;p&gt;So here is some points about Temporary tables..&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Can be create by simple Create Table Syntax use # for Local Temporary Table and ## for Global Temporary table. &lt;/li&gt;
&lt;li&gt;Local temporary tables will be dropped at the end of current session but if it is created inside a store procedure, it will be dropped when store procedure is finished. &lt;/li&gt;
&lt;li&gt;Its name is limited to 116 characters. &lt;/li&gt;
&lt;li&gt;Foreign Key constraints can&amp;rsquo;t be applied to primary tables. &lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Now we know a little about Table Variables :&lt;/p&gt;
&lt;p&gt;Table Variables (@) introduced first in SQL Server 2000 and onwards as name suggest its a variable of type table. Its definition&amp;rsquo;s include column definition, names, data type and constraint(Foreign Key Constraint are not allowed). They are more flexible and and &lt;span style="text-decoration:line-through;"&gt;always stay in memory &lt;/span&gt;well this is not true that table Variables stay always in memory this is a MYTH as table variables may be stored as in same way in TempDb as temporary tables we will look at some example for this. They are created with the Declare @variable syntax. There are some properties for Table Variables&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;They have well defined limited scope and are not part of persistent database. &lt;/li&gt;
&lt;li&gt;Transactional rollbacks doesn&amp;rsquo;t affect on them. &lt;/li&gt;
&lt;li&gt;They have very limited scope like current batch of statements so they can be deleted automatically after the completion of statements. &lt;/li&gt;
&lt;li&gt;You don&amp;rsquo;t use them in nested procedures. &lt;/li&gt;
&lt;li&gt;You not able to truncate a table variable. &lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;So these are the some of basics for Table Variables and Temporary Tables but our Aim is to be find out which one is best in terms of performance, Advantages&amp;nbsp; &amp;amp; Disadvantages for each and some considerations so we try to understand things why one is better then another and why not so&lt;/p&gt;
&lt;p&gt;&lt;b&gt;A.)&lt;/b&gt; Table Variables have a limited scope and are not part of persistent database, transaction rollback do not affect them.&lt;/p&gt;
&lt;p&gt;Let&amp;rsquo;s understand what does it mean by transaction rollback do not affect them just take a simple example for this..&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;div id="codeSnippetWrapper"&gt;
&lt;div id="codeSnippet" style="border-style:none;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;direction:ltr;line-height:12pt;font-family:&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;text-align:left;"&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;direction:ltr;line-height:12pt;font-family:&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;text-align:left;"&gt;&lt;span style="color:#008000;"&gt;-- Create Tempoarary Table &lt;/span&gt;&lt;/pre&gt;

&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;direction:ltr;line-height:12pt;font-family:&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;text-align:left;"&gt;&lt;span style="color:#0000ff;"&gt;CREATE&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;TABLE&lt;/span&gt; #LOCALTEST(C1 &lt;span style="color:#0000ff;"&gt;INT&lt;/span&gt;, C2 &lt;span style="color:#0000ff;"&gt;VARCHAR&lt;/span&gt;(50))&lt;/pre&gt;

&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;direction:ltr;line-height:12pt;font-family:&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;text-align:left;"&gt;&lt;span style="color:#008000;"&gt;-- Declare Table Variable&lt;/span&gt;&lt;/pre&gt;

&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;direction:ltr;line-height:12pt;font-family:&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;text-align:left;"&gt;&lt;span style="color:#0000ff;"&gt;DECLARE&lt;/span&gt; @LOCALTEST &lt;span style="color:#0000ff;"&gt;TABLE&lt;/span&gt;(C1 &lt;span style="color:#0000ff;"&gt;INT&lt;/span&gt;, C2 &lt;span style="color:#0000ff;"&gt;VARCHAR&lt;/span&gt;(50))&lt;/pre&gt;

&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;direction:ltr;line-height:12pt;font-family:&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;text-align:left;"&gt;&amp;nbsp;&lt;/pre&gt;

&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;direction:ltr;line-height:12pt;font-family:&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;text-align:left;"&gt;&lt;span style="color:#008000;"&gt;-- Insert Values into both&lt;/span&gt;&lt;/pre&gt;

&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;direction:ltr;line-height:12pt;font-family:&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;text-align:left;"&gt;Insert &lt;span style="color:#0000ff;"&gt;into&lt;/span&gt; #LOCALTEST &lt;span style="color:#0000ff;"&gt;SELECT&lt;/span&gt; 1 ,&lt;span style="color:#006080;"&gt;&amp;#39;Ashish&amp;#39;&lt;/span&gt;&lt;/pre&gt;

&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;direction:ltr;line-height:12pt;font-family:&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;text-align:left;"&gt;Insert &lt;span style="color:#0000ff;"&gt;into&lt;/span&gt; @LOCALTEST &lt;span style="color:#0000ff;"&gt;SELECT&lt;/span&gt; 1 ,&lt;span style="color:#006080;"&gt;&amp;#39;Ashish&amp;#39;&lt;/span&gt;&lt;/pre&gt;

&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;direction:ltr;line-height:12pt;font-family:&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;text-align:left;"&gt;&amp;nbsp;&lt;/pre&gt;

&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;direction:ltr;line-height:12pt;font-family:&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;text-align:left;"&gt;&lt;span style="color:#008000;"&gt;-- Begin Transaction (Update both Temp table &amp;amp; Table Var)&lt;/span&gt;&lt;/pre&gt;

&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;direction:ltr;line-height:12pt;font-family:&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;text-align:left;"&gt;&lt;span style="color:#0000ff;"&gt;BEGIN&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;TRAN&lt;/span&gt;&lt;/pre&gt;

&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;direction:ltr;line-height:12pt;font-family:&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;text-align:left;"&gt;    &lt;span style="color:#0000ff;"&gt;UPDATE&lt;/span&gt; #LOCALTEST &lt;span style="color:#0000ff;"&gt;SET&lt;/span&gt; C2=&lt;span style="color:#006080;"&gt;&amp;#39;ASHISH GILHOTRA&amp;#39;&lt;/span&gt; &lt;/pre&gt;

&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;direction:ltr;line-height:12pt;font-family:&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;text-align:left;"&gt;    &lt;span style="color:#0000ff;"&gt;UPDATE&lt;/span&gt; @LOCALTEST &lt;span style="color:#0000ff;"&gt;SET&lt;/span&gt; C2=&lt;span style="color:#006080;"&gt;&amp;#39;ASHISH GILHOTRA&amp;#39;&lt;/span&gt; &lt;/pre&gt;

&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;direction:ltr;line-height:12pt;font-family:&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;text-align:left;"&gt;&lt;span style="color:#008000;"&gt;-- Rollback Tran&lt;/span&gt;&lt;/pre&gt;

&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;direction:ltr;line-height:12pt;font-family:&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;text-align:left;"&gt;&lt;span style="color:#0000ff;"&gt;ROLLBACK&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;TRAN&lt;/span&gt;&lt;/pre&gt;

&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;direction:ltr;line-height:12pt;font-family:&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;text-align:left;"&gt;&amp;nbsp;&lt;/pre&gt;

&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;direction:ltr;line-height:12pt;font-family:&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;text-align:left;"&gt; &lt;span style="color:#008000;"&gt;-- Check data&lt;/span&gt;&lt;/pre&gt;

&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;direction:ltr;line-height:12pt;font-family:&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;text-align:left;"&gt;&lt;span style="color:#0000ff;"&gt;SELECT&lt;/span&gt; * &lt;span style="color:#0000ff;"&gt;FROM&lt;/span&gt; #LOCALTEST&lt;/pre&gt;

&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;direction:ltr;line-height:12pt;font-family:&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;text-align:left;"&gt;&lt;span style="color:#0000ff;"&gt;SELECT&lt;/span&gt; * &lt;span style="color:#0000ff;"&gt;FROM&lt;/span&gt; @LOCALTEST&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;and here is the result set &lt;/p&gt;
&lt;p&gt;&lt;a href="http://beyondrelational.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/ashish/P32_5F00_1_5F00_60441104.jpg"&gt;&lt;img title="P32_1" style="border-top-width:0px;display:inline;border-left-width:0px;border-bottom-width:0px;border-right-width:0px;" alt="P32_1" src="http://beyondrelational.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/ashish/P32_5F00_1_5F00_thumb_5F00_11D49FFC.jpg" width="275" border="0" height="202" /&gt;&lt;/a&gt; &lt;/p&gt;
&lt;p&gt;From this it&amp;rsquo;s very clear that Table Variables doesn&amp;rsquo;t take part in rollback transactions.So it may be or may not be useful for developers depends on the developers.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;B.) &lt;/b&gt;There is less locking and logging on table variables then temporary tables so what does it means so we take an another example to understand this ..&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;div id="codeSnippetWrapper"&gt;
&lt;div id="codeSnippet" style="border-style:none;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;direction:ltr;line-height:12pt;font-family:&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;text-align:left;"&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;direction:ltr;line-height:12pt;font-family:&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;text-align:left;"&gt;&lt;span style="color:#0000ff;"&gt;USE&lt;/span&gt; tempdb&lt;/pre&gt;

&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;direction:ltr;line-height:12pt;font-family:&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;text-align:left;"&gt;&lt;span style="color:#0000ff;"&gt;GO&lt;/span&gt;&lt;/pre&gt;

&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;direction:ltr;line-height:12pt;font-family:&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;text-align:left;"&gt;&amp;nbsp;&lt;/pre&gt;

&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;direction:ltr;line-height:12pt;font-family:&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;text-align:left;"&gt;&lt;span style="color:#008000;"&gt;-- Drop table #LOCALTEST&lt;/span&gt;&lt;/pre&gt;

&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;direction:ltr;line-height:12pt;font-family:&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;text-align:left;"&gt;&lt;span style="color:#008000;"&gt;-- Drop table DUMMYDATA&lt;/span&gt;&lt;/pre&gt;

&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;direction:ltr;line-height:12pt;font-family:&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;text-align:left;"&gt;&lt;span style="color:#008000;"&gt;-- Create a dummy table&lt;/span&gt;&lt;/pre&gt;

&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;direction:ltr;line-height:12pt;font-family:&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;text-align:left;"&gt;&lt;span style="color:#0000ff;"&gt;CREATE&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;TABLE&lt;/span&gt; DUMMYDATA (A &lt;span style="color:#0000ff;"&gt;int&lt;/span&gt;, B &lt;span style="color:#0000ff;"&gt;varchar&lt;/span&gt;(100))&lt;/pre&gt;

&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;direction:ltr;line-height:12pt;font-family:&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;text-align:left;"&gt;&lt;span style="color:#008000;"&gt;-- Populate Data in it&lt;/span&gt;&lt;/pre&gt;

&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;direction:ltr;line-height:12pt;font-family:&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;text-align:left;"&gt;&lt;span style="color:#0000ff;"&gt;Declare&lt;/span&gt; @i &lt;span style="color:#0000ff;"&gt;int&lt;/span&gt;&lt;/pre&gt;

&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;direction:ltr;line-height:12pt;font-family:&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;text-align:left;"&gt;&lt;span style="color:#0000ff;"&gt;set&lt;/span&gt; @i=1&lt;/pre&gt;

&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;direction:ltr;line-height:12pt;font-family:&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;text-align:left;"&gt;&lt;span style="color:#0000ff;"&gt;while&lt;/span&gt; @i&amp;lt;1001&lt;/pre&gt;

&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;direction:ltr;line-height:12pt;font-family:&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;text-align:left;"&gt;&lt;span style="color:#0000ff;"&gt;BEGIN&lt;/span&gt;&lt;/pre&gt;

&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;direction:ltr;line-height:12pt;font-family:&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;text-align:left;"&gt;INSERT &lt;span style="color:#0000ff;"&gt;into&lt;/span&gt; DUMMYDATA &lt;span style="color:#0000ff;"&gt;SELECT&lt;/span&gt; @i,REPLICATE(&lt;span style="color:#006080;"&gt;&amp;#39;A&amp;#39;&lt;/span&gt;,100)&lt;/pre&gt;

&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;direction:ltr;line-height:12pt;font-family:&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;text-align:left;"&gt;&lt;span style="color:#0000ff;"&gt;SET&lt;/span&gt; @i=@i+1&lt;/pre&gt;

&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;direction:ltr;line-height:12pt;font-family:&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;text-align:left;"&gt;&lt;span style="color:#0000ff;"&gt;END&lt;/span&gt;&lt;/pre&gt;

&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;direction:ltr;line-height:12pt;font-family:&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;text-align:left;"&gt;--&lt;span style="color:#0000ff;"&gt;select&lt;/span&gt; * &lt;span style="color:#0000ff;"&gt;from&lt;/span&gt; DUMMYDATA&lt;/pre&gt;

&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;direction:ltr;line-height:12pt;font-family:&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;text-align:left;"&gt; &lt;/pre&gt;

&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;direction:ltr;line-height:12pt;font-family:&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;text-align:left;"&gt;--&lt;span style="color:#0000ff;"&gt;Using&lt;/span&gt; #LOCALTEST &lt;/pre&gt;

&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;direction:ltr;line-height:12pt;font-family:&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;text-align:left;"&gt;&lt;span style="color:#0000ff;"&gt;CREATE&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;TABLE&lt;/span&gt; #LOCALTEST(C1 &lt;span style="color:#0000ff;"&gt;INT&lt;/span&gt;, C2 &lt;span style="color:#0000ff;"&gt;VARCHAR&lt;/span&gt;(100))&lt;/pre&gt;

&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;direction:ltr;line-height:12pt;font-family:&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;text-align:left;"&gt;&lt;span style="color:#0000ff;"&gt;GO&lt;/span&gt;&lt;/pre&gt;

&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;direction:ltr;line-height:12pt;font-family:&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;text-align:left;"&gt;&lt;span style="color:#0000ff;"&gt;BEGIN&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;TRAN&lt;/span&gt; &lt;/pre&gt;

&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;direction:ltr;line-height:12pt;font-family:&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;text-align:left;"&gt;    INSERT &lt;span style="color:#0000ff;"&gt;INTO&lt;/span&gt; #LOCALTEST(C1,C2) &lt;/pre&gt;

&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;direction:ltr;line-height:12pt;font-family:&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;text-align:left;"&gt;    &lt;span style="color:#0000ff;"&gt;SELECT&lt;/span&gt; A,B &lt;span style="color:#0000ff;"&gt;FROM&lt;/span&gt; DUMMYDATA&lt;/pre&gt;

&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;direction:ltr;line-height:12pt;font-family:&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;text-align:left;"&gt;&lt;span style="color:#008000;"&gt;-- Using @LOCALTEST&lt;/span&gt;&lt;/pre&gt;

&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;direction:ltr;line-height:12pt;font-family:&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;text-align:left;"&gt;&lt;span style="color:#0000ff;"&gt;DECLARE&lt;/span&gt; @LOCALTEST &lt;span style="color:#0000ff;"&gt;TABLE&lt;/span&gt;(C1 &lt;span style="color:#0000ff;"&gt;INT&lt;/span&gt;, C2 &lt;span style="color:#0000ff;"&gt;VARCHAR&lt;/span&gt;(100))&lt;/pre&gt;

&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;direction:ltr;line-height:12pt;font-family:&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;text-align:left;"&gt;&amp;nbsp;&lt;/pre&gt;

&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;direction:ltr;line-height:12pt;font-family:&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;text-align:left;"&gt;&lt;span style="color:#0000ff;"&gt;BEGIN&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;TRAN&lt;/span&gt; &lt;/pre&gt;

&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;direction:ltr;line-height:12pt;font-family:&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;text-align:left;"&gt;    INSERT &lt;span style="color:#0000ff;"&gt;INTO&lt;/span&gt; @LOCALTEST(C1,C2) &lt;/pre&gt;

&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;direction:ltr;line-height:12pt;font-family:&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;text-align:left;"&gt;    &lt;span style="color:#0000ff;"&gt;SELECT&lt;/span&gt; A,B &lt;span style="color:#0000ff;"&gt;FROM&lt;/span&gt; DUMMYDATA&lt;/pre&gt;

&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;direction:ltr;line-height:12pt;font-family:&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;text-align:left;"&gt;&amp;nbsp;&lt;/pre&gt;

&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;direction:ltr;line-height:12pt;font-family:&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;text-align:left;"&gt;&lt;span style="color:#008000;"&gt;-- Now check for locks&lt;/span&gt;&lt;/pre&gt;

&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;direction:ltr;line-height:12pt;font-family:&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;text-align:left;"&gt;&amp;nbsp;&lt;/pre&gt;

&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;direction:ltr;line-height:12pt;font-family:&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;text-align:left;"&gt;&lt;span style="color:#0000ff;"&gt;select&lt;/span&gt; request_session_id, resource_type, db_name(resource_database_id),(&lt;span style="color:#0000ff;"&gt;case&lt;/span&gt; resource_type&lt;/pre&gt;

&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;direction:ltr;line-height:12pt;font-family:&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;text-align:left;"&gt;      &lt;span style="color:#0000ff;"&gt;WHEN&lt;/span&gt; &lt;span style="color:#006080;"&gt;&amp;#39;OBJECT&amp;#39;&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;then&lt;/span&gt; object_name(resource_associated_entity_id)&lt;/pre&gt;

&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;direction:ltr;line-height:12pt;font-family:&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;text-align:left;"&gt;      &lt;span style="color:#0000ff;"&gt;WHEN&lt;/span&gt; &lt;span style="color:#006080;"&gt;&amp;#39;DATABASE&amp;#39;&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;then&lt;/span&gt; &lt;span style="color:#006080;"&gt;&amp;#39; &amp;#39;&lt;/span&gt;&lt;/pre&gt;

&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;direction:ltr;line-height:12pt;font-family:&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;text-align:left;"&gt;      &lt;span style="color:#0000ff;"&gt;ELSE&lt;/span&gt; (&lt;span style="color:#0000ff;"&gt;select&lt;/span&gt; object_name(object_id) &lt;/pre&gt;

&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;direction:ltr;line-height:12pt;font-family:&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;text-align:left;"&gt;            &lt;span style="color:#0000ff;"&gt;from&lt;/span&gt; sys.partitions &lt;/pre&gt;

&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;direction:ltr;line-height:12pt;font-family:&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;text-align:left;"&gt;            &lt;span style="color:#0000ff;"&gt;where&lt;/span&gt; hobt_id=resource_associated_entity_id)&lt;/pre&gt;

&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;direction:ltr;line-height:12pt;font-family:&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;text-align:left;"&gt;    &lt;span style="color:#0000ff;"&gt;END&lt;/span&gt;) &lt;span style="color:#0000ff;"&gt;as&lt;/span&gt; objname,&lt;/pre&gt;

&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;direction:ltr;line-height:12pt;font-family:&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;text-align:left;"&gt;resource_description,&lt;/pre&gt;

&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;direction:ltr;line-height:12pt;font-family:&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;text-align:left;"&gt;request_mode,&lt;/pre&gt;

&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;direction:ltr;line-height:12pt;font-family:&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;text-align:left;"&gt;request_status&lt;/pre&gt;

&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;direction:ltr;line-height:12pt;font-family:&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;text-align:left;"&gt;&lt;span style="color:#0000ff;"&gt;from&lt;/span&gt; sys.dm_tran_locks&lt;/pre&gt;

&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;direction:ltr;line-height:12pt;font-family:&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;text-align:left;"&gt;&amp;nbsp;&lt;/pre&gt;

&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;direction:ltr;line-height:12pt;font-family:&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;text-align:left;"&gt;&amp;nbsp;&lt;/pre&gt;

&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;direction:ltr;line-height:12pt;font-family:&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;text-align:left;"&gt;--&lt;span style="color:#0000ff;"&gt;Rollback&lt;/span&gt; tran&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;So if you going to run this query batch you will see lock acquire by&amp;nbsp; &amp;ldquo;#LOCALTEST&amp;rdquo; not by @LOCALTEST so yes that true that Table Variables takes less locking then temporary tables.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;for logging purpose just populate temp Table and Table Variable with same data as shown above and now use fn_dblog(Un Documented) to see what happen like this..&lt;/p&gt;
&lt;p&gt;So here is a way to find logging &lt;/p&gt;
&lt;p&gt;First of all see logging for Table Variables&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;div id="codeSnippetWrapper"&gt;
&lt;div id="codeSnippet" style="border-style:none;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;direction:ltr;line-height:12pt;font-family:&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;text-align:left;"&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;direction:ltr;line-height:12pt;font-family:&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;text-align:left;"&gt;&lt;span style="color:#008000;"&gt;-- Table Variable&lt;/span&gt;&lt;/pre&gt;

&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;direction:ltr;line-height:12pt;font-family:&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;text-align:left;"&gt;&amp;nbsp;&lt;/pre&gt;

&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;direction:ltr;line-height:12pt;font-family:&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;text-align:left;"&gt;&lt;span style="color:#0000ff;"&gt;DECLARE&lt;/span&gt; @LOCALTEST &lt;span style="color:#0000ff;"&gt;TABLE&lt;/span&gt;(C1 &lt;span style="color:#0000ff;"&gt;INT&lt;/span&gt;, C2 &lt;span style="color:#0000ff;"&gt;VARCHAR&lt;/span&gt;(100))&lt;/pre&gt;

&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;direction:ltr;line-height:12pt;font-family:&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;text-align:left;"&gt;    INSERT &lt;span style="color:#0000ff;"&gt;INTO&lt;/span&gt; @LOCALTEST(C1,C2) &lt;/pre&gt;

&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;direction:ltr;line-height:12pt;font-family:&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;text-align:left;"&gt;    &lt;span style="color:#0000ff;"&gt;SELECT&lt;/span&gt; A,B &lt;span style="color:#0000ff;"&gt;FROM&lt;/span&gt; DUMMYDATA&lt;/pre&gt;

&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;direction:ltr;line-height:12pt;font-family:&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;text-align:left;"&gt;&amp;nbsp;&lt;/pre&gt;

&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;direction:ltr;line-height:12pt;font-family:&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;text-align:left;"&gt;&lt;span style="color:#008000;"&gt;-- update all the rows&lt;/span&gt;&lt;/pre&gt;

&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;direction:ltr;line-height:12pt;font-family:&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;text-align:left;"&gt;&lt;span style="color:#0000ff;"&gt;update&lt;/span&gt; @LOCALTEST &lt;span style="color:#0000ff;"&gt;set&lt;/span&gt; C2 = replicate (&lt;span style="color:#006080;"&gt;&amp;#39;AB&amp;#39;&lt;/span&gt;, 50)&lt;/pre&gt;

&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;direction:ltr;line-height:12pt;font-family:&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;text-align:left;"&gt;&amp;nbsp;&lt;/pre&gt;

&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;direction:ltr;line-height:12pt;font-family:&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;text-align:left;"&gt;&lt;span style="color:#008000;"&gt;-- Look at the top 10 log records.&lt;/span&gt;&lt;/pre&gt;

&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;direction:ltr;line-height:12pt;font-family:&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;text-align:left;"&gt;&lt;span style="color:#0000ff;"&gt;select&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;top&lt;/span&gt; 10 &lt;span style="color:#0000ff;"&gt;operation&lt;/span&gt;, AllocUnitName&lt;/pre&gt;

&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;direction:ltr;line-height:12pt;font-family:&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;text-align:left;"&gt;&lt;span style="color:#0000ff;"&gt;from&lt;/span&gt; fn_dblog(&lt;span style="color:#0000ff;"&gt;null&lt;/span&gt;, &lt;span style="color:#0000ff;"&gt;null&lt;/span&gt;)&lt;/pre&gt;

&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;direction:ltr;line-height:12pt;font-family:&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;text-align:left;"&gt;&lt;span style="color:#0000ff;"&gt;where&lt;/span&gt; AllocUnitName &lt;span style="color:#0000ff;"&gt;like&lt;/span&gt; &lt;span style="color:#006080;"&gt;&amp;#39;%LOCALTEST%&amp;#39;&lt;/span&gt;&lt;/pre&gt;

&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;direction:ltr;line-height:12pt;font-family:&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;text-align:left;"&gt;&lt;span style="color:#0000ff;"&gt;order&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;by&lt;/span&gt; [Log Record Length] &lt;span style="color:#0000ff;"&gt;Desc&lt;/span&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;For this i don&amp;rsquo;t get any records of update log in this and try same for Temporary Tables you will get update logs in this..&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;div id="codeSnippetWrapper"&gt;
&lt;div id="codeSnippet" style="border-style:none;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;direction:ltr;line-height:12pt;font-family:&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;text-align:left;"&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;direction:ltr;line-height:12pt;font-family:&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;text-align:left;"&gt;&lt;span style="color:#008000;"&gt;-- Temp Table&lt;/span&gt;&lt;/pre&gt;

&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;direction:ltr;line-height:12pt;font-family:&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;text-align:left;"&gt;&amp;nbsp;&lt;/pre&gt;

&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;direction:ltr;line-height:12pt;font-family:&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;text-align:left;"&gt;--&lt;span style="color:#0000ff;"&gt;drop&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;table&lt;/span&gt; #localtest&lt;/pre&gt;

&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;direction:ltr;line-height:12pt;font-family:&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;text-align:left;"&gt;&lt;span style="color:#0000ff;"&gt;CREATE&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;TABLE&lt;/span&gt; #LOCALTEST(C1 &lt;span style="color:#0000ff;"&gt;INT&lt;/span&gt;, C2 &lt;span style="color:#0000ff;"&gt;VARCHAR&lt;/span&gt;(100))&lt;/pre&gt;

&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;direction:ltr;line-height:12pt;font-family:&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;text-align:left;"&gt;&lt;span style="color:#0000ff;"&gt;GO&lt;/span&gt;&lt;/pre&gt;

&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;direction:ltr;line-height:12pt;font-family:&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;text-align:left;"&gt;&amp;nbsp;&lt;/pre&gt;

&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;direction:ltr;line-height:12pt;font-family:&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;text-align:left;"&gt;    INSERT &lt;span style="color:#0000ff;"&gt;INTO&lt;/span&gt; #LOCALTEST(C1,C2) &lt;/pre&gt;

&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;direction:ltr;line-height:12pt;font-family:&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;text-align:left;"&gt;    &lt;span style="color:#0000ff;"&gt;SELECT&lt;/span&gt; A,B &lt;span style="color:#0000ff;"&gt;FROM&lt;/span&gt; DUMMYDATA&lt;/pre&gt;

&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;direction:ltr;line-height:12pt;font-family:&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;text-align:left;"&gt;&amp;nbsp;&lt;/pre&gt;

&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;direction:ltr;line-height:12pt;font-family:&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;text-align:left;"&gt;&lt;span style="color:#008000;"&gt;-- update all the rows&lt;/span&gt;&lt;/pre&gt;

&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;direction:ltr;line-height:12pt;font-family:&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;text-align:left;"&gt;&lt;span style="color:#0000ff;"&gt;update&lt;/span&gt; #LOCALTEST &lt;span style="color:#0000ff;"&gt;set&lt;/span&gt; C2 = replicate (&lt;span style="color:#006080;"&gt;&amp;#39;ab&amp;#39;&lt;/span&gt;, 50)&lt;/pre&gt;

&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;direction:ltr;line-height:12pt;font-family:&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;text-align:left;"&gt;&amp;nbsp;&lt;/pre&gt;

&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;direction:ltr;line-height:12pt;font-family:&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;text-align:left;"&gt;&lt;span style="color:#008000;"&gt;-- Look at the log records. Here you get log records for update&lt;/span&gt;&lt;/pre&gt;

&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;direction:ltr;line-height:12pt;font-family:&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;text-align:left;"&gt;&lt;span style="color:#0000ff;"&gt;select&lt;/span&gt;  &lt;span style="color:#0000ff;"&gt;operation&lt;/span&gt;,AllocUnitName&lt;/pre&gt;

&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;direction:ltr;line-height:12pt;font-family:&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;text-align:left;"&gt;&lt;span style="color:#0000ff;"&gt;from&lt;/span&gt; fn_dblog(&lt;span style="color:#0000ff;"&gt;null&lt;/span&gt;, &lt;span style="color:#0000ff;"&gt;null&lt;/span&gt;)&lt;/pre&gt;

&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;direction:ltr;line-height:12pt;font-family:&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;text-align:left;"&gt;&lt;span style="color:#0000ff;"&gt;where&lt;/span&gt; AllocUnitName &lt;span style="color:#0000ff;"&gt;like&lt;/span&gt; &lt;span style="color:#006080;"&gt;&amp;#39;%LOCALTEST%&amp;#39;&lt;/span&gt;&lt;/pre&gt;

&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;direction:ltr;line-height:12pt;font-family:&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;text-align:left;"&gt;&lt;span style="color:#0000ff;"&gt;order&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;by&lt;/span&gt; [Log Record Length] Desc&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;And at last about the performance and IO usage for temporary table and table variables i use that example so the values vary for user to user so you can try the same on your systems and see what results you have with this&amp;hellip;i am still working on this and as soon as possible i will be back with some results valid and good results to this till then you can try this at your end&amp;hellip;&lt;/p&gt;
&lt;div id="codeSnippetWrapper"&gt;
&lt;div id="codeSnippet" style="border-style:none;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;direction:ltr;line-height:12pt;font-family:&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;text-align:left;"&gt;
&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;direction:ltr;line-height:12pt;font-family:&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;text-align:left;"&gt;&lt;span style="color:#0000ff;"&gt;USE&lt;/span&gt; AdventureWorks&lt;/pre&gt;

&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;direction:ltr;line-height:12pt;font-family:&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;text-align:left;"&gt;&amp;nbsp;&lt;/pre&gt;

&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;direction:ltr;line-height:12pt;font-family:&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;text-align:left;"&gt;---------------------------------------------------------------------&lt;span style="color:#008000;"&gt;--&lt;/span&gt;&lt;/pre&gt;

&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;direction:ltr;line-height:12pt;font-family:&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;text-align:left;"&gt;&lt;span style="color:#0000ff;"&gt;DECLARE&lt;/span&gt; @TEMP &lt;span style="color:#0000ff;"&gt;TABLE&lt;/span&gt;&lt;/pre&gt;

&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;direction:ltr;line-height:12pt;font-family:&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;text-align:left;"&gt;(ADDRESSID &lt;span style="color:#0000ff;"&gt;INT&lt;/span&gt; ,ADDRESSLINE1 &lt;span style="color:#0000ff;"&gt;VARCHAR&lt;/span&gt;(100)&lt;/pre&gt;

&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;direction:ltr;line-height:12pt;font-family:&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;text-align:left;"&gt;,ADDRESSLINE2 &lt;span style="color:#0000ff;"&gt;VARCHAR&lt;/span&gt;(100),CITY &lt;span style="color:#0000ff;"&gt;VARCHAR&lt;/span&gt;(30),StateProvinceID &lt;span style="color:#0000ff;"&gt;INT&lt;/span&gt;)&lt;/pre&gt;

&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;direction:ltr;line-height:12pt;font-family:&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;text-align:left;"&gt;&amp;nbsp;&lt;/pre&gt;

&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;direction:ltr;line-height:12pt;font-family:&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;text-align:left;"&gt;INSERT &lt;span style="color:#0000ff;"&gt;INTO&lt;/span&gt; @TEMP (ADDRESSID,ADDRESSLINE1,ADDRESSLINE2,CITY,StateProvinceID)&lt;/pre&gt;

&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;direction:ltr;line-height:12pt;font-family:&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;text-align:left;"&gt;&lt;span style="color:#0000ff;"&gt;SELECT&lt;/span&gt;  &lt;span style="color:#0000ff;"&gt;TOP&lt;/span&gt; 100 ADDRESSID,ADDRESSLINE1&lt;/pre&gt;

&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;direction:ltr;line-height:12pt;font-family:&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;text-align:left;"&gt;,ADDRESSLINE2,CITY,StateProvinceID  &lt;span style="color:#0000ff;"&gt;FROM&lt;/span&gt; PERSON.ADDRESS&lt;/pre&gt;

&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;direction:ltr;line-height:12pt;font-family:&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;text-align:left;"&gt;&amp;nbsp;&lt;/pre&gt;

&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;direction:ltr;line-height:12pt;font-family:&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;text-align:left;"&gt;--&lt;span style="color:#0000ff;"&gt;SELECT&lt;/span&gt; * &lt;span style="color:#0000ff;"&gt;FROM&lt;/span&gt; @TEMP&lt;/pre&gt;

&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;direction:ltr;line-height:12pt;font-family:&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;text-align:left;"&gt;&lt;span style="color:#0000ff;"&gt;SET&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;STATISTICS&lt;/span&gt; IO &lt;span style="color:#0000ff;"&gt;ON&lt;/span&gt;&lt;/pre&gt;

&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;direction:ltr;line-height:12pt;font-family:&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;text-align:left;"&gt;&lt;span style="color:#0000ff;"&gt;SET&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;STATISTICS&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;TIME&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;ON&lt;/span&gt;&lt;/pre&gt;

&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;direction:ltr;line-height:12pt;font-family:&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;text-align:left;"&gt;&amp;nbsp;&lt;/pre&gt;

&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;direction:ltr;line-height:12pt;font-family:&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;text-align:left;"&gt;&lt;span style="color:#0000ff;"&gt;SELECT&lt;/span&gt; a.*&lt;/pre&gt;

&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;direction:ltr;line-height:12pt;font-family:&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;text-align:left;"&gt;&lt;span style="color:#0000ff;"&gt;FROM&lt;/span&gt; @TEMP A &lt;span style="color:#0000ff;"&gt;INNER&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;JOIN&lt;/span&gt; PERSON.STATEPROVINCE B &lt;/pre&gt;

&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;direction:ltr;line-height:12pt;font-family:&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;text-align:left;"&gt;&lt;span style="color:#0000ff;"&gt;ON&lt;/span&gt; A.StateProvinceID=B.StateProvinceID&lt;/pre&gt;

&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;direction:ltr;line-height:12pt;font-family:&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;text-align:left;"&gt;&amp;nbsp;&lt;/pre&gt;

&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;direction:ltr;line-height:12pt;font-family:&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;text-align:left;"&gt;&lt;span style="color:#0000ff;"&gt;SET&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;STATISTICS&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;TIME&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;OFF&lt;/span&gt;&lt;/pre&gt;

&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;direction:ltr;line-height:12pt;font-family:&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;text-align:left;"&gt;&lt;span style="color:#0000ff;"&gt;SET&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;STATISTICS&lt;/span&gt; IO &lt;span style="color:#0000ff;"&gt;OFF&lt;/span&gt;&lt;/pre&gt;

&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;direction:ltr;line-height:12pt;font-family:&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;text-align:left;"&gt;&amp;nbsp;&lt;/pre&gt;

&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;direction:ltr;line-height:12pt;font-family:&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;text-align:left;"&gt;&amp;nbsp;&lt;/pre&gt;

&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;direction:ltr;line-height:12pt;font-family:&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;text-align:left;"&gt;-------------------------------------------------------------------------------------------&lt;span style="color:#008000;"&gt;--&lt;/span&gt;&lt;/pre&gt;

&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;direction:ltr;line-height:12pt;font-family:&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;text-align:left;"&gt;&lt;span style="color:#0000ff;"&gt;CREATE&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;TABLE&lt;/span&gt; #TEMP(ADDRESSID &lt;span style="color:#0000ff;"&gt;INT&lt;/span&gt; ,ADDRESSLINE1 &lt;span style="color:#0000ff;"&gt;VARCHAR&lt;/span&gt;(100)&lt;/pre&gt;

&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;direction:ltr;line-height:12pt;font-family:&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;text-align:left;"&gt;,ADDRESSLINE2 &lt;span style="color:#0000ff;"&gt;VARCHAR&lt;/span&gt;(100),CITY &lt;span style="color:#0000ff;"&gt;VARCHAR&lt;/span&gt;(30),StateProvinceID &lt;span style="color:#0000ff;"&gt;INT&lt;/span&gt;)&lt;/pre&gt;

&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;direction:ltr;line-height:12pt;font-family:&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;text-align:left;"&gt;&amp;nbsp;&lt;/pre&gt;

&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;direction:ltr;line-height:12pt;font-family:&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;text-align:left;"&gt;INSERT &lt;span style="color:#0000ff;"&gt;INTO&lt;/span&gt; #TEMP (ADDRESSID,ADDRESSLINE1,ADDRESSLINE2,CITY,StateProvinceID)&lt;/pre&gt;

&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;direction:ltr;line-height:12pt;font-family:&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;text-align:left;"&gt;&lt;span style="color:#0000ff;"&gt;SELECT&lt;/span&gt;  &lt;span style="color:#0000ff;"&gt;TOP&lt;/span&gt; 100 ADDRESSID,ADDRESSLINE1&lt;/pre&gt;

&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;direction:ltr;line-height:12pt;font-family:&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;text-align:left;"&gt;,ADDRESSLINE2,CITY,StateProvinceID  &lt;span style="color:#0000ff;"&gt;FROM&lt;/span&gt; PERSON.ADDRESS&lt;/pre&gt;

&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;direction:ltr;line-height:12pt;font-family:&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;text-align:left;"&gt;&amp;nbsp;&lt;/pre&gt;

&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;direction:ltr;line-height:12pt;font-family:&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;text-align:left;"&gt;--&lt;span style="color:#0000ff;"&gt;SELECT&lt;/span&gt; * &lt;span style="color:#0000ff;"&gt;FROM&lt;/span&gt; @TEMP&lt;/pre&gt;

&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;direction:ltr;line-height:12pt;font-family:&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;text-align:left;"&gt;&lt;span style="color:#0000ff;"&gt;SET&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;STATISTICS&lt;/span&gt; IO &lt;span style="color:#0000ff;"&gt;ON&lt;/span&gt;&lt;/pre&gt;

&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;direction:ltr;line-height:12pt;font-family:&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;text-align:left;"&gt;&lt;span style="color:#0000ff;"&gt;SET&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;STATISTICS&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;TIME&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;ON&lt;/span&gt;&lt;/pre&gt;

&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;direction:ltr;line-height:12pt;font-family:&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;text-align:left;"&gt;&amp;nbsp;&lt;/pre&gt;

&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;direction:ltr;line-height:12pt;font-family:&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;text-align:left;"&gt;&lt;span style="color:#0000ff;"&gt;SELECT&lt;/span&gt; a.*&lt;/pre&gt;

&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;direction:ltr;line-height:12pt;font-family:&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;text-align:left;"&gt;&lt;span style="color:#0000ff;"&gt;FROM&lt;/span&gt; #TEMP A &lt;span style="color:#0000ff;"&gt;INNER&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;JOIN&lt;/span&gt; PERSON.STATEPROVINCE B &lt;/pre&gt;

&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;direction:ltr;line-height:12pt;font-family:&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;text-align:left;"&gt;&lt;span style="color:#0000ff;"&gt;ON&lt;/span&gt; A.StateProvinceID=B.StateProvinceID&lt;/pre&gt;

&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;direction:ltr;line-height:12pt;font-family:&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;text-align:left;"&gt;&amp;nbsp;&lt;/pre&gt;

&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;direction:ltr;line-height:12pt;font-family:&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;text-align:left;"&gt;&lt;span style="color:#0000ff;"&gt;SET&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;STATISTICS&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;TIME&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;OFF&lt;/span&gt;&lt;/pre&gt;

&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;direction:ltr;line-height:12pt;font-family:&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;text-align:left;"&gt;&lt;span style="color:#0000ff;"&gt;SET&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;STATISTICS&lt;/span&gt; IO &lt;span style="color:#0000ff;"&gt;OFF&lt;/span&gt;&lt;/pre&gt;

&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;direction:ltr;line-height:12pt;font-family:&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;text-align:left;"&gt; &lt;/pre&gt;

&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;direction:ltr;line-height:12pt;font-family:&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;text-align:left;"&gt;&lt;span style="color:#0000ff;"&gt;DROP&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;TABLE&lt;/span&gt; #TEMP&lt;/pre&gt;

&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;direction:ltr;line-height:12pt;font-family:&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;text-align:left;"&gt;&amp;nbsp;&lt;/pre&gt;

&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;direction:ltr;line-height:12pt;font-family:&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:white;text-align:left;"&gt;&amp;nbsp;&lt;/pre&gt;

&lt;pre style="border-style:none;margin:0em;padding:0px;overflow:visible;font-size:8pt;width:100%;color:black;direction:ltr;line-height:12pt;font-family:&amp;#39;Courier New&amp;#39;,courier,monospace;background-color:#f4f4f4;text-align:left;"&gt;----------------------------------------------------------------&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;There are some more things like You can&amp;rsquo;t Alter Table Variable definition no DDL is applied on Table Variables and no statistics is maintained on table variable and statistics are used by query optimizer so there is a performance issue with this.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;So after that experiments i think that this is totally depends on the developer that what he wants to use and what are the requirements. i will made a follow up post on this topic again as i may miss many of things on this vast topic so i really appreciate your suggestions and reviews on this if you found anything which i miss or wrong in this then drop a comment here we will try to make it clear as soon as possible and soon as i got more information about this i will write a follow up post soon.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Thanks&lt;/p&gt;
&lt;div id="codeSnippetWrapper"&gt;&amp;nbsp;&lt;/div&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;div id="codeSnippetWrapper"&gt;&lt;/div&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://beyondrelational.com/aggbug.aspx?PostID=595" width="1" height="1"&gt;&lt;img src="http://feeds.feedburner.com/~r/AshishsBlog/~4/7DsQfpFraLA" height="1" width="1"/&gt;</description><category domain="http://beyondrelational.com/blogs/ashish/archive/tags/T-SQL/default.aspx">T-SQL</category><category domain="http://beyondrelational.com/blogs/ashish/archive/tags/SQL-Server/default.aspx">SQL-Server</category><category domain="http://beyondrelational.com/blogs/ashish/archive/tags/Technology/default.aspx">Technology</category><category domain="http://beyondrelational.com/blogs/ashish/archive/tags/Table-variable/default.aspx">Table-variable</category><category domain="http://beyondrelational.com/blogs/ashish/archive/tags/TempDb/default.aspx">TempDb</category><category domain="http://beyondrelational.com/blogs/ashish/archive/tags/Temporary-Table/default.aspx">Temporary-Table</category><feedburner:origLink>http://beyondrelational.com/blogs/ashish/archive/2009/07/31/temporary-tables-and-table-variables.aspx</feedburner:origLink></item><item><title>BackUp Status Script</title><link>http://feedproxy.google.com/~r/AshishsBlog/~3/XslNRg3XVSA/backup-status-script.aspx</link><pubDate>Wed, 22 Jul 2009 19:17:00 GMT</pubDate><guid isPermaLink="false">6e5011fa-7db5-4df3-bb79-9085c1d333b3:579</guid><dc:creator>Ashish Gilhotra</dc:creator><slash:comments>0</slash:comments><wfw:commentRss>http://beyondrelational.com/blogs/ashish/rsscomments.aspx?PostID=579</wfw:commentRss><comments>http://beyondrelational.com/blogs/ashish/archive/2009/07/22/backup-status-script.aspx#comments</comments><description>&lt;p&gt;This time its all about a script a backup script.Today early morning i asked to get BackUp details for some of DB&amp;rsquo;s we have, usually they ask me about the last BackUp taken so its easy for me to tell him. But this time he needs all the history of BackUp&amp;rsquo;s for some reason.So i know that iformation is stored somewhere is System databases so started goggling for it&amp;nbsp; and i found it on mssqltips.com and the script is written by &lt;a target="_blank" href="http://thomaslarock.com/"&gt;Thomas LaRock&lt;/a&gt;(aka SQLRockStar) and i modified this script according to my use by taking his prior permission i modified his script and add the details about the restoration of BackUp&amp;rsquo;s and location of BackUp&amp;rsquo;s basically i added information about the Restorations of BackUp&amp;rsquo;s, so here is my modified script about BackUp status which returns some very useful information about BackUp&amp;rsquo;s and restore.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;div id="codeSnippetWrapper"&gt;
&lt;div style="font-size:8pt;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:&amp;#39;Courier New&amp;#39;, courier, monospace;background-color:#f4f4f4;text-align:left;border-style:none;padding:0px;" id="codeSnippet"&gt;
&lt;pre style="font-size:8pt;margin:0em;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:&amp;#39;Courier New&amp;#39;, courier, monospace;background-color:white;text-align:left;border-style:none;padding:0px;"&gt;&lt;span style="color:#008000;"&gt;-- Script Returns BackUp Status and corresponding Restore Status for all Databases BackUps&lt;/span&gt;&lt;/pre&gt;

&lt;pre style="font-size:8pt;margin:0em;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:&amp;#39;Courier New&amp;#39;, courier, monospace;background-color:#f4f4f4;text-align:left;border-style:none;padding:0px;"&gt; &lt;/pre&gt;

&lt;pre style="font-size:8pt;margin:0em;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:&amp;#39;Courier New&amp;#39;, courier, monospace;background-color:white;text-align:left;border-style:none;padding:0px;"&gt;&lt;span style="color:#0000ff;"&gt;DECLARE&lt;/span&gt; @DBNAME &lt;span style="color:#0000ff;"&gt;VARCHAR&lt;/span&gt;(100)&lt;/pre&gt;

&lt;pre style="font-size:8pt;margin:0em;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:&amp;#39;Courier New&amp;#39;, courier, monospace;background-color:#f4f4f4;text-align:left;border-style:none;padding:0px;"&gt;&lt;span style="color:#0000ff;"&gt;SET&lt;/span&gt; @DBNAME=&lt;span style="color:#0000ff;"&gt;NULL&lt;/span&gt;  &lt;span style="color:#008000;"&gt;-- Default NULL(All Databses)&lt;/span&gt;&lt;/pre&gt;

&lt;pre style="font-size:8pt;margin:0em;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:&amp;#39;Courier New&amp;#39;, courier, monospace;background-color:white;text-align:left;border-style:none;padding:0px;"&gt;&lt;span style="color:#0000ff;"&gt;select&lt;/span&gt; &lt;span style="color:#006080;"&gt;&amp;#39;BackUp Name&amp;#39;&lt;/span&gt;=BS.name,&lt;/pre&gt;

&lt;pre style="font-size:8pt;margin:0em;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:&amp;#39;Courier New&amp;#39;, courier, monospace;background-color:#f4f4f4;text-align:left;border-style:none;padding:0px;"&gt;&lt;span style="color:#006080;"&gt;&amp;#39;User Name&amp;#39;&lt;/span&gt;=BS.user_name,&lt;/pre&gt;

&lt;pre style="font-size:8pt;margin:0em;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:&amp;#39;Courier New&amp;#39;, courier, monospace;background-color:white;text-align:left;border-style:none;padding:0px;"&gt;&lt;span style="color:#006080;"&gt;&amp;#39;Start Date&amp;#39;&lt;/span&gt;=BS.backup_start_date,&lt;/pre&gt;

&lt;pre style="font-size:8pt;margin:0em;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:&amp;#39;Courier New&amp;#39;, courier, monospace;background-color:#f4f4f4;text-align:left;border-style:none;padding:0px;"&gt;&lt;span style="color:#006080;"&gt;&amp;#39;Finish Date&amp;#39;&lt;/span&gt;=BS.backup_finish_date,&lt;/pre&gt;

&lt;pre style="font-size:8pt;margin:0em;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:&amp;#39;Courier New&amp;#39;, courier, monospace;background-color:white;text-align:left;border-style:none;padding:0px;"&gt;&lt;span style="color:#006080;"&gt;&amp;#39;Backup Type&amp;#39;&lt;/span&gt;=&lt;span style="color:#0000ff;"&gt;Case&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;when&lt;/span&gt; BS.type=&lt;span style="color:#006080;"&gt;&amp;#39;D&amp;#39;&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;then&lt;/span&gt; &lt;span style="color:#006080;"&gt;&amp;#39;FULL Backup&amp;#39;&lt;/span&gt;&lt;/pre&gt;

&lt;pre style="font-size:8pt;margin:0em;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:&amp;#39;Courier New&amp;#39;, courier, monospace;background-color:#f4f4f4;text-align:left;border-style:none;padding:0px;"&gt;              &lt;span style="color:#0000ff;"&gt;when&lt;/span&gt; BS.type=&lt;span style="color:#006080;"&gt;&amp;#39;L&amp;#39;&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;then&lt;/span&gt; &lt;span style="color:#006080;"&gt;&amp;#39;Transaction Log Backup&amp;#39;&lt;/span&gt;&lt;/pre&gt;

&lt;pre style="font-size:8pt;margin:0em;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:&amp;#39;Courier New&amp;#39;, courier, monospace;background-color:white;text-align:left;border-style:none;padding:0px;"&gt;              &lt;span style="color:#0000ff;"&gt;when&lt;/span&gt; BS.type=&lt;span style="color:#006080;"&gt;&amp;#39;I&amp;#39;&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;then&lt;/span&gt; &lt;span style="color:#006080;"&gt;&amp;#39;Differential Backup&amp;#39;&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;end&lt;/span&gt;&lt;/pre&gt;

&lt;pre style="font-size:8pt;margin:0em;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:&amp;#39;Courier New&amp;#39;, courier, monospace;background-color:#f4f4f4;text-align:left;border-style:none;padding:0px;"&gt;,&lt;span style="color:#006080;"&gt;&amp;#39;Backup Size MB&amp;#39;&lt;/span&gt;=floor(((BS.backup_size/1024)/1024))&lt;/pre&gt;

&lt;pre style="font-size:8pt;margin:0em;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:&amp;#39;Courier New&amp;#39;, courier, monospace;background-color:white;text-align:left;border-style:none;padding:0px;"&gt;,&lt;span style="color:#006080;"&gt;&amp;#39;DbName&amp;#39;&lt;/span&gt;=BS.database_name&lt;/pre&gt;

&lt;pre style="font-size:8pt;margin:0em;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:&amp;#39;Courier New&amp;#39;, courier, monospace;background-color:#f4f4f4;text-align:left;border-style:none;padding:0px;"&gt;,&lt;span style="color:#006080;"&gt;&amp;#39;Server Name&amp;#39;&lt;/span&gt;=BS.server_name&lt;/pre&gt;

&lt;pre style="font-size:8pt;margin:0em;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:&amp;#39;Courier New&amp;#39;, courier, monospace;background-color:white;text-align:left;border-style:none;padding:0px;"&gt;,MF.physical_device_name&lt;/pre&gt;

&lt;pre style="font-size:8pt;margin:0em;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:&amp;#39;Courier New&amp;#39;, courier, monospace;background-color:#f4f4f4;text-align:left;border-style:none;padding:0px;"&gt;,&lt;span style="color:#006080;"&gt;&amp;#39;IS Ever Restored&amp;#39;&lt;/span&gt;=&lt;span style="color:#0000ff;"&gt;case&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;when&lt;/span&gt; BS.backup_set_id &lt;span style="color:#0000ff;"&gt;in&lt;/span&gt; &lt;/pre&gt;

&lt;pre style="font-size:8pt;margin:0em;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:&amp;#39;Courier New&amp;#39;, courier, monospace;background-color:white;text-align:left;border-style:none;padding:0px;"&gt;(&lt;span style="color:#0000ff;"&gt;select&lt;/span&gt; backup_set_id &lt;span style="color:#0000ff;"&gt;from&lt;/span&gt; msdb.dbo.restorehistory)&lt;/pre&gt;

&lt;pre style="font-size:8pt;margin:0em;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:&amp;#39;Courier New&amp;#39;, courier, monospace;background-color:#f4f4f4;text-align:left;border-style:none;padding:0px;"&gt; &lt;span style="color:#0000ff;"&gt;then&lt;/span&gt; &lt;span style="color:#006080;"&gt;&amp;#39;Yes&amp;#39;&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;else&lt;/span&gt; &lt;span style="color:#006080;"&gt;&amp;#39;No&amp;#39;&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;end&lt;/span&gt;&lt;/pre&gt;

&lt;pre style="font-size:8pt;margin:0em;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:&amp;#39;Courier New&amp;#39;, courier, monospace;background-color:white;text-align:left;border-style:none;padding:0px;"&gt;,&lt;span style="color:#006080;"&gt;&amp;#39;Destination Db&amp;#39;&lt;/span&gt;&lt;/pre&gt;

&lt;pre style="font-size:8pt;margin:0em;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:&amp;#39;Courier New&amp;#39;, courier, monospace;background-color:#f4f4f4;text-align:left;border-style:none;padding:0px;"&gt;=isnull(RH.destination_database_name,&lt;span style="color:#006080;"&gt;&amp;#39;Yet Not Restored From This BackUpSet&amp;#39;&lt;/span&gt;)&lt;/pre&gt;

&lt;pre style="font-size:8pt;margin:0em;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:&amp;#39;Courier New&amp;#39;, courier, monospace;background-color:white;text-align:left;border-style:none;padding:0px;"&gt;,&lt;span style="color:#006080;"&gt;&amp;#39;Restore Path&amp;#39;&lt;/span&gt;&lt;/pre&gt;

&lt;pre style="font-size:8pt;margin:0em;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:&amp;#39;Courier New&amp;#39;, courier, monospace;background-color:#f4f4f4;text-align:left;border-style:none;padding:0px;"&gt;=isnull(&lt;span style="color:#0000ff;"&gt;min&lt;/span&gt;(RF.destination_phys_name),&lt;span style="color:#006080;"&gt;&amp;#39;Yet Not Restored From This BackUpSet&amp;#39;&lt;/span&gt;)&lt;/pre&gt;

&lt;pre style="font-size:8pt;margin:0em;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:&amp;#39;Courier New&amp;#39;, courier, monospace;background-color:white;text-align:left;border-style:none;padding:0px;"&gt;,&lt;span style="color:#006080;"&gt;&amp;#39;restore Type&amp;#39;&lt;/span&gt;=isnull(&lt;span style="color:#0000ff;"&gt;CASE&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;WHEN&lt;/span&gt; RH.restore_type = &lt;span style="color:#006080;"&gt;&amp;#39;D&amp;#39;&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;THEN&lt;/span&gt; &lt;span style="color:#006080;"&gt;&amp;#39;Database&amp;#39;&lt;/span&gt;&lt;/pre&gt;

&lt;pre style="font-size:8pt;margin:0em;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:&amp;#39;Courier New&amp;#39;, courier, monospace;background-color:#f4f4f4;text-align:left;border-style:none;padding:0px;"&gt;              &lt;span style="color:#0000ff;"&gt;WHEN&lt;/span&gt; RH.restore_type = &lt;span style="color:#006080;"&gt;&amp;#39;F&amp;#39;&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;THEN&lt;/span&gt; &lt;span style="color:#006080;"&gt;&amp;#39;File&amp;#39;&lt;/span&gt;&lt;/pre&gt;

&lt;pre style="font-size:8pt;margin:0em;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:&amp;#39;Courier New&amp;#39;, courier, monospace;background-color:white;text-align:left;border-style:none;padding:0px;"&gt;              &lt;span style="color:#0000ff;"&gt;WHEN&lt;/span&gt; RH.restore_type = &lt;span style="color:#006080;"&gt;&amp;#39;G&amp;#39;&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;THEN&lt;/span&gt; &lt;span style="color:#006080;"&gt;&amp;#39;Filegroup&amp;#39;&lt;/span&gt;&lt;/pre&gt;

&lt;pre style="font-size:8pt;margin:0em;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:&amp;#39;Courier New&amp;#39;, courier, monospace;background-color:#f4f4f4;text-align:left;border-style:none;padding:0px;"&gt;              &lt;span style="color:#0000ff;"&gt;WHEN&lt;/span&gt; RH.restore_type = &lt;span style="color:#006080;"&gt;&amp;#39;I&amp;#39;&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;THEN&lt;/span&gt; &lt;span style="color:#006080;"&gt;&amp;#39;Differential&amp;#39;&lt;/span&gt;&lt;/pre&gt;

&lt;pre style="font-size:8pt;margin:0em;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:&amp;#39;Courier New&amp;#39;, courier, monospace;background-color:white;text-align:left;border-style:none;padding:0px;"&gt;              &lt;span style="color:#0000ff;"&gt;WHEN&lt;/span&gt; RH.restore_type = &lt;span style="color:#006080;"&gt;&amp;#39;L&amp;#39;&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;THEN&lt;/span&gt; &lt;span style="color:#006080;"&gt;&amp;#39;Log&amp;#39;&lt;/span&gt;&lt;/pre&gt;

&lt;pre style="font-size:8pt;margin:0em;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:&amp;#39;Courier New&amp;#39;, courier, monospace;background-color:#f4f4f4;text-align:left;border-style:none;padding:0px;"&gt;              &lt;span style="color:#0000ff;"&gt;WHEN&lt;/span&gt; RH.restore_type = &lt;span style="color:#006080;"&gt;&amp;#39;V&amp;#39;&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;THEN&lt;/span&gt; &lt;span style="color:#006080;"&gt;&amp;#39;Verifyonly&amp;#39;&lt;/span&gt;&lt;/pre&gt;

&lt;pre style="font-size:8pt;margin:0em;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:&amp;#39;Courier New&amp;#39;, courier, monospace;background-color:white;text-align:left;border-style:none;padding:0px;"&gt;              &lt;span style="color:#0000ff;"&gt;WHEN&lt;/span&gt; RH.restore_type = &lt;span style="color:#006080;"&gt;&amp;#39;R&amp;#39;&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;THEN&lt;/span&gt; &lt;span style="color:#006080;"&gt;&amp;#39;Revert&amp;#39;&lt;/span&gt;&lt;/pre&gt;

&lt;pre style="font-size:8pt;margin:0em;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:&amp;#39;Courier New&amp;#39;, courier, monospace;background-color:#f4f4f4;text-align:left;border-style:none;padding:0px;"&gt;              &lt;span style="color:#0000ff;"&gt;ELSE&lt;/span&gt; RH.restore_type &lt;/pre&gt;

&lt;pre style="font-size:8pt;margin:0em;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:&amp;#39;Courier New&amp;#39;, courier, monospace;background-color:white;text-align:left;border-style:none;padding:0px;"&gt;             &lt;span style="color:#0000ff;"&gt;END&lt;/span&gt; ,&lt;span style="color:#006080;"&gt;&amp;#39;Yet Not&amp;#39;&lt;/span&gt;)&lt;/pre&gt;

&lt;pre style="font-size:8pt;margin:0em;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:&amp;#39;Courier New&amp;#39;, courier, monospace;background-color:#f4f4f4;text-align:left;border-style:none;padding:0px;"&gt;,Rh.restore_date,&lt;span style="color:#006080;"&gt;&amp;#39;Restore By&amp;#39;&lt;/span&gt;=isnull(RH.user_name,&lt;span style="color:#006080;"&gt;&amp;#39;No One&amp;#39;&lt;/span&gt;)&lt;/pre&gt;

&lt;pre style="font-size:8pt;margin:0em;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:&amp;#39;Courier New&amp;#39;, courier, monospace;background-color:white;text-align:left;border-style:none;padding:0px;"&gt;,&lt;span style="color:#006080;"&gt;&amp;#39;Time Taken&amp;#39;&lt;/span&gt;&lt;/pre&gt;

&lt;pre style="font-size:8pt;margin:0em;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:&amp;#39;Courier New&amp;#39;, courier, monospace;background-color:#f4f4f4;text-align:left;border-style:none;padding:0px;"&gt;=&lt;span style="color:#0000ff;"&gt;cast&lt;/span&gt;(datediff(ss,BS.backup_start_date,BS.backup_finish_date)/3600 &lt;span style="color:#0000ff;"&gt;as&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;varchar&lt;/span&gt;(10))&lt;/pre&gt;

&lt;pre style="font-size:8pt;margin:0em;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:&amp;#39;Courier New&amp;#39;, courier, monospace;background-color:white;text-align:left;border-style:none;padding:0px;"&gt;+&lt;span style="color:#006080;"&gt;&amp;#39; Hours, &amp;#39;&lt;/span&gt; + &lt;/pre&gt;

&lt;pre style="font-size:8pt;margin:0em;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:&amp;#39;Courier New&amp;#39;, courier, monospace;background-color:#f4f4f4;text-align:left;border-style:none;padding:0px;"&gt;&lt;span style="color:#0000ff;"&gt;cast&lt;/span&gt;(datediff(ss,BS.backup_start_date,BS.backup_finish_date)/60 &lt;span style="color:#0000ff;"&gt;as&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;varchar&lt;/span&gt;(10))&lt;/pre&gt;

&lt;pre style="font-size:8pt;margin:0em;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:&amp;#39;Courier New&amp;#39;, courier, monospace;background-color:white;text-align:left;border-style:none;padding:0px;"&gt;+ &lt;span style="color:#006080;"&gt;&amp;#39; Minutes, &amp;#39;&lt;/span&gt; + &lt;/pre&gt;

&lt;pre style="font-size:8pt;margin:0em;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:&amp;#39;Courier New&amp;#39;, courier, monospace;background-color:#f4f4f4;text-align:left;border-style:none;padding:0px;"&gt;&lt;span style="color:#0000ff;"&gt;cast&lt;/span&gt;(datediff(ss,BS.backup_start_date,BS.backup_finish_date)%60 &lt;span style="color:#0000ff;"&gt;as&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;varchar&lt;/span&gt;(10)) &lt;/pre&gt;

&lt;pre style="font-size:8pt;margin:0em;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:&amp;#39;Courier New&amp;#39;, courier, monospace;background-color:white;text-align:left;border-style:none;padding:0px;"&gt;+&lt;span style="color:#006080;"&gt;&amp;#39; Seconds&amp;#39;&lt;/span&gt;&lt;/pre&gt;

&lt;pre style="font-size:8pt;margin:0em;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:&amp;#39;Courier New&amp;#39;, courier, monospace;background-color:#f4f4f4;text-align:left;border-style:none;padding:0px;"&gt;&lt;span style="color:#0000ff;"&gt;from&lt;/span&gt; msdb..backupset BS &lt;/pre&gt;

&lt;pre style="font-size:8pt;margin:0em;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:&amp;#39;Courier New&amp;#39;, courier, monospace;background-color:white;text-align:left;border-style:none;padding:0px;"&gt;&lt;span style="color:#0000ff;"&gt;JOIN&lt;/span&gt; msdb..backupmediafamily MF &lt;/pre&gt;

&lt;pre style="font-size:8pt;margin:0em;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:&amp;#39;Courier New&amp;#39;, courier, monospace;background-color:#f4f4f4;text-align:left;border-style:none;padding:0px;"&gt;&lt;span style="color:#0000ff;"&gt;on&lt;/span&gt; BS.media_set_id=MF.media_set_id&lt;/pre&gt;

&lt;pre style="font-size:8pt;margin:0em;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:&amp;#39;Courier New&amp;#39;, courier, monospace;background-color:white;text-align:left;border-style:none;padding:0px;"&gt;&lt;span style="color:#0000ff;"&gt;left&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;outer&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;join&lt;/span&gt; msdb..restorehistory RH &lt;/pre&gt;

&lt;pre style="font-size:8pt;margin:0em;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:&amp;#39;Courier New&amp;#39;, courier, monospace;background-color:#f4f4f4;text-align:left;border-style:none;padding:0px;"&gt;&lt;span style="color:#0000ff;"&gt;on&lt;/span&gt; BS.backup_set_id =RH.backup_set_id&lt;/pre&gt;

&lt;pre style="font-size:8pt;margin:0em;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:&amp;#39;Courier New&amp;#39;, courier, monospace;background-color:white;text-align:left;border-style:none;padding:0px;"&gt;&lt;span style="color:#0000ff;"&gt;left&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;outer&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;join&lt;/span&gt; msdb..restorefile RF &lt;/pre&gt;

&lt;pre style="font-size:8pt;margin:0em;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:&amp;#39;Courier New&amp;#39;, courier, monospace;background-color:#f4f4f4;text-align:left;border-style:none;padding:0px;"&gt;&lt;span style="color:#0000ff;"&gt;on&lt;/span&gt; RF.restore_history_id=Rh.restore_history_id&lt;/pre&gt;

&lt;pre style="font-size:8pt;margin:0em;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:&amp;#39;Courier New&amp;#39;, courier, monospace;background-color:white;text-align:left;border-style:none;padding:0px;"&gt;&lt;span style="color:#0000ff;"&gt;where&lt;/span&gt; BS.database_name = isnull(@DBNAME,BS.database_name)&lt;/pre&gt;

&lt;pre style="font-size:8pt;margin:0em;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:&amp;#39;Courier New&amp;#39;, courier, monospace;background-color:#f4f4f4;text-align:left;border-style:none;padding:0px;"&gt;&lt;span style="color:#0000ff;"&gt;group&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;by&lt;/span&gt; BS.name,BS.user_name,BS.backup_start_date,BS.backup_finish_date,&lt;/pre&gt;

&lt;pre style="font-size:8pt;margin:0em;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:&amp;#39;Courier New&amp;#39;, courier, monospace;background-color:white;text-align:left;border-style:none;padding:0px;"&gt;BS.TYPE,BS.backup_size,BS.database_name,BS.server_name&lt;/pre&gt;

&lt;pre style="font-size:8pt;margin:0em;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:&amp;#39;Courier New&amp;#39;, courier, monospace;background-color:#f4f4f4;text-align:left;border-style:none;padding:0px;"&gt;,MF.physical_device_name,BS.backup_set_id,RH.destination_database_name&lt;/pre&gt;

&lt;pre style="font-size:8pt;margin:0em;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:&amp;#39;Courier New&amp;#39;, courier, monospace;background-color:white;text-align:left;border-style:none;padding:0px;"&gt;,RH.restore_type,Rh.restore_date,RH.user_name&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Here this scripts take a Database name as parameter and is you don&amp;rsquo;t supply that parameter that by default it shoes information about all databases&lt;/p&gt;
&lt;p&gt;Here what this script returns :&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;BS_Name = Name of BackUp &lt;/li&gt;
&lt;li&gt;BS_UserName = Name of User from which BackUp had taken. &lt;/li&gt;
&lt;li&gt;backup_start_date = Start Date Time of BackUp &lt;/li&gt;
&lt;li&gt;backup_end_date = End Date Time of BackUp &lt;/li&gt;
&lt;li&gt;BackUp Type = Type of BackUp &lt;/li&gt;
&lt;li&gt;BackUp Size = Size of BackUp File &lt;/li&gt;
&lt;li&gt;Dbname = Name of database &lt;/li&gt;
&lt;li&gt;ServerName = Name of Server &lt;/li&gt;
&lt;li&gt;Physical_Device_Name = name of Drive or Device where backup stored &lt;/li&gt;
&lt;li&gt;Is Ever Restored = is BackUp Ever Restore(Yes/No) &lt;/li&gt;
&lt;li&gt;Destination Db = Name of Database Restored By BackUp &lt;/li&gt;
&lt;li&gt;Restore Path = Path from database restored &lt;/li&gt;
&lt;li&gt;Restore type = Type of restoration &lt;/li&gt;
&lt;li&gt;restore_date = Date when Database Restored &lt;/li&gt;
&lt;li&gt;restore by = User by which database in restored &lt;/li&gt;
&lt;li&gt;Time Taken = Total time taken to take Database BackUp &lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;So in this way this script return some useful information regarding BackUp&amp;rsquo;s and Restoration of backup&amp;rsquo;s its really make sense if you schedule this script to send through mail to get updates about your BackUp&amp;rsquo;s and Restore information so its really a good idea if we send this information in mail so in next blog post i will write how to send this information using 
  &lt;br /&gt;e-mail to direct in your inbox through Database nail in SQL Server.&lt;/p&gt;
&lt;p&gt;SO if you have any suggestions regarding this script and do let me now or if you found any other method then do post here any kind of suggestions are welcomed &lt;/p&gt;
&lt;p&gt;Thanks&amp;hellip;.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://beyondrelational.com/aggbug.aspx?PostID=579" width="1" height="1"&gt;&lt;img src="http://feeds.feedburner.com/~r/AshishsBlog/~4/XslNRg3XVSA" height="1" width="1"/&gt;</description><category domain="http://beyondrelational.com/blogs/ashish/archive/tags/T-SQL/default.aspx">T-SQL</category><category domain="http://beyondrelational.com/blogs/ashish/archive/tags/SQL-Server/default.aspx">SQL-Server</category><category domain="http://beyondrelational.com/blogs/ashish/archive/tags/Restore/default.aspx">Restore</category><category domain="http://beyondrelational.com/blogs/ashish/archive/tags/Script/default.aspx">Script</category><category domain="http://beyondrelational.com/blogs/ashish/archive/tags/BackUP/default.aspx">BackUP</category><feedburner:origLink>http://beyondrelational.com/blogs/ashish/archive/2009/07/22/backup-status-script.aspx</feedburner:origLink></item><item><title>T-SQL Challenges</title><link>http://feedproxy.google.com/~r/AshishsBlog/~3/SwIGzgUCbaA/t-sql-challenges.aspx</link><pubDate>Wed, 08 Jul 2009 09:05:00 GMT</pubDate><guid isPermaLink="false">6e5011fa-7db5-4df3-bb79-9085c1d333b3:543</guid><dc:creator>Ashish Gilhotra</dc:creator><slash:comments>0</slash:comments><wfw:commentRss>http://beyondrelational.com/blogs/ashish/rsscomments.aspx?PostID=543</wfw:commentRss><comments>http://beyondrelational.com/blogs/ashish/archive/2009/07/08/t-sql-challenges.aspx#comments</comments><description>&lt;p&gt;Hi All &amp;hellip;&lt;/p&gt;
&lt;p&gt;You all must here about &lt;a href="http://www.tsqlchallenges.com/" target="_blank"&gt;T-SQL Challenges&lt;/a&gt;, these challenges are ideal to learn Set Based Queries using TSql. The most beneficial part of these challenges is that, through these challenges , you get a chance to see better solution to solve a given problem, &amp;nbsp;T-SQL Challenges is mainly focused on writing Set Based Queries using T SQL. You can find previous challenges, winner of all challenges, and the best possible for all solutions by T SQL Challenges team as well as all the solutions provided by the winners with explanation of their solution&amp;rsquo;s &lt;a href="http://beyondrelational.com/blogs/tc/default.aspx"&gt;here&lt;/a&gt;&amp;nbsp;(ie &lt;a href="http://beyondrelational.com/blogs/tc/archive/2009/06/30/tsql-challenges-8-winners.aspx" target="_blank"&gt;TSQL Challenge #8&lt;/a&gt;)on &lt;a href="http://beyondrelational.com/blogs/tc/default.aspx"&gt;TSQL Challenges Blog&lt;/a&gt; at &lt;a href="http://beyondrelational.com/"&gt;beyondrelational.com&lt;/a&gt;&amp;nbsp;; and TSQL challenge team also provided a winning certificate for&amp;nbsp;&lt;span&gt;TSQL&amp;nbsp;&lt;/span&gt;&lt;span style="font-size:x-small;"&gt;C&lt;/span&gt;&lt;span&gt;hallenges winners.H&lt;/span&gt;ere is my certificate for my &lt;a href="http://beyondrelational.com/blogs/tc/archive/2009/04/23/tsql-challenge-1-answer-and-winners.aspx"&gt;winning entry&lt;/a&gt; of &lt;a href="http://beyondrelational.com/blogs/tc/archive/2009/02/27/tsql-challenge-1.aspx"&gt;TSQL Challenge #1&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;a href="http://beyondrelational.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/ashish/AshishGihotra_5F00_0C02B8FA.png"&gt;&lt;img title="Ashish Gihotra" style="border-right:0px;border-top:0px;display:inline;border-left:0px;border-bottom:0px;" height="287" alt="Ashish Gihotra" src="http://beyondrelational.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/ashish/AshishGihotra_5F00_thumb_5F00_74B6F2E1.png" width="438" border="0" /&gt;&lt;/a&gt; &lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;The most wonderful effort put in to these challenges by TSQL Team is that they provide a free training webcast for those peoples who interesting in challenges , but not able to solve it.The training webcast&amp;nbsp; helps us to write complex set based queries in simple manner and enhance our T SQL Set Based Quering Skills. So if you able to solve the challenge then send your entries else join the training webcast and learn how to write/solve challenges.&lt;/p&gt;
&lt;p&gt;So hope to see you all having fun solving these challenges.&lt;/p&gt;
&lt;p&gt;Thanks&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://beyondrelational.com/aggbug.aspx?PostID=543" width="1" height="1"&gt;&lt;img src="http://feeds.feedburner.com/~r/AshishsBlog/~4/SwIGzgUCbaA" height="1" width="1"/&gt;</description><category domain="http://beyondrelational.com/blogs/ashish/archive/tags/T-SQL/default.aspx">T-SQL</category><category domain="http://beyondrelational.com/blogs/ashish/archive/tags/SQL-Server/default.aspx">SQL-Server</category><category domain="http://beyondrelational.com/blogs/ashish/archive/tags/T-SQL-Challenges/default.aspx">T-SQL-Challenges</category><feedburner:origLink>http://beyondrelational.com/blogs/ashish/archive/2009/07/08/t-sql-challenges.aspx</feedburner:origLink></item><item><title>Who Created a Table – DDL Triggers in SQL SERVER 2008</title><link>http://feedproxy.google.com/~r/AshishsBlog/~3/grKtQ7ZdnII/who-create-a-table-ddl-triggers-in-sql-server-2008.aspx</link><pubDate>Tue, 30 Jun 2009 15:02:00 GMT</pubDate><guid isPermaLink="false">6e5011fa-7db5-4df3-bb79-9085c1d333b3:521</guid><dc:creator>Ashish Gilhotra</dc:creator><slash:comments>0</slash:comments><wfw:commentRss>http://beyondrelational.com/blogs/ashish/rsscomments.aspx?PostID=521</wfw:commentRss><comments>http://beyondrelational.com/blogs/ashish/archive/2009/06/30/who-create-a-table-ddl-triggers-in-sql-server-2008.aspx#comments</comments><description>Hi all this post is about the new features in SQL Server 2008 .. SQL Server 2008 has a power full feature called DDL triggers which uses for Auditing changes in database and this is very useful too. You will find a blog entry about auditing using transaction...(&lt;a href="http://beyondrelational.com/blogs/ashish/archive/2009/06/30/who-create-a-table-ddl-triggers-in-sql-server-2008.aspx"&gt;read more&lt;/a&gt;)&lt;img src="http://beyondrelational.com/aggbug.aspx?PostID=521" width="1" height="1"&gt;&lt;img src="http://feeds.feedburner.com/~r/AshishsBlog/~4/grKtQ7ZdnII" height="1" width="1"/&gt;</description><category domain="http://beyondrelational.com/blogs/ashish/archive/tags/T-SQL/default.aspx">T-SQL</category><category domain="http://beyondrelational.com/blogs/ashish/archive/tags/SQLServer-2008/default.aspx">SQLServer-2008</category><category domain="http://beyondrelational.com/blogs/ashish/archive/tags/Auditing/default.aspx">Auditing</category><category domain="http://beyondrelational.com/blogs/ashish/archive/tags/Triggers/default.aspx">Triggers</category><feedburner:origLink>http://beyondrelational.com/blogs/ashish/archive/2009/06/30/who-create-a-table-ddl-triggers-in-sql-server-2008.aspx</feedburner:origLink></item><item><title>Encryption &amp; Decryption Part II</title><link>http://feedproxy.google.com/~r/AshishsBlog/~3/MsPNKQ254QQ/encryption-amp-decryption-part-ii.aspx</link><pubDate>Mon, 29 Jun 2009 14:34:00 GMT</pubDate><guid isPermaLink="false">6e5011fa-7db5-4df3-bb79-9085c1d333b3:485</guid><dc:creator>Ashish Gilhotra</dc:creator><slash:comments>0</slash:comments><wfw:commentRss>http://beyondrelational.com/blogs/ashish/rsscomments.aspx?PostID=485</wfw:commentRss><comments>http://beyondrelational.com/blogs/ashish/archive/2009/06/29/encryption-amp-decryption-part-ii.aspx#comments</comments><description>Hi all me again here with a post about Encryption &amp;amp; Decryption in Sql Server 2005.I have received a couple of questions regarding my article Encryption &amp;amp; Decryption in Sql Server 2005 , so i started responding through mail but because i found...(&lt;a href="http://beyondrelational.com/blogs/ashish/archive/2009/06/29/encryption-amp-decryption-part-ii.aspx"&gt;read more&lt;/a&gt;)&lt;img src="http://beyondrelational.com/aggbug.aspx?PostID=485" width="1" height="1"&gt;&lt;img src="http://feeds.feedburner.com/~r/AshishsBlog/~4/MsPNKQ254QQ" height="1" width="1"/&gt;</description><category domain="http://beyondrelational.com/blogs/ashish/archive/tags/T-SQL/default.aspx">T-SQL</category><category domain="http://beyondrelational.com/blogs/ashish/archive/tags/SQLSERVER-2005/default.aspx">SQLSERVER-2005</category><category domain="http://beyondrelational.com/blogs/ashish/archive/tags/Decryption/default.aspx">Decryption</category><category domain="http://beyondrelational.com/blogs/ashish/archive/tags/Encryption/default.aspx">Encryption</category><feedburner:origLink>http://beyondrelational.com/blogs/ashish/archive/2009/06/29/encryption-amp-decryption-part-ii.aspx</feedburner:origLink></item><item><title>Sparse Columns – Introduction</title><link>http://feedproxy.google.com/~r/AshishsBlog/~3/sUKJENvwHXg/sparse-columns-introduction.aspx</link><pubDate>Thu, 11 Jun 2009 16:13:00 GMT</pubDate><guid isPermaLink="false">6e5011fa-7db5-4df3-bb79-9085c1d333b3:409</guid><dc:creator>Ashish Gilhotra</dc:creator><slash:comments>0</slash:comments><wfw:commentRss>http://beyondrelational.com/blogs/ashish/rsscomments.aspx?PostID=409</wfw:commentRss><comments>http://beyondrelational.com/blogs/ashish/archive/2009/06/11/sparse-columns-introduction.aspx#comments</comments><description>So after a long i get a chance to work on SQL Server 2008 and understand it in better way. So today we look into a new storage feature in SQL Server 2008 as Sparse Column. Sparse column takes no physical usage for a column which may have &amp;ldquo;NULL&amp;rdquo;...(&lt;a href="http://beyondrelational.com/blogs/ashish/archive/2009/06/11/sparse-columns-introduction.aspx"&gt;read more&lt;/a&gt;)&lt;img src="http://beyondrelational.com/aggbug.aspx?PostID=409" width="1" height="1"&gt;&lt;img src="http://feeds.feedburner.com/~r/AshishsBlog/~4/sUKJENvwHXg" height="1" width="1"/&gt;</description><category domain="http://beyondrelational.com/blogs/ashish/archive/tags/SQL-Server/default.aspx">SQL-Server</category><category domain="http://beyondrelational.com/blogs/ashish/archive/tags/SQLServer-2008/default.aspx">SQLServer-2008</category><category domain="http://beyondrelational.com/blogs/ashish/archive/tags/SparseColumns/default.aspx">SparseColumns</category><feedburner:origLink>http://beyondrelational.com/blogs/ashish/archive/2009/06/11/sparse-columns-introduction.aspx</feedburner:origLink></item><item><title>TechEd on Road – Ahmedabad June 20, 2009</title><link>http://feedproxy.google.com/~r/AshishsBlog/~3/E9sTPjcC6cw/teched-on-road-ahmedabad-june-20-2009.aspx</link><pubDate>Thu, 11 Jun 2009 07:46:00 GMT</pubDate><guid isPermaLink="false">6e5011fa-7db5-4df3-bb79-9085c1d333b3:412</guid><dc:creator>Ashish Gilhotra</dc:creator><slash:comments>0</slash:comments><wfw:commentRss>http://beyondrelational.com/blogs/ashish/rsscomments.aspx?PostID=412</wfw:commentRss><comments>http://beyondrelational.com/blogs/ashish/archive/2009/06/11/teched-on-road-ahmedabad-june-20-2009.aspx#comments</comments><description>&lt;p&gt;Hi all …&lt;/p&gt;  &lt;p&gt;This time a great news for all the technology enthusiast and want to meet great peoples in technology and you missed &lt;strong&gt;TechEd India 2009 &lt;/strong&gt;so you can attend now the same kind of event in &lt;strong&gt;Ahmedabad, India on June 20, 2009 Saturday(TechEd on Road) by 1:30 PM.&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;You will get a chance to meet Two MVP’S here &lt;a href="http://beyondrelational.com/blogs/jacob/default.aspx"&gt;Jacob Sebastian&lt;/a&gt; and &lt;a href="http://blog.sqlauthority.com/"&gt;Pinal Dave&lt;/a&gt; , who presents numerous technical sessions on SQL Server, Exchange Server 2010, Windows Server 2008 and Virtualization. &lt;/p&gt;  &lt;p&gt;Anyone who is interested in technology can attend this event .This is free event no charges will be taken to attend this event. You can get detailed information about this event on &lt;a href="http://blog.sqlauthority.com/2009/06/09/sqlauthority-news-teched-on-road-ahmedabad-india-is-announced-june-20-2009-saturday/"&gt;Pinal’s Blog&lt;/a&gt; and &lt;a href="http://beyondrelational.com/blogs/jacob/archive/2009/06/10/beyond-relational-news-tech-ed-ahmedabad-2009-announced-20-june-2009-saturday-hotel-rock-regency.aspx"&gt;Jacob’s Blog&lt;/a&gt; .     &lt;br /&gt;    &lt;br /&gt;&lt;a href="http://beyondrelational.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/ashish/techedonroad_5F00_382D9585.jpg"&gt;&lt;img title="techedonroad" style="border-right:0px;border-top:0px;display:inline;border-left:0px;border-bottom:0px;" height="906" alt="techedonroad" src="http://beyondrelational.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/ashish/techedonroad_5F00_thumb_5F00_4C6DEE14.jpg" width="511" border="0" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;So mark your calendar for this grand event in Ahmedabad here are the details of this event ::&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;Location ::&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;Hotel Rock Regency    &lt;br /&gt;C.G. Road     &lt;br /&gt;Ahmedabad, India.&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;Date &amp;amp; Time::&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;June 20, 2009 Saturday    &lt;br /&gt;1:30 PM &lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;Hope to see you there on time.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://beyondrelational.com/aggbug.aspx?PostID=412" width="1" height="1"&gt;&lt;img src="http://feeds.feedburner.com/~r/AshishsBlog/~4/E9sTPjcC6cw" height="1" width="1"/&gt;</description><category domain="http://beyondrelational.com/blogs/ashish/archive/tags/SQL-Server/default.aspx">SQL-Server</category><category domain="http://beyondrelational.com/blogs/ashish/archive/tags/Event/default.aspx">Event</category><category domain="http://beyondrelational.com/blogs/ashish/archive/tags/TechEd/default.aspx">TechEd</category><category domain="http://beyondrelational.com/blogs/ashish/archive/tags/Technology/default.aspx">Technology</category><feedburner:origLink>http://beyondrelational.com/blogs/ashish/archive/2009/06/11/teched-on-road-ahmedabad-june-20-2009.aspx</feedburner:origLink></item><item><title>Encryption &amp; Decryption in SQL SERVER 2005</title><link>http://feedproxy.google.com/~r/AshishsBlog/~3/Xs1UPA4w3kI/encryption-amp-decryption-in-sql-server-2005.aspx</link><pubDate>Sat, 30 May 2009 13:44:00 GMT</pubDate><guid isPermaLink="false">6e5011fa-7db5-4df3-bb79-9085c1d333b3:168</guid><dc:creator>Ashish Gilhotra</dc:creator><slash:comments>3</slash:comments><wfw:commentRss>http://beyondrelational.com/blogs/ashish/rsscomments.aspx?PostID=168</wfw:commentRss><comments>http://beyondrelational.com/blogs/ashish/archive/2009/05/30/encryption-amp-decryption-in-sql-server-2005.aspx#comments</comments><description>&lt;p&gt;Hi all,&lt;/p&gt;
&lt;p&gt;Here is a very powerful feature of SQL Server 2005 is Data Encryption &amp;amp; Decryption, in Sql Server 2000 if we like to Encrypt Data then we have to write our own functions to encrypt the data. In SQL Server 2005 and SQL Server 2008, these&amp;nbsp; functions are available by default.&lt;/p&gt;
&lt;p&gt;SQL Server provides the following method to encrypt your data&amp;hellip;.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;ENCRYPTION by passphrase&lt;/li&gt;
&lt;li&gt;ENCRYPTION by symmetric key&lt;/li&gt;
&lt;li&gt;ENCRYPTION by asymmetric key &lt;/li&gt;
&lt;li&gt;ENCRYPTION by certificate&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;So here we try to encrypt the data by using Symmetric keys.&lt;/p&gt;
&lt;p&gt;So in this we firstly create a database and create master key ,certificate ,symmetric key table and do encryption so here we go&amp;hellip;   &lt;br /&gt;    &lt;br /&gt;Create Database ..&lt;/p&gt;
&lt;div id="codeSnippetWrapper"&gt;
&lt;div id="codeSnippet" style="font-size:8pt;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:&amp;#39;Courier New&amp;#39;, courier, monospace;background-color:#f4f4f4;text-align:left;border-style:none;padding:0px;"&gt;
&lt;pre style="font-size:8pt;margin:0em;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:&amp;#39;Courier New&amp;#39;, courier, monospace;background-color:white;text-align:left;border-style:none;padding:0px;"&gt;&lt;span style="color:#0000ff;"&gt;USE&lt;/span&gt; MASTER&lt;/pre&gt;

&lt;pre style="font-size:8pt;margin:0em;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:&amp;#39;Courier New&amp;#39;, courier, monospace;background-color:#f4f4f4;text-align:left;border-style:none;padding:0px;"&gt;&lt;span style="color:#0000ff;"&gt;GO&lt;/span&gt;&lt;/pre&gt;

&lt;pre style="font-size:8pt;margin:0em;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:&amp;#39;Courier New&amp;#39;, courier, monospace;background-color:white;text-align:left;border-style:none;padding:0px;"&gt;&amp;nbsp;&lt;/pre&gt;

&lt;pre style="font-size:8pt;margin:0em;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:&amp;#39;Courier New&amp;#39;, courier, monospace;background-color:#f4f4f4;text-align:left;border-style:none;padding:0px;"&gt;&lt;span style="color:#008000;"&gt;-- First Create a DATABASE&lt;/span&gt;&lt;/pre&gt;

&lt;pre style="font-size:8pt;margin:0em;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:&amp;#39;Courier New&amp;#39;, courier, monospace;background-color:white;text-align:left;border-style:none;padding:0px;"&gt;&lt;span style="color:#0000ff;"&gt;CREATE&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;DATABASE&lt;/span&gt; ENCRYPTDECRYPTTEST &lt;span style="color:#0000ff;"&gt;ON&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;PRIMARY&lt;/span&gt;&lt;/pre&gt;

&lt;pre style="font-size:8pt;margin:0em;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:&amp;#39;Courier New&amp;#39;, courier, monospace;background-color:#f4f4f4;text-align:left;border-style:none;padding:0px;"&gt;(NAME=N&lt;span style="color:#006080;"&gt;&amp;#39;ENCRYPTDECRYPTTEST&amp;#39;&lt;/span&gt; ,FILENAME=N&lt;span style="color:#006080;"&gt;&amp;#39;D:\ENCRYPTDECRYPTTEST.mdf&amp;#39;&lt;/span&gt;)&lt;/pre&gt;

&lt;pre style="font-size:8pt;margin:0em;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:&amp;#39;Courier New&amp;#39;, courier, monospace;background-color:white;text-align:left;border-style:none;padding:0px;"&gt;LOG &lt;span style="color:#0000ff;"&gt;ON&lt;/span&gt; &lt;/pre&gt;

&lt;pre style="font-size:8pt;margin:0em;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:&amp;#39;Courier New&amp;#39;, courier, monospace;background-color:#f4f4f4;text-align:left;border-style:none;padding:0px;"&gt;(NAME=N&lt;span style="color:#006080;"&gt;&amp;#39;ENCRYPTDECRYPTTEST_LOG&amp;#39;&lt;/span&gt; ,FILENAME=N&lt;span style="color:#006080;"&gt;&amp;#39;D:\ENCRYPTDECRYPTTEST.ldf&amp;#39;&lt;/span&gt;)&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;Use database and Create master key, certificate and symmetric key&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;div id="codeSnippetWrapper"&gt;
&lt;div id="codeSnippet" style="font-size:8pt;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:&amp;#39;Courier New&amp;#39;, courier, monospace;background-color:#f4f4f4;text-align:left;border-style:none;padding:0px;"&gt;
&lt;pre style="font-size:8pt;margin:0em;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:&amp;#39;Courier New&amp;#39;, courier, monospace;background-color:white;text-align:left;border-style:none;padding:0px;"&gt;&lt;span style="color:#008000;"&gt;-- Use database&lt;/span&gt;&lt;/pre&gt;

&lt;pre style="font-size:8pt;margin:0em;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:&amp;#39;Courier New&amp;#39;, courier, monospace;background-color:#f4f4f4;text-align:left;border-style:none;padding:0px;"&gt;&lt;span style="color:#0000ff;"&gt;USE&lt;/span&gt; ENCRYPTDECRYPTTEST&lt;/pre&gt;

&lt;pre style="font-size:8pt;margin:0em;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:&amp;#39;Courier New&amp;#39;, courier, monospace;background-color:white;text-align:left;border-style:none;padding:0px;"&gt;&lt;span style="color:#0000ff;"&gt;GO&lt;/span&gt;&lt;/pre&gt;

&lt;pre style="font-size:8pt;margin:0em;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:&amp;#39;Courier New&amp;#39;, courier, monospace;background-color:#f4f4f4;text-align:left;border-style:none;padding:0px;"&gt;&amp;nbsp;&lt;/pre&gt;

&lt;pre style="font-size:8pt;margin:0em;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:&amp;#39;Courier New&amp;#39;, courier, monospace;background-color:white;text-align:left;border-style:none;padding:0px;"&gt;&lt;span style="color:#008000;"&gt;-- Create Master Key&lt;/span&gt;&lt;/pre&gt;

&lt;pre style="font-size:8pt;margin:0em;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:&amp;#39;Courier New&amp;#39;, courier, monospace;background-color:#f4f4f4;text-align:left;border-style:none;padding:0px;"&gt;&lt;span style="color:#0000ff;"&gt;CREATE&lt;/span&gt; MASTER &lt;span style="color:#0000ff;"&gt;KEY&lt;/span&gt; ENCRYPTION &lt;span style="color:#0000ff;"&gt;BY&lt;/span&gt; &lt;/pre&gt;

&lt;pre style="font-size:8pt;margin:0em;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:&amp;#39;Courier New&amp;#39;, courier, monospace;background-color:white;text-align:left;border-style:none;padding:0px;"&gt;    PASSWORD =&lt;span style="color:#006080;"&gt;&amp;#39;ASHISH&amp;#39;&lt;/span&gt;&lt;/pre&gt;

&lt;pre style="font-size:8pt;margin:0em;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:&amp;#39;Courier New&amp;#39;, courier, monospace;background-color:#f4f4f4;text-align:left;border-style:none;padding:0px;"&gt;&lt;span style="color:#0000ff;"&gt;GO&lt;/span&gt;&lt;/pre&gt;

&lt;pre style="font-size:8pt;margin:0em;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:&amp;#39;Courier New&amp;#39;, courier, monospace;background-color:white;text-align:left;border-style:none;padding:0px;"&gt;&amp;nbsp;&lt;/pre&gt;

&lt;pre style="font-size:8pt;margin:0em;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:&amp;#39;Courier New&amp;#39;, courier, monospace;background-color:#f4f4f4;text-align:left;border-style:none;padding:0px;"&gt;&amp;nbsp;&lt;/pre&gt;

&lt;pre style="font-size:8pt;margin:0em;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:&amp;#39;Courier New&amp;#39;, courier, monospace;background-color:white;text-align:left;border-style:none;padding:0px;"&gt;&lt;span style="color:#008000;"&gt;-- Create Certificate&lt;/span&gt;&lt;/pre&gt;

&lt;pre style="font-size:8pt;margin:0em;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:&amp;#39;Courier New&amp;#39;, courier, monospace;background-color:#f4f4f4;text-align:left;border-style:none;padding:0px;"&gt;&lt;span style="color:#0000ff;"&gt;CREATE&lt;/span&gt; CERTIFICATE ENCDECTEST &lt;/pre&gt;

&lt;pre style="font-size:8pt;margin:0em;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:&amp;#39;Courier New&amp;#39;, courier, monospace;background-color:white;text-align:left;border-style:none;padding:0px;"&gt;    &lt;span style="color:#0000ff;"&gt;WITH&lt;/span&gt; SUBJECT=&lt;span style="color:#006080;"&gt;&amp;#39;ASHISH&amp;#39;&lt;/span&gt;&lt;/pre&gt;

&lt;pre style="font-size:8pt;margin:0em;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:&amp;#39;Courier New&amp;#39;, courier, monospace;background-color:#f4f4f4;text-align:left;border-style:none;padding:0px;"&gt;&lt;span style="color:#0000ff;"&gt;GO&lt;/span&gt;&lt;/pre&gt;

&lt;pre style="font-size:8pt;margin:0em;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:&amp;#39;Courier New&amp;#39;, courier, monospace;background-color:white;text-align:left;border-style:none;padding:0px;"&gt;&amp;nbsp;&lt;/pre&gt;

&lt;pre style="font-size:8pt;margin:0em;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:&amp;#39;Courier New&amp;#39;, courier, monospace;background-color:#f4f4f4;text-align:left;border-style:none;padding:0px;"&gt;&lt;span style="color:#008000;"&gt;-- Check it&lt;/span&gt;&lt;/pre&gt;

&lt;pre style="font-size:8pt;margin:0em;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:&amp;#39;Courier New&amp;#39;, courier, monospace;background-color:white;text-align:left;border-style:none;padding:0px;"&gt;&lt;span style="color:#0000ff;"&gt;SELECT&lt;/span&gt; * &lt;span style="color:#0000ff;"&gt;FROM&lt;/span&gt; SYS.CERTIFICATES&lt;/pre&gt;

&lt;pre style="font-size:8pt;margin:0em;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:&amp;#39;Courier New&amp;#39;, courier, monospace;background-color:#f4f4f4;text-align:left;border-style:none;padding:0px;"&gt;&amp;nbsp;&lt;/pre&gt;

&lt;pre style="font-size:8pt;margin:0em;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:&amp;#39;Courier New&amp;#39;, courier, monospace;background-color:white;text-align:left;border-style:none;padding:0px;"&gt;&lt;span style="color:#008000;"&gt;-- Create Symmetric Key&lt;/span&gt;&lt;/pre&gt;

&lt;pre style="font-size:8pt;margin:0em;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:&amp;#39;Courier New&amp;#39;, courier, monospace;background-color:#f4f4f4;text-align:left;border-style:none;padding:0px;"&gt;&lt;span style="color:#0000ff;"&gt;CREATE&lt;/span&gt; SYMMETRIC &lt;span style="color:#0000ff;"&gt;KEY&lt;/span&gt; TESTKEY&lt;/pre&gt;

&lt;pre style="font-size:8pt;margin:0em;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:&amp;#39;Courier New&amp;#39;, courier, monospace;background-color:white;text-align:left;border-style:none;padding:0px;"&gt;    &lt;span style="color:#0000ff;"&gt;WITH&lt;/span&gt; ALGORITHM = TRIPLE_DES&lt;/pre&gt;

&lt;pre style="font-size:8pt;margin:0em;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:&amp;#39;Courier New&amp;#39;, courier, monospace;background-color:#f4f4f4;text-align:left;border-style:none;padding:0px;"&gt;    ENCRYPTION &lt;span style="color:#0000ff;"&gt;BY&lt;/span&gt; CERTIFICATE ENCDECTEST&lt;/pre&gt;

&lt;pre style="font-size:8pt;margin:0em;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:&amp;#39;Courier New&amp;#39;, courier, monospace;background-color:white;text-align:left;border-style:none;padding:0px;"&gt;&lt;span style="color:#0000ff;"&gt;GO&lt;/span&gt; &lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;
  &lt;br /&gt;In the above create symmetric key T-Sql statement the algorithm parameter is the most important part&amp;hellip;&lt;/p&gt;
&lt;p&gt;SQL SERVER can use the following algorithms in encryption:&lt;/p&gt;
&lt;p&gt;DES, TRIPLE_DES, RC2, RC4, RC4_128, DESX, AES_128, AES_192 AND AES_256.&lt;/p&gt;
&lt;p&gt;Now create a table &amp;hellip;&lt;/p&gt;
&lt;div id="codeSnippetWrapper"&gt;
&lt;div id="codeSnippet" style="font-size:8pt;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:&amp;#39;Courier New&amp;#39;, courier, monospace;background-color:#f4f4f4;text-align:left;border-style:none;padding:0px;"&gt;
&lt;pre style="font-size:8pt;margin:0em;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:&amp;#39;Courier New&amp;#39;, courier, monospace;background-color:white;text-align:left;border-style:none;padding:0px;"&gt;&lt;span style="color:#008000;"&gt;-- Create a Sample Table&lt;/span&gt;&lt;/pre&gt;

&lt;pre style="font-size:8pt;margin:0em;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:&amp;#39;Courier New&amp;#39;, courier, monospace;background-color:#f4f4f4;text-align:left;border-style:none;padding:0px;"&gt;&lt;span style="color:#0000ff;"&gt;CREATE&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;TABLE&lt;/span&gt; USERS (UID &lt;span style="color:#0000ff;"&gt;INT&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;IDENTITY&lt;/span&gt;(100,1),UFNAME &lt;span style="color:#0000ff;"&gt;VARCHAR&lt;/span&gt;(100),ULNAME &lt;span style="color:#0000ff;"&gt;VARCHAR&lt;/span&gt;(100),ULOGINDI &lt;span style="color:#0000ff;"&gt;VARCHAR&lt;/span&gt;(50),UPASSWORD VARBINARY(256))&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;So now its turn to insert data in USERS table and we encrypt the UPASSWORD field using our symmetric key this can be done by a Store Procedure so we create a Insert Procedure for this.. so here is the procedure&amp;hellip;.&lt;/p&gt;
&lt;div id="codeSnippetWrapper"&gt;
&lt;div id="codeSnippet" style="font-size:8pt;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:&amp;#39;Courier New&amp;#39;, courier, monospace;background-color:#f4f4f4;text-align:left;border-style:none;padding:0px;"&gt;
&lt;pre style="font-size:8pt;margin:0em;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:&amp;#39;Courier New&amp;#39;, courier, monospace;background-color:white;text-align:left;border-style:none;padding:0px;"&gt;&lt;span style="color:#008000;"&gt;-- Create a Procedure to Insert Data in Table&lt;/span&gt;&lt;/pre&gt;

&lt;pre style="font-size:8pt;margin:0em;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:&amp;#39;Courier New&amp;#39;, courier, monospace;background-color:#f4f4f4;text-align:left;border-style:none;padding:0px;"&gt;&lt;span style="color:#0000ff;"&gt;CREATE&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;PROC&lt;/span&gt; [InsertUSER]&lt;/pre&gt;

&lt;pre style="font-size:8pt;margin:0em;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:&amp;#39;Courier New&amp;#39;, courier, monospace;background-color:white;text-align:left;border-style:none;padding:0px;"&gt;  @UFNAME &lt;span style="color:#0000ff;"&gt;VARCHAR&lt;/span&gt;(100),&lt;/pre&gt;

&lt;pre style="font-size:8pt;margin:0em;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:&amp;#39;Courier New&amp;#39;, courier, monospace;background-color:#f4f4f4;text-align:left;border-style:none;padding:0px;"&gt;  @ULNAME &lt;span style="color:#0000ff;"&gt;VARCHAR&lt;/span&gt;(100),&lt;/pre&gt;

&lt;pre style="font-size:8pt;margin:0em;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:&amp;#39;Courier New&amp;#39;, courier, monospace;background-color:white;text-align:left;border-style:none;padding:0px;"&gt;  @ULOGINDI &lt;span style="color:#0000ff;"&gt;VARCHAR&lt;/span&gt;(12),&lt;/pre&gt;

&lt;pre style="font-size:8pt;margin:0em;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:&amp;#39;Courier New&amp;#39;, courier, monospace;background-color:#f4f4f4;text-align:left;border-style:none;padding:0px;"&gt;  @UPASSWORD &lt;span style="color:#0000ff;"&gt;VARCHAR&lt;/span&gt;(20)&lt;/pre&gt;

&lt;pre style="font-size:8pt;margin:0em;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:&amp;#39;Courier New&amp;#39;, courier, monospace;background-color:white;text-align:left;border-style:none;padding:0px;"&gt;&lt;span style="color:#0000ff;"&gt;AS&lt;/span&gt;&lt;/pre&gt;

&lt;pre style="font-size:8pt;margin:0em;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:&amp;#39;Courier New&amp;#39;, courier, monospace;background-color:#f4f4f4;text-align:left;border-style:none;padding:0px;"&gt;&lt;span style="color:#0000ff;"&gt;BEGIN&lt;/span&gt;&lt;/pre&gt;

&lt;pre style="font-size:8pt;margin:0em;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:&amp;#39;Courier New&amp;#39;, courier, monospace;background-color:white;text-align:left;border-style:none;padding:0px;"&gt;&lt;span style="color:#008000;"&gt;-- you must open the key as it is not already&lt;/span&gt;&lt;/pre&gt;

&lt;pre style="font-size:8pt;margin:0em;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:&amp;#39;Courier New&amp;#39;, courier, monospace;background-color:#f4f4f4;text-align:left;border-style:none;padding:0px;"&gt;    &lt;span style="color:#0000ff;"&gt;OPEN&lt;/span&gt; SYMMETRIC &lt;span style="color:#0000ff;"&gt;KEY&lt;/span&gt; TESTKEY &lt;/pre&gt;

&lt;pre style="font-size:8pt;margin:0em;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:&amp;#39;Courier New&amp;#39;, courier, monospace;background-color:white;text-align:left;border-style:none;padding:0px;"&gt;        DECRYPTION &lt;span style="color:#0000ff;"&gt;BY&lt;/span&gt; CERTIFICATE ENCDECTEST;&lt;/pre&gt;

&lt;pre style="font-size:8pt;margin:0em;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:&amp;#39;Courier New&amp;#39;, courier, monospace;background-color:#f4f4f4;text-align:left;border-style:none;padding:0px;"&gt;    &lt;/pre&gt;

&lt;pre style="font-size:8pt;margin:0em;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:&amp;#39;Courier New&amp;#39;, courier, monospace;background-color:white;text-align:left;border-style:none;padding:0px;"&gt;&lt;span style="color:#008000;"&gt;-- Insert statement&lt;/span&gt;&lt;/pre&gt;

&lt;pre style="font-size:8pt;margin:0em;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:&amp;#39;Courier New&amp;#39;, courier, monospace;background-color:#f4f4f4;text-align:left;border-style:none;padding:0px;"&gt;    INSERT &lt;span style="color:#0000ff;"&gt;INTO&lt;/span&gt; [USERS] &lt;/pre&gt;

&lt;pre style="font-size:8pt;margin:0em;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:&amp;#39;Courier New&amp;#39;, courier, monospace;background-color:white;text-align:left;border-style:none;padding:0px;"&gt;    (UFNAME, ULNAME, ULOGINDI, UPASSWORD) &lt;/pre&gt;

&lt;pre style="font-size:8pt;margin:0em;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:&amp;#39;Courier New&amp;#39;, courier, monospace;background-color:#f4f4f4;text-align:left;border-style:none;padding:0px;"&gt;    &lt;span style="color:#0000ff;"&gt;VALUES&lt;/span&gt; &lt;/pre&gt;

&lt;pre style="font-size:8pt;margin:0em;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:&amp;#39;Courier New&amp;#39;, courier, monospace;background-color:white;text-align:left;border-style:none;padding:0px;"&gt;    (@UFNAME, @ULNAME, @ULOGINDI, &lt;/pre&gt;

&lt;pre style="font-size:8pt;margin:0em;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:&amp;#39;Courier New&amp;#39;, courier, monospace;background-color:#f4f4f4;text-align:left;border-style:none;padding:0px;"&gt;     EncryptByKey(Key_GUID(&lt;span style="color:#006080;"&gt;&amp;#39;TESTKEY&amp;#39;&lt;/span&gt;), @UPASSWORD));&lt;/pre&gt;

&lt;pre style="font-size:8pt;margin:0em;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:&amp;#39;Courier New&amp;#39;, courier, monospace;background-color:white;text-align:left;border-style:none;padding:0px;"&gt;     &lt;/pre&gt;

&lt;pre style="font-size:8pt;margin:0em;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:&amp;#39;Courier New&amp;#39;, courier, monospace;background-color:#f4f4f4;text-align:left;border-style:none;padding:0px;"&gt;&lt;span style="color:#0000ff;"&gt;END&lt;/span&gt;;&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;So after creating procedure you can run these procedures by following parameters and check the data in table&amp;hellip;&lt;/p&gt;
&lt;div id="codeSnippetWrapper"&gt;
&lt;div id="codeSnippet" style="font-size:8pt;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:&amp;#39;Courier New&amp;#39;, courier, monospace;background-color:#f4f4f4;text-align:left;border-style:none;padding:0px;"&gt;
&lt;pre style="font-size:8pt;margin:0em;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:&amp;#39;Courier New&amp;#39;, courier, monospace;background-color:white;text-align:left;border-style:none;padding:0px;"&gt;&lt;span style="color:#008000;"&gt;-- Run Insert Procedure&lt;/span&gt;&lt;/pre&gt;

&lt;pre style="font-size:8pt;margin:0em;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:&amp;#39;Courier New&amp;#39;, courier, monospace;background-color:#f4f4f4;text-align:left;border-style:none;padding:0px;"&gt;&lt;span style="color:#0000ff;"&gt;EXEC&lt;/span&gt; INSERTUSER &lt;span style="color:#006080;"&gt;&amp;#39;ASHISH&amp;#39;&lt;/span&gt;,&lt;span style="color:#006080;"&gt;&amp;#39;GILHOTRA&amp;#39;&lt;/span&gt;,&lt;span style="color:#006080;"&gt;&amp;#39;ASHISH&amp;#39;&lt;/span&gt;,&lt;span style="color:#006080;"&gt;&amp;#39;MYPASSWORD&amp;#39;&lt;/span&gt;&lt;/pre&gt;

&lt;pre style="font-size:8pt;margin:0em;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:&amp;#39;Courier New&amp;#39;, courier, monospace;background-color:white;text-align:left;border-style:none;padding:0px;"&gt;&amp;nbsp;&lt;/pre&gt;

&lt;pre style="font-size:8pt;margin:0em;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:&amp;#39;Courier New&amp;#39;, courier, monospace;background-color:#f4f4f4;text-align:left;border-style:none;padding:0px;"&gt;&lt;span style="color:#008000;"&gt;-- Check the Data&lt;/span&gt;&lt;/pre&gt;

&lt;pre style="font-size:8pt;margin:0em;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:&amp;#39;Courier New&amp;#39;, courier, monospace;background-color:white;text-align:left;border-style:none;padding:0px;"&gt;&lt;span style="color:#0000ff;"&gt;SELECT&lt;/span&gt; * &lt;span style="color:#0000ff;"&gt;FROM&lt;/span&gt; USERS&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;
  &lt;br /&gt;and the results will be like this&amp;hellip;&lt;/p&gt;
&lt;p&gt;&lt;a href="http://beyondrelational.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/ashish/ENCDEC1_5F00_257B4925.jpg"&gt;&lt;img title="ENCDEC1" style="border-right:0px;border-top:0px;display:inline;border-left:0px;border-bottom:0px;" height="118" alt="ENCDEC1" src="http://beyondrelational.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/ashish/ENCDEC1_5F00_thumb_5F00_2EFBB9AE.jpg" width="284" border="0" /&gt;&lt;/a&gt; &lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Now we create a Store Procedure to extract the decrypted data so here we go and create a store procedure to extract data in Decrypted form&amp;hellip;&lt;/p&gt;
&lt;p&gt;and run that procedure&amp;hellip;
  &lt;/p&gt;
&lt;div id="codeSnippetWrapper"&gt;
&lt;div id="codeSnippet" style="font-size:8pt;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:&amp;#39;Courier New&amp;#39;, courier, monospace;background-color:#f4f4f4;text-align:left;border-style:none;padding:0px;"&gt;
&lt;pre style="font-size:8pt;margin:0em;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:&amp;#39;Courier New&amp;#39;, courier, monospace;background-color:white;text-align:left;border-style:none;padding:0px;"&gt;&lt;span style="color:#008000;"&gt;-- Procedure to Retrive Users&lt;/span&gt;&lt;/pre&gt;

&lt;pre style="font-size:8pt;margin:0em;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:&amp;#39;Courier New&amp;#39;, courier, monospace;background-color:#f4f4f4;text-align:left;border-style:none;padding:0px;"&gt;&lt;span style="color:#0000ff;"&gt;CREATE&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;PROC&lt;/span&gt; [RetrieveUSER]&lt;/pre&gt;

&lt;pre style="font-size:8pt;margin:0em;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:&amp;#39;Courier New&amp;#39;, courier, monospace;background-color:white;text-align:left;border-style:none;padding:0px;"&gt;    @UID &lt;span style="color:#0000ff;"&gt;INT&lt;/span&gt;&lt;/pre&gt;

&lt;pre style="font-size:8pt;margin:0em;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:&amp;#39;Courier New&amp;#39;, courier, monospace;background-color:#f4f4f4;text-align:left;border-style:none;padding:0px;"&gt;&lt;span style="color:#0000ff;"&gt;AS&lt;/span&gt;&lt;/pre&gt;

&lt;pre style="font-size:8pt;margin:0em;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:&amp;#39;Courier New&amp;#39;, courier, monospace;background-color:white;text-align:left;border-style:none;padding:0px;"&gt;&lt;span style="color:#0000ff;"&gt;BEGIN&lt;/span&gt;&lt;/pre&gt;

&lt;pre style="font-size:8pt;margin:0em;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:&amp;#39;Courier New&amp;#39;, courier, monospace;background-color:#f4f4f4;text-align:left;border-style:none;padding:0px;"&gt;&lt;span style="color:#008000;"&gt;-- you must open the key as it is not already&lt;/span&gt;&lt;/pre&gt;

&lt;pre style="font-size:8pt;margin:0em;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:&amp;#39;Courier New&amp;#39;, courier, monospace;background-color:white;text-align:left;border-style:none;padding:0px;"&gt;    &lt;span style="color:#0000ff;"&gt;OPEN&lt;/span&gt; SYMMETRIC &lt;span style="color:#0000ff;"&gt;KEY&lt;/span&gt; TESTKEY &lt;/pre&gt;

&lt;pre style="font-size:8pt;margin:0em;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:&amp;#39;Courier New&amp;#39;, courier, monospace;background-color:#f4f4f4;text-align:left;border-style:none;padding:0px;"&gt;        DECRYPTION &lt;span style="color:#0000ff;"&gt;BY&lt;/span&gt; CERTIFICATE ENCDECTEST;&lt;/pre&gt;

&lt;pre style="font-size:8pt;margin:0em;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:&amp;#39;Courier New&amp;#39;, courier, monospace;background-color:white;text-align:left;border-style:none;padding:0px;"&gt;&amp;nbsp;&lt;/pre&gt;

&lt;pre style="font-size:8pt;margin:0em;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:&amp;#39;Courier New&amp;#39;, courier, monospace;background-color:#f4f4f4;text-align:left;border-style:none;padding:0px;"&gt;&lt;span style="color:#008000;"&gt;-- Select statement&lt;/span&gt;&lt;/pre&gt;

&lt;pre style="font-size:8pt;margin:0em;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:&amp;#39;Courier New&amp;#39;, courier, monospace;background-color:white;text-align:left;border-style:none;padding:0px;"&gt;  &lt;span style="color:#0000ff;"&gt;SELECT&lt;/span&gt; UID, UFNAME, ULNAME, ULOGINDI, &lt;span style="color:#0000ff;"&gt;CONVERT&lt;/span&gt;(&lt;span style="color:#0000ff;"&gt;VARCHAR&lt;/span&gt;(20),DECRYPTBYKEY(UPASSWORD)) &lt;span style="color:#0000ff;"&gt;AS&lt;/span&gt; PASSWORD&lt;/pre&gt;

&lt;pre style="font-size:8pt;margin:0em;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:&amp;#39;Courier New&amp;#39;, courier, monospace;background-color:#f4f4f4;text-align:left;border-style:none;padding:0px;"&gt;  &lt;span style="color:#0000ff;"&gt;FROM&lt;/span&gt; USERS&lt;/pre&gt;

&lt;pre style="font-size:8pt;margin:0em;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:&amp;#39;Courier New&amp;#39;, courier, monospace;background-color:white;text-align:left;border-style:none;padding:0px;"&gt;  &lt;span style="color:#0000ff;"&gt;WHERE&lt;/span&gt; UID = @UID;&lt;/pre&gt;

&lt;pre style="font-size:8pt;margin:0em;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:&amp;#39;Courier New&amp;#39;, courier, monospace;background-color:#f4f4f4;text-align:left;border-style:none;padding:0px;"&gt;&lt;span style="color:#0000ff;"&gt;END&lt;/span&gt;;&lt;/pre&gt;

&lt;pre style="font-size:8pt;margin:0em;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:&amp;#39;Courier New&amp;#39;, courier, monospace;background-color:white;text-align:left;border-style:none;padding:0px;"&gt;&amp;nbsp;&lt;/pre&gt;

&lt;pre style="font-size:8pt;margin:0em;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:&amp;#39;Courier New&amp;#39;, courier, monospace;background-color:#f4f4f4;text-align:left;border-style:none;padding:0px;"&gt;&lt;span style="color:#008000;"&gt;-- Execute Retrive Procedure&lt;/span&gt;&lt;/pre&gt;

&lt;pre style="font-size:8pt;margin:0em;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:&amp;#39;Courier New&amp;#39;, courier, monospace;background-color:white;text-align:left;border-style:none;padding:0px;"&gt;&lt;span style="color:#0000ff;"&gt;EXEC&lt;/span&gt; RetrieveUSER 100&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt; and the results will be like this&amp;hellip;.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;a href="http://beyondrelational.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/ashish/encdec2_5F00_13E80C02.jpg"&gt;&lt;img title="encdec2" style="border-right:0px;border-top:0px;display:inline;border-left:0px;border-bottom:0px;" height="157" alt="encdec2" src="http://beyondrelational.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/ashish/encdec2_5F00_thumb_5F00_5D9E9605.jpg" width="284" border="0" /&gt;&lt;/a&gt; &lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;So in this way you can protect your sensitive data like passwords, credit cars numbers and many more,,,,
  &lt;br /&gt;there also some others way to do encryption in SQL Server 2005 and SQL Server 2008 .&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Thanks &amp;amp; Happy Querying&amp;hellip;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://beyondrelational.com/aggbug.aspx?PostID=168" width="1" height="1"&gt;&lt;img src="http://feeds.feedburner.com/~r/AshishsBlog/~4/Xs1UPA4w3kI" height="1" width="1"/&gt;</description><category domain="http://beyondrelational.com/blogs/ashish/archive/tags/SQLSERVER-2005/default.aspx">SQLSERVER-2005</category><category domain="http://beyondrelational.com/blogs/ashish/archive/tags/Decryption/default.aspx">Decryption</category><category domain="http://beyondrelational.com/blogs/ashish/archive/tags/Encryption/default.aspx">Encryption</category><feedburner:origLink>http://beyondrelational.com/blogs/ashish/archive/2009/05/30/encryption-amp-decryption-in-sql-server-2005.aspx</feedburner:origLink></item><item><title>Running Out of System Table</title><link>http://feedproxy.google.com/~r/AshishsBlog/~3/TsH-Kn1_nac/running-out-of-system-table.aspx</link><pubDate>Thu, 21 May 2009 13:23:00 GMT</pubDate><guid isPermaLink="false">6e5011fa-7db5-4df3-bb79-9085c1d333b3:138</guid><dc:creator>Ashish Gilhotra</dc:creator><slash:comments>0</slash:comments><wfw:commentRss>http://beyondrelational.com/blogs/ashish/rsscomments.aspx?PostID=138</wfw:commentRss><comments>http://beyondrelational.com/blogs/ashish/archive/2009/05/21/running-out-of-system-table.aspx#comments</comments><description>&lt;p&gt;Hi all, &lt;/p&gt;
&lt;p&gt;Today i encounter a issue with my instance as i am using the table SPT_VALUES from the master database available in our Sql Server, so when i tried to fetch some records from master..spt_values then it shows me error&amp;hellip;&lt;/p&gt;
&lt;p&gt;Here is a example of query and the error thrown by SQL is..&lt;/p&gt;
&lt;div id="codeSnippetWrapper"&gt;
&lt;div id="codeSnippet" style="font-size:8pt;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:&amp;#39;Courier New&amp;#39;, courier, monospace;background-color:#f4f4f4;text-align:left;border-style:none;padding:0px;"&gt;
&lt;pre style="font-size:8pt;margin:0em;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:&amp;#39;Courier New&amp;#39;, courier, monospace;background-color:white;text-align:left;border-style:none;padding:0px;"&gt;&lt;span style="color:#0000ff;"&gt;SELECT&lt;/span&gt; * &lt;span style="color:#0000ff;"&gt;FROM&lt;/span&gt; orders &lt;span style="color:#0000ff;"&gt;WHERE&lt;/span&gt; order_id &lt;span style="color:#0000ff;"&gt;in&lt;/span&gt; (&lt;span style="color:#0000ff;"&gt;SELECT&lt;/span&gt; number &lt;span style="color:#0000ff;"&gt;FROM&lt;/span&gt; master..spt_values &lt;span style="color:#0000ff;"&gt;WHERE&lt;/span&gt; type=&lt;span style="color:#006080;"&gt;&amp;#39;P&amp;#39;&lt;/span&gt;)&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;and Error is..&lt;/p&gt;
&lt;p&gt;&lt;span style="color:#ff0000;"&gt;Msg 208, Level 16, State 1, Line 1
    &lt;br /&gt;Invalid object name &amp;#39;master..spt_values&amp;#39;.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="color:#ff0000;"&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;So it is very uncommon thing to me to loose table from Master Database in Sql Server 2005. But i found that it is not a very uncommon thing because if you can right click on the table present in Master Database and choose the &amp;lsquo;DELETE&amp;rsquo; option then table would be deleted from your server.&lt;/p&gt;
&lt;p&gt;Now what happen next when tables get deleted from your Master Database, there are some information which stored in Tables in Master Database&amp;hellip;&lt;/p&gt;
&lt;p&gt;So i googled a lot about this and here is the solution&amp;hellip;&lt;/p&gt;
&lt;p&gt;There is a script file named &amp;ldquo;u_tables.sql&amp;rdquo;&amp;nbsp; in &amp;ldquo;installation directory &amp;gt;MSSQL&amp;gt;Install&amp;rdquo; folder .&lt;/p&gt;
&lt;p&gt;Execute this script against the instance that has these missing tables, and you will get the tables again.&lt;/p&gt;
&lt;p&gt;But this script has limitations because its only able to recreate /reproduce only two System Tables &amp;ldquo;dbo.spt_monitor and dbo.spt_values&amp;rdquo; .&lt;/p&gt;
&lt;p&gt;So in this way you can get your tables back in Master Database..But it is highly recommended that you don&amp;rsquo;t delete tables present in Master Database.&lt;/p&gt;
&lt;p&gt;Thanks. &lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://beyondrelational.com/aggbug.aspx?PostID=138" width="1" height="1"&gt;&lt;img src="http://feeds.feedburner.com/~r/AshishsBlog/~4/TsH-Kn1_nac" height="1" width="1"/&gt;</description><category domain="http://beyondrelational.com/blogs/ashish/archive/tags/SQLSERVER-2005/default.aspx">SQLSERVER-2005</category><category domain="http://beyondrelational.com/blogs/ashish/archive/tags/u_5F00_tables.sql/default.aspx">u_tables.sql</category><feedburner:origLink>http://beyondrelational.com/blogs/ashish/archive/2009/05/21/running-out-of-system-table.aspx</feedburner:origLink></item><item><title>Error/Exception Handling in SQL Server 2005</title><link>http://feedproxy.google.com/~r/AshishsBlog/~3/6KGWS6iCaUk/error-exception-handling-in-sql-server-2005.aspx</link><pubDate>Sat, 09 May 2009 16:16:00 GMT</pubDate><guid isPermaLink="false">6e5011fa-7db5-4df3-bb79-9085c1d333b3:101</guid><dc:creator>Ashish Gilhotra</dc:creator><slash:comments>0</slash:comments><wfw:commentRss>http://beyondrelational.com/blogs/ashish/rsscomments.aspx?PostID=101</wfw:commentRss><comments>http://beyondrelational.com/blogs/ashish/archive/2009/05/09/error-exception-handling-in-sql-server-2005.aspx#comments</comments><description>&lt;p&gt;Being a .Net developer, the most useful feature i found was the Error Handling or Exception Handling technique.When it comes to programming languages , all popular OOP languages have TRY()&amp;hellip;Catch() method to handle an exception.&lt;/p&gt;
&lt;p&gt;In Sql Server 2005, error handling was made easy . This article demonstrates various methods of handling errors using    &lt;br /&gt;Try()..Catch() in T-SQL. &lt;/p&gt;
&lt;p&gt;Here you try something like that&amp;hellip;&lt;/p&gt;
&lt;div id="codeSnippetWrapper"&gt;
&lt;div id="codeSnippet" style="font-size:8pt;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:&amp;#39;Courier New&amp;#39;, courier, monospace;background-color:#f4f4f4;text-align:left;border-style:none;padding:0px;"&gt;
&lt;pre style="font-size:8pt;margin:0em;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:&amp;#39;Courier New&amp;#39;, courier, monospace;background-color:white;text-align:left;border-style:none;padding:0px;"&gt;&lt;span style="color:#0000ff;"&gt;declare&lt;/span&gt; @i tinyint                     &lt;/pre&gt;

&lt;pre style="font-size:8pt;margin:0em;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:&amp;#39;Courier New&amp;#39;, courier, monospace;background-color:#f4f4f4;text-align:left;border-style:none;padding:0px;"&gt;&lt;span style="color:#0000ff;"&gt;select&lt;/span&gt; @i=&lt;span style="color:#0000ff;"&gt;count&lt;/span&gt;(*) &lt;span style="color:#0000ff;"&gt;from&lt;/span&gt; sys.sysobjects  &lt;/pre&gt;

&lt;pre style="font-size:8pt;margin:0em;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:&amp;#39;Courier New&amp;#39;, courier, monospace;background-color:white;text-align:left;border-style:none;padding:0px;"&gt;&lt;span style="color:#0000ff;"&gt;select&lt;/span&gt; @i*999999999 &lt;span style="color:#0000ff;"&gt;as&lt;/span&gt; myval&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;When you try to run this you will get a error like this&amp;hellip;&lt;/p&gt;
&lt;p&gt;-- Error&lt;/p&gt;
&lt;p&gt;Msg 220, Level 16, State 2, Line 2
  &lt;br /&gt;Arithmetic overflow error for data type tinyint, value = 1812. &lt;/p&gt;
&lt;p&gt;(1 row(s) affected)&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Now try to run it something like this&amp;hellip;.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;div id="codeSnippetWrapper"&gt;
&lt;div id="codeSnippet" style="font-size:8pt;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:&amp;#39;Courier New&amp;#39;, courier, monospace;background-color:#f4f4f4;text-align:left;border-style:none;padding:0px;"&gt;
&lt;pre style="font-size:8pt;margin:0em;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:&amp;#39;Courier New&amp;#39;, courier, monospace;background-color:white;text-align:left;border-style:none;padding:0px;"&gt;&lt;span style="color:#0000ff;"&gt;begin&lt;/span&gt; try                              &lt;/pre&gt;

&lt;pre style="font-size:8pt;margin:0em;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:&amp;#39;Courier New&amp;#39;, courier, monospace;background-color:#f4f4f4;text-align:left;border-style:none;padding:0px;"&gt;    &lt;span style="color:#0000ff;"&gt;declare&lt;/span&gt; @i tinyint                     &lt;/pre&gt;

&lt;pre style="font-size:8pt;margin:0em;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:&amp;#39;Courier New&amp;#39;, courier, monospace;background-color:white;text-align:left;border-style:none;padding:0px;"&gt;    &lt;span style="color:#0000ff;"&gt;select&lt;/span&gt; @i=&lt;span style="color:#0000ff;"&gt;count&lt;/span&gt;(*) &lt;span style="color:#0000ff;"&gt;from&lt;/span&gt; sys.sysobjects &lt;/pre&gt;

&lt;pre style="font-size:8pt;margin:0em;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:&amp;#39;Courier New&amp;#39;, courier, monospace;background-color:#f4f4f4;text-align:left;border-style:none;padding:0px;"&gt;    &lt;span style="color:#0000ff;"&gt;select&lt;/span&gt; @i*999999999 &lt;span style="color:#0000ff;"&gt;as&lt;/span&gt; myval           &lt;/pre&gt;

&lt;pre style="font-size:8pt;margin:0em;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:&amp;#39;Courier New&amp;#39;, courier, monospace;background-color:white;text-align:left;border-style:none;padding:0px;"&gt;&lt;span style="color:#0000ff;"&gt;end&lt;/span&gt; try                                &lt;/pre&gt;

&lt;pre style="font-size:8pt;margin:0em;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:&amp;#39;Courier New&amp;#39;, courier, monospace;background-color:#f4f4f4;text-align:left;border-style:none;padding:0px;"&gt;&lt;span style="color:#0000ff;"&gt;begin&lt;/span&gt; catch                            &lt;/pre&gt;

&lt;pre style="font-size:8pt;margin:0em;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:&amp;#39;Courier New&amp;#39;, courier, monospace;background-color:white;text-align:left;border-style:none;padding:0px;"&gt;    &lt;span style="color:#0000ff;"&gt;select&lt;/span&gt;                                 &lt;/pre&gt;

&lt;pre style="font-size:8pt;margin:0em;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:&amp;#39;Courier New&amp;#39;, courier, monospace;background-color:#f4f4f4;text-align:left;border-style:none;padding:0px;"&gt;    error_line() &lt;span style="color:#0000ff;"&gt;as&lt;/span&gt; errornumber    &lt;/pre&gt;

&lt;pre style="font-size:8pt;margin:0em;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:&amp;#39;Courier New&amp;#39;, courier, monospace;background-color:white;text-align:left;border-style:none;padding:0px;"&gt;&lt;span style="color:#0000ff;"&gt;end&lt;/span&gt; catch    &lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;you will get result like &lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;errornumber
  &lt;br /&gt;------------------
  &lt;br /&gt;4&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;so now this time it throws the number of error.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;You can also get more parameters&amp;nbsp; like Error_Line from this like,,,&lt;/p&gt;
&lt;div id="codeSnippetWrapper"&gt;
&lt;div id="codeSnippet" style="font-size:8pt;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:&amp;#39;Courier New&amp;#39;, courier, monospace;background-color:#f4f4f4;text-align:left;border-style:none;padding:0px;"&gt;
&lt;pre style="font-size:8pt;margin:0em;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:&amp;#39;Courier New&amp;#39;, courier, monospace;background-color:white;text-align:left;border-style:none;padding:0px;"&gt;&lt;span style="color:#0000ff;"&gt;begin&lt;/span&gt; try                              &lt;/pre&gt;

&lt;pre style="font-size:8pt;margin:0em;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:&amp;#39;Courier New&amp;#39;, courier, monospace;background-color:#f4f4f4;text-align:left;border-style:none;padding:0px;"&gt;    &lt;span style="color:#0000ff;"&gt;declare&lt;/span&gt; @i tinyint                     &lt;/pre&gt;

&lt;pre style="font-size:8pt;margin:0em;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:&amp;#39;Courier New&amp;#39;, courier, monospace;background-color:white;text-align:left;border-style:none;padding:0px;"&gt;    &lt;span style="color:#0000ff;"&gt;select&lt;/span&gt; @i=&lt;span style="color:#0000ff;"&gt;count&lt;/span&gt;(*) &lt;span style="color:#0000ff;"&gt;from&lt;/span&gt; sys.sysobjects &lt;/pre&gt;

&lt;pre style="font-size:8pt;margin:0em;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:&amp;#39;Courier New&amp;#39;, courier, monospace;background-color:#f4f4f4;text-align:left;border-style:none;padding:0px;"&gt;    &lt;span style="color:#0000ff;"&gt;select&lt;/span&gt; @i*999999999 &lt;span style="color:#0000ff;"&gt;as&lt;/span&gt; myval           &lt;/pre&gt;

&lt;pre style="font-size:8pt;margin:0em;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:&amp;#39;Courier New&amp;#39;, courier, monospace;background-color:white;text-align:left;border-style:none;padding:0px;"&gt;&lt;span style="color:#0000ff;"&gt;end&lt;/span&gt; try                                &lt;/pre&gt;

&lt;pre style="font-size:8pt;margin:0em;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:&amp;#39;Courier New&amp;#39;, courier, monospace;background-color:#f4f4f4;text-align:left;border-style:none;padding:0px;"&gt;&lt;span style="color:#0000ff;"&gt;begin&lt;/span&gt; catch                            &lt;/pre&gt;

&lt;pre style="font-size:8pt;margin:0em;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:&amp;#39;Courier New&amp;#39;, courier, monospace;background-color:white;text-align:left;border-style:none;padding:0px;"&gt;    &lt;span style="color:#0000ff;"&gt;select&lt;/span&gt;                                 &lt;/pre&gt;

&lt;pre style="font-size:8pt;margin:0em;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:&amp;#39;Courier New&amp;#39;, courier, monospace;background-color:#f4f4f4;text-align:left;border-style:none;padding:0px;"&gt;        ERROR_NUMBER() &lt;span style="color:#0000ff;"&gt;AS&lt;/span&gt; ErrorNumber,&lt;/pre&gt;

&lt;pre style="font-size:8pt;margin:0em;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:&amp;#39;Courier New&amp;#39;, courier, monospace;background-color:white;text-align:left;border-style:none;padding:0px;"&gt;        ERROR_SEVERITY() &lt;span style="color:#0000ff;"&gt;AS&lt;/span&gt; ErrorSeverity,&lt;/pre&gt;

&lt;pre style="font-size:8pt;margin:0em;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:&amp;#39;Courier New&amp;#39;, courier, monospace;background-color:#f4f4f4;text-align:left;border-style:none;padding:0px;"&gt;        ERROR_STATE() &lt;span style="color:#0000ff;"&gt;AS&lt;/span&gt; ErrorState,&lt;/pre&gt;

&lt;pre style="font-size:8pt;margin:0em;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:&amp;#39;Courier New&amp;#39;, courier, monospace;background-color:white;text-align:left;border-style:none;padding:0px;"&gt;        ERROR_PROCEDURE() &lt;span style="color:#0000ff;"&gt;AS&lt;/span&gt; ErrorProcedure,&lt;/pre&gt;

&lt;pre style="font-size:8pt;margin:0em;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:&amp;#39;Courier New&amp;#39;, courier, monospace;background-color:#f4f4f4;text-align:left;border-style:none;padding:0px;"&gt;        ERROR_LINE() &lt;span style="color:#0000ff;"&gt;AS&lt;/span&gt; ErrorLine,&lt;/pre&gt;

&lt;pre style="font-size:8pt;margin:0em;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:&amp;#39;Courier New&amp;#39;, courier, monospace;background-color:white;text-align:left;border-style:none;padding:0px;"&gt;        ERROR_MESSAGE() &lt;span style="color:#0000ff;"&gt;AS&lt;/span&gt; ErrorMessage;&lt;/pre&gt;

&lt;pre style="font-size:8pt;margin:0em;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:&amp;#39;Courier New&amp;#39;, courier, monospace;background-color:#f4f4f4;text-align:left;border-style:none;padding:0px;"&gt;&amp;nbsp;&lt;/pre&gt;

&lt;pre style="font-size:8pt;margin:0em;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:&amp;#39;Courier New&amp;#39;, courier, monospace;background-color:white;text-align:left;border-style:none;padding:0px;"&gt;&lt;span style="color:#0000ff;"&gt;end&lt;/span&gt; catch  &lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;a href="http://beyondrelational.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/ashish/error_5F00_handling1_5F00_77F9377E.jpg"&gt;&lt;img title="error_handling1" style="border-right:0px;border-top:0px;display:inline;margin:0px 10px 0px 0px;border-left:0px;border-bottom:0px;" height="190" alt="error_handling1" src="http://beyondrelational.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/ashish/error_5F00_handling1_5F00_thumb_5F00_421963C6.jpg" width="428" border="0" /&gt;&lt;/a&gt; &lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;like this&amp;hellip;&amp;hellip;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Now you can also make a Store Procedure like this which throws error and use this in your try()..catch() statement like this&amp;hellip;&lt;/p&gt;
&lt;div id="codeSnippetWrapper"&gt;
&lt;div id="codeSnippet" style="font-size:8pt;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:&amp;#39;Courier New&amp;#39;, courier, monospace;background-color:#f4f4f4;text-align:left;border-style:none;padding:0px;"&gt;
&lt;pre style="font-size:8pt;margin:0em;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:&amp;#39;Courier New&amp;#39;, courier, monospace;background-color:white;text-align:left;border-style:none;padding:0px;"&gt;&lt;span style="color:#0000ff;"&gt;CREATE&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;PROCEDURE&lt;/span&gt; Sp_ThrowErrorInfo&lt;/pre&gt;

&lt;pre style="font-size:8pt;margin:0em;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:&amp;#39;Courier New&amp;#39;, courier, monospace;background-color:#f4f4f4;text-align:left;border-style:none;padding:0px;"&gt;&lt;span style="color:#0000ff;"&gt;AS&lt;/span&gt;&lt;/pre&gt;

&lt;pre style="font-size:8pt;margin:0em;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:&amp;#39;Courier New&amp;#39;, courier, monospace;background-color:white;text-align:left;border-style:none;padding:0px;"&gt;    &lt;span style="color:#0000ff;"&gt;SELECT&lt;/span&gt;&lt;/pre&gt;

&lt;pre style="font-size:8pt;margin:0em;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:&amp;#39;Courier New&amp;#39;, courier, monospace;background-color:#f4f4f4;text-align:left;border-style:none;padding:0px;"&gt;        ERROR_NUMBER() &lt;span style="color:#0000ff;"&gt;AS&lt;/span&gt; ErrorNumber,&lt;/pre&gt;

&lt;pre style="font-size:8pt;margin:0em;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:&amp;#39;Courier New&amp;#39;, courier, monospace;background-color:white;text-align:left;border-style:none;padding:0px;"&gt;        ERROR_SEVERITY() &lt;span style="color:#0000ff;"&gt;AS&lt;/span&gt; ErrorSeverity,&lt;/pre&gt;

&lt;pre style="font-size:8pt;margin:0em;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:&amp;#39;Courier New&amp;#39;, courier, monospace;background-color:#f4f4f4;text-align:left;border-style:none;padding:0px;"&gt;        ERROR_STATE() &lt;span style="color:#0000ff;"&gt;AS&lt;/span&gt; ErrorState,&lt;/pre&gt;

&lt;pre style="font-size:8pt;margin:0em;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:&amp;#39;Courier New&amp;#39;, courier, monospace;background-color:white;text-align:left;border-style:none;padding:0px;"&gt;        ERROR_PROCEDURE() &lt;span style="color:#0000ff;"&gt;AS&lt;/span&gt; ErrorProcedure,&lt;/pre&gt;

&lt;pre style="font-size:8pt;margin:0em;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:&amp;#39;Courier New&amp;#39;, courier, monospace;background-color:#f4f4f4;text-align:left;border-style:none;padding:0px;"&gt;        ERROR_LINE() &lt;span style="color:#0000ff;"&gt;AS&lt;/span&gt; ErrorLine,&lt;/pre&gt;

&lt;pre style="font-size:8pt;margin:0em;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:&amp;#39;Courier New&amp;#39;, courier, monospace;background-color:white;text-align:left;border-style:none;padding:0px;"&gt;        ERROR_MESSAGE() &lt;span style="color:#0000ff;"&gt;AS&lt;/span&gt; ErrorMessage;&lt;/pre&gt;

&lt;pre style="font-size:8pt;margin:0em;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:&amp;#39;Courier New&amp;#39;, courier, monospace;background-color:#f4f4f4;text-align:left;border-style:none;padding:0px;"&gt;&lt;span style="color:#0000ff;"&gt;GO&lt;/span&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt; then try&amp;nbsp; like this..&lt;/p&gt;
&lt;div id="codeSnippetWrapper"&gt;
&lt;div id="codeSnippet" style="font-size:8pt;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:&amp;#39;Courier New&amp;#39;, courier, monospace;background-color:#f4f4f4;text-align:left;border-style:none;padding:0px;"&gt;
&lt;pre style="font-size:8pt;margin:0em;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:&amp;#39;Courier New&amp;#39;, courier, monospace;background-color:white;text-align:left;border-style:none;padding:0px;"&gt;&lt;span style="color:#0000ff;"&gt;BEGIN&lt;/span&gt; TRY&lt;/pre&gt;

&lt;pre style="font-size:8pt;margin:0em;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:&amp;#39;Courier New&amp;#39;, courier, monospace;background-color:#f4f4f4;text-align:left;border-style:none;padding:0px;"&gt;    &lt;span style="color:#0000ff;"&gt;declare&lt;/span&gt; @i tinyint                     &lt;/pre&gt;

&lt;pre style="font-size:8pt;margin:0em;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:&amp;#39;Courier New&amp;#39;, courier, monospace;background-color:white;text-align:left;border-style:none;padding:0px;"&gt;    &lt;span style="color:#0000ff;"&gt;select&lt;/span&gt; @i=&lt;span style="color:#0000ff;"&gt;count&lt;/span&gt;(*) &lt;span style="color:#0000ff;"&gt;from&lt;/span&gt; sys.sysobjects &lt;/pre&gt;

&lt;pre style="font-size:8pt;margin:0em;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:&amp;#39;Courier New&amp;#39;, courier, monospace;background-color:#f4f4f4;text-align:left;border-style:none;padding:0px;"&gt;    &lt;span style="color:#0000ff;"&gt;select&lt;/span&gt; @i*999999999 &lt;span style="color:#0000ff;"&gt;as&lt;/span&gt; myval &lt;/pre&gt;

&lt;pre style="font-size:8pt;margin:0em;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:&amp;#39;Courier New&amp;#39;, courier, monospace;background-color:white;text-align:left;border-style:none;padding:0px;"&gt;&lt;span style="color:#0000ff;"&gt;END&lt;/span&gt; TRY&lt;/pre&gt;

&lt;pre style="font-size:8pt;margin:0em;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:&amp;#39;Courier New&amp;#39;, courier, monospace;background-color:#f4f4f4;text-align:left;border-style:none;padding:0px;"&gt;&lt;span style="color:#0000ff;"&gt;BEGIN&lt;/span&gt; CATCH&lt;/pre&gt;

&lt;pre style="font-size:8pt;margin:0em;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:&amp;#39;Courier New&amp;#39;, courier, monospace;background-color:white;text-align:left;border-style:none;padding:0px;"&gt;   &lt;span style="color:#0000ff;"&gt;Exec&lt;/span&gt; Sp_ThrowErrorInfo&lt;/pre&gt;

&lt;pre style="font-size:8pt;margin:0em;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:&amp;#39;Courier New&amp;#39;, courier, monospace;background-color:#f4f4f4;text-align:left;border-style:none;padding:0px;"&gt;&lt;span style="color:#0000ff;"&gt;END&lt;/span&gt; CATCH;&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;This gives you same results as above.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;You can also use it with a procedure like if you have some kind of procedure than you want to associate with it 
  &lt;br /&gt;Try()&amp;hellip;Catch() block then do something like that&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;First create a Procedure which contains SQL statements to do a specific task, i made a Store procedure which select all the data from a table which doesn&amp;rsquo;t present in the database&amp;nbsp; &lt;/p&gt;
&lt;div id="codeSnippetWrapper"&gt;
&lt;div id="codeSnippet" style="font-size:8pt;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:&amp;#39;Courier New&amp;#39;, courier, monospace;background-color:#f4f4f4;text-align:left;border-style:none;padding:0px;"&gt;
&lt;pre style="font-size:8pt;margin:0em;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:&amp;#39;Courier New&amp;#39;, courier, monospace;background-color:white;text-align:left;border-style:none;padding:0px;"&gt;&lt;span style="color:#0000ff;"&gt;CREATE&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;PROCEDURE&lt;/span&gt; Sp_ErrorTest&lt;/pre&gt;

&lt;pre style="font-size:8pt;margin:0em;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:&amp;#39;Courier New&amp;#39;, courier, monospace;background-color:#f4f4f4;text-align:left;border-style:none;padding:0px;"&gt;&lt;span style="color:#0000ff;"&gt;AS&lt;/span&gt;&lt;/pre&gt;

&lt;pre style="font-size:8pt;margin:0em;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:&amp;#39;Courier New&amp;#39;, courier, monospace;background-color:white;text-align:left;border-style:none;padding:0px;"&gt;    &lt;span style="color:#0000ff;"&gt;SELECT&lt;/span&gt; * &lt;span style="color:#0000ff;"&gt;FROM&lt;/span&gt; NonexistentTable;&lt;/pre&gt;

&lt;pre style="font-size:8pt;margin:0em;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:&amp;#39;Courier New&amp;#39;, courier, monospace;background-color:#f4f4f4;text-align:left;border-style:none;padding:0px;"&gt;&lt;span style="color:#0000ff;"&gt;GO&lt;/span&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;then do like this&amp;hellip;.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;div id="codeSnippetWrapper"&gt;
&lt;div id="codeSnippet" style="font-size:8pt;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:&amp;#39;Courier New&amp;#39;, courier, monospace;background-color:#f4f4f4;text-align:left;border-style:none;padding:0px;"&gt;
&lt;pre style="font-size:8pt;margin:0em;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:&amp;#39;Courier New&amp;#39;, courier, monospace;background-color:white;text-align:left;border-style:none;padding:0px;"&gt;&lt;span style="color:#0000ff;"&gt;BEGIN&lt;/span&gt; TRY&lt;/pre&gt;

&lt;pre style="font-size:8pt;margin:0em;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:&amp;#39;Courier New&amp;#39;, courier, monospace;background-color:#f4f4f4;text-align:left;border-style:none;padding:0px;"&gt;    &lt;span style="color:#0000ff;"&gt;EXECUTE&lt;/span&gt; usp_ExampleProc&lt;/pre&gt;

&lt;pre style="font-size:8pt;margin:0em;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:&amp;#39;Courier New&amp;#39;, courier, monospace;background-color:white;text-align:left;border-style:none;padding:0px;"&gt;&lt;span style="color:#0000ff;"&gt;END&lt;/span&gt; TRY&lt;/pre&gt;

&lt;pre style="font-size:8pt;margin:0em;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:&amp;#39;Courier New&amp;#39;, courier, monospace;background-color:#f4f4f4;text-align:left;border-style:none;padding:0px;"&gt;&lt;span style="color:#0000ff;"&gt;BEGIN&lt;/span&gt; CATCH&lt;/pre&gt;

&lt;pre style="font-size:8pt;margin:0em;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:&amp;#39;Courier New&amp;#39;, courier, monospace;background-color:white;text-align:left;border-style:none;padding:0px;"&gt;     &lt;span style="color:#0000ff;"&gt;EXECUTE&lt;/span&gt; Sp_ThrowErrorInfo&lt;/pre&gt;

&lt;pre style="font-size:8pt;margin:0em;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:&amp;#39;Courier New&amp;#39;, courier, monospace;background-color:#f4f4f4;text-align:left;border-style:none;padding:0px;"&gt;&lt;span style="color:#0000ff;"&gt;END&lt;/span&gt; CATCH;&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;This will show you error,, so in this way you can use Store Procedures in Error Handling&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;There are many kind of errors which you able to trace with Try()&amp;hellip;Catch() statements in T-SQL&lt;/p&gt;
&lt;p&gt;The following system functions can be used to obtain information about the error that CATCH block&amp;nbsp; to be executed:&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;ERROR_NUMBER()&lt;/strong&gt; returns the number of the error.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;ERROR_SEVERITY()&lt;/strong&gt; returns the severity.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;ERROR_STATE()&lt;/strong&gt; returns the error state number.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;ERROR_PROCEDURE()&lt;/strong&gt; returns the name of the stored procedure or trigger where the error occurred.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;ERROR_LINE()&lt;/strong&gt; returns the line number inside the routine that caused the error.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;ERROR_MESSAGE()&lt;/strong&gt; returns the complete text of the error message. The text includes the values supplied for any substitutable parameters, such as lengths, object names, or times.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;If these functions are used outside the CATCH block, then all of them will return NULL value.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;You can also use Try()..Catch() statement&amp;nbsp; to handle errors that occur inside a transaction, by checking the value of&amp;nbsp; XACT_STATE . The XACT_STATE function determines whether the transaction should be committed or rolled back.&lt;/p&gt;
&lt;p&gt;You can use XACT_STATE_ABORT is on, this makes transaction uncommittable when error occurs..&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;If XACT_STATE =1 , transaction is committable.&lt;/p&gt;
&lt;p&gt;If XACT_STATE=-1, the transaction is uncommittable and should be rolled back.&lt;/p&gt;
&lt;p&gt;If XACT_STATE=0, means that there is no transaction and a commit or rollback operation would generate an error.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;In this way there is a lot more to do in error handling, and there are commands which give you very fine-grained control over small set of errors.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Thanks..&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://beyondrelational.com/aggbug.aspx?PostID=101" width="1" height="1"&gt;&lt;img src="http://feeds.feedburner.com/~r/AshishsBlog/~4/6KGWS6iCaUk" height="1" width="1"/&gt;</description><category domain="http://beyondrelational.com/blogs/ashish/archive/tags/T-SQL/default.aspx">T-SQL</category><category domain="http://beyondrelational.com/blogs/ashish/archive/tags/SQL/default.aspx">SQL</category><category domain="http://beyondrelational.com/blogs/ashish/archive/tags/ErrorHandling/default.aspx">ErrorHandling</category><category domain="http://beyondrelational.com/blogs/ashish/archive/tags/SQLSERVER-2005/default.aspx">SQLSERVER-2005</category><feedburner:origLink>http://beyondrelational.com/blogs/ashish/archive/2009/05/09/error-exception-handling-in-sql-server-2005.aspx</feedburner:origLink></item><item><title>Generating Unique Random Numeric and Alpha Numeric Values</title><link>http://feedproxy.google.com/~r/AshishsBlog/~3/HnBt0kVPd7I/generating-unique-random-numeric-and-alpha-numeric-values.aspx</link><pubDate>Wed, 06 May 2009 09:20:00 GMT</pubDate><guid isPermaLink="false">6e5011fa-7db5-4df3-bb79-9085c1d333b3:85</guid><dc:creator>Ashish Gilhotra</dc:creator><slash:comments>0</slash:comments><wfw:commentRss>http://beyondrelational.com/blogs/ashish/rsscomments.aspx?PostID=85</wfw:commentRss><comments>http://beyondrelational.com/blogs/ashish/archive/2009/05/06/generating-unique-random-numeric-and-alpha-numeric-values.aspx#comments</comments><description>&lt;p&gt;Hi&amp;hellip;&lt;/p&gt;
&lt;p&gt;In this post , I showed a way to generate 8 characters numeric and alpha numeric values.This can be useful in situations where one has to allocate passwords or unique id to users.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Here is a way in SQL to generate Random, Unique and Reliable Alpha Numeric Values..&lt;/p&gt;
&lt;div id="codeSnippetWrapper"&gt;
&lt;div style="font-size:8pt;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:&amp;#39;Courier New&amp;#39;, courier, monospace;background-color:#f4f4f4;text-align:left;border-style:none;padding:0px;" id="codeSnippet"&gt;
&lt;pre style="font-size:8pt;margin:0em;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:&amp;#39;Courier New&amp;#39;, courier, monospace;background-color:white;text-align:left;border-style:none;padding:0px;"&gt;&lt;span style="color:#0000ff;"&gt;SELECT&lt;/span&gt;  NEWID()&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;This always give you unique, random values but as the length of the&amp;nbsp; data as a result of this is too large so its not easy to remember that.&lt;/p&gt;
&lt;p&gt;So if you want to Generate 8 characters Numeric or Alpha Numeric values then here is the script for that.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;By this script you generate 8 characters Numeric values &lt;/p&gt;
&lt;div id="codeSnippetWrapper"&gt;
&lt;div style="font-size:8pt;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:&amp;#39;Courier New&amp;#39;, courier, monospace;background-color:#f4f4f4;text-align:left;border-style:none;padding:0px;" id="codeSnippet"&gt;
&lt;pre style="font-size:8pt;margin:0em;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:&amp;#39;Courier New&amp;#39;, courier, monospace;background-color:white;text-align:left;border-style:none;padding:0px;"&gt;&lt;span style="color:#0000ff;"&gt;SELECT&lt;/span&gt; number/&lt;span style="color:#0000ff;"&gt;nullif&lt;/span&gt;(power(10,len(number)-8),0) &lt;span style="color:#0000ff;"&gt;AS&lt;/span&gt; number &lt;span style="color:#0000ff;"&gt;FROM&lt;/span&gt;&lt;/pre&gt;

&lt;pre style="font-size:8pt;margin:0em;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:&amp;#39;Courier New&amp;#39;, courier, monospace;background-color:#f4f4f4;text-align:left;border-style:none;padding:0px;"&gt;(&lt;/pre&gt;

&lt;pre style="font-size:8pt;margin:0em;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:&amp;#39;Courier New&amp;#39;, courier, monospace;background-color:white;text-align:left;border-style:none;padding:0px;"&gt;    &lt;span style="color:#0000ff;"&gt;SELECT&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;TOP&lt;/span&gt; 1 ABS(CHECKSUM(NEWID())) &lt;span style="color:#0000ff;"&gt;AS&lt;/span&gt; number&lt;/pre&gt;

&lt;pre style="font-size:8pt;margin:0em;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:&amp;#39;Courier New&amp;#39;, courier, monospace;background-color:#f4f4f4;text-align:left;border-style:none;padding:0px;"&gt;    &lt;span style="color:#0000ff;"&gt;FROM&lt;/span&gt; sysobjects s1 &lt;span style="color:#0000ff;"&gt;cross&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;join&lt;/span&gt; sysobjects s2&lt;/pre&gt;

&lt;pre style="font-size:8pt;margin:0em;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:&amp;#39;Courier New&amp;#39;, courier, monospace;background-color:white;text-align:left;border-style:none;padding:0px;"&gt;) &lt;span style="color:#0000ff;"&gt;AS&lt;/span&gt; T&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;and here is the Script for generating 8 characters Alpha Numeric values .&lt;/p&gt;
&lt;div id="codeSnippetWrapper"&gt;
&lt;div style="font-size:8pt;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:&amp;#39;Courier New&amp;#39;, courier, monospace;background-color:#f4f4f4;text-align:left;border-style:none;padding:0px;" id="codeSnippet"&gt;
&lt;pre style="font-size:8pt;margin:0em;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:&amp;#39;Courier New&amp;#39;, courier, monospace;background-color:white;text-align:left;border-style:none;padding:0px;"&gt;&lt;span style="color:#0000ff;"&gt;DECLARE&lt;/span&gt; @alpha_numeric &lt;span style="color:#0000ff;"&gt;VARCHAR&lt;/span&gt;(8)&lt;/pre&gt;

&lt;pre style="font-size:8pt;margin:0em;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:&amp;#39;Courier New&amp;#39;, courier, monospace;background-color:#f4f4f4;text-align:left;border-style:none;padding:0px;"&gt;&lt;span style="color:#0000ff;"&gt;SET&lt;/span&gt; @alpha_numeric=&lt;span style="color:#006080;"&gt;&amp;#39;&amp;#39;&lt;/span&gt;&lt;/pre&gt;

&lt;pre style="font-size:8pt;margin:0em;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:&amp;#39;Courier New&amp;#39;, courier, monospace;background-color:white;text-align:left;border-style:none;padding:0px;"&gt;&lt;span style="color:#0000ff;"&gt;SELECT&lt;/span&gt; @alpha_numeric=@alpha_numeric+&lt;span style="color:#0000ff;"&gt;CHAR&lt;/span&gt;(n) &lt;span style="color:#0000ff;"&gt;FROM&lt;/span&gt;&lt;/pre&gt;

&lt;pre style="font-size:8pt;margin:0em;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:&amp;#39;Courier New&amp;#39;, courier, monospace;background-color:#f4f4f4;text-align:left;border-style:none;padding:0px;"&gt;(&lt;/pre&gt;

&lt;pre style="font-size:8pt;margin:0em;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:&amp;#39;Courier New&amp;#39;, courier, monospace;background-color:white;text-align:left;border-style:none;padding:0px;"&gt;    &lt;span style="color:#0000ff;"&gt;SELECT&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;TOP&lt;/span&gt; 8 number &lt;span style="color:#0000ff;"&gt;AS&lt;/span&gt; n &lt;span style="color:#0000ff;"&gt;FROM&lt;/span&gt; master..spt_values&lt;/pre&gt;

&lt;pre style="font-size:8pt;margin:0em;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:&amp;#39;Courier New&amp;#39;, courier, monospace;background-color:#f4f4f4;text-align:left;border-style:none;padding:0px;"&gt;    &lt;span style="color:#0000ff;"&gt;WHERE&lt;/span&gt; TYPE=&lt;span style="color:#006080;"&gt;&amp;#39;p&amp;#39;&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;and&lt;/span&gt; (number &lt;span style="color:#0000ff;"&gt;between&lt;/span&gt; 48 &lt;span style="color:#0000ff;"&gt;and&lt;/span&gt; 57 &lt;span style="color:#0000ff;"&gt;or&lt;/span&gt; number &lt;span style="color:#0000ff;"&gt;between&lt;/span&gt; 65 &lt;span style="color:#0000ff;"&gt;and&lt;/span&gt; 90)&lt;/pre&gt;

&lt;pre style="font-size:8pt;margin:0em;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:&amp;#39;Courier New&amp;#39;, courier, monospace;background-color:white;text-align:left;border-style:none;padding:0px;"&gt;    &lt;span style="color:#0000ff;"&gt;ORDER&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;BY&lt;/span&gt; NEWID()&lt;/pre&gt;

&lt;pre style="font-size:8pt;margin:0em;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:&amp;#39;Courier New&amp;#39;, courier, monospace;background-color:#f4f4f4;text-align:left;border-style:none;padding:0px;"&gt;) &lt;span style="color:#0000ff;"&gt;AS&lt;/span&gt; t&lt;/pre&gt;

&lt;pre style="font-size:8pt;margin:0em;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:&amp;#39;Courier New&amp;#39;, courier, monospace;background-color:white;text-align:left;border-style:none;padding:0px;"&gt;&amp;nbsp;&lt;/pre&gt;

&lt;pre style="font-size:8pt;margin:0em;overflow:visible;width:100%;color:black;direction:ltr;line-height:12pt;font-family:&amp;#39;Courier New&amp;#39;, courier, monospace;background-color:#f4f4f4;text-align:left;border-style:none;padding:0px;"&gt;&lt;span style="color:#0000ff;"&gt;SELECT&lt;/span&gt; @alpha_numeric&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;So in this way you generate 8 characters Numeric and Alpha Numeric values&amp;hellip;&lt;/p&gt;
&lt;p&gt;You can also change the length of your String by Alter some values in above script.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Thanks&amp;hellip; &lt;/p&gt;
&lt;div style="padding-right:0px;display:inline;padding-left:0px;float:none;padding-bottom:0px;margin:0px;padding-top:0px;" id="scid:0767317B-992E-4b12-91E0-4F059A8CECA8:00f59e1b-8f4f-4f9a-8114-500d70cb9f8e" class="wlWriterEditableSmartContent"&gt;Technorati Tags: &lt;a rel="tag" href="http://technorati.com/tags/SQL"&gt;SQL&lt;/a&gt;,&lt;a rel="tag" href="http://technorati.com/tags/T-SQL"&gt;T-SQL&lt;/a&gt;,&lt;a rel="tag" href="http://technorati.com/tags/Random+Numbers"&gt;Random Numbers&lt;/a&gt;&lt;/div&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://beyondrelational.com/aggbug.aspx?PostID=85" width="1" height="1"&gt;&lt;img src="http://feeds.feedburner.com/~r/AshishsBlog/~4/HnBt0kVPd7I" height="1" width="1"/&gt;</description><feedburner:origLink>http://beyondrelational.com/blogs/ashish/archive/2009/05/06/generating-unique-random-numeric-and-alpha-numeric-values.aspx</feedburner:origLink></item></channel></rss>

