<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://beyondrelational.com/live/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Search results matching tag 'SQL'</title><link>http://beyondrelational.com/live/search/SearchResults.aspx?a=1&amp;o=DateDescending&amp;tag=SQL&amp;orTags=0</link><description>Search results matching tag 'SQL'</description><dc:language>en-US</dc:language><generator>CommunityServer 2008.5 SP1 (Build: 31106.3070)</generator><item><title>One more example - No order guaranteed if order by is not specified</title><link>http://beyondrelational.com/live/blogs/chintak/archive/2012/04/13/one-more-example-no-order-guaranteed-if-order-by-is-not-specified.aspx</link><pubDate>Fri, 13 Apr 2012 16:43:00 GMT</pubDate><guid isPermaLink="false">6e5011fa-7db5-4df3-bb79-9085c1d333b3:15611</guid><dc:creator>chhapia_chintak</dc:creator><description>&lt;p&gt;As we know that, No order guaranteed if order by is notf &amp;nbsp;explcitly specified. Below is one more example of this.&lt;/p&gt;
&lt;p&gt;Below is the code to pupolate dummy table.&lt;/p&gt;
&lt;pre class="brush: sql"&gt;If OBJECT_ID(&amp;#39;dbo.testTable&amp;#39;) is not null 
	drop table dbo.testTable
Go
Create table dbo.testTable
( c1 int not null,
c2 int not null,
c3 int not null,
c4 int not null)
go
Alter table dbo.testTable add constraint pk_testTable primary key (c1)
go
declare @i int
select @i = 1

set nocount on;
begin tran

while (@i &amp;lt; 1001)
begin
	insert into testTable (c1,c2,c3,c4)
	select @i, @i/2, 10000-(@i/4), @i%2

	select @i = @i + 1
end
commit
go
&lt;/pre&gt;
&lt;p&gt;Now, when we run below query, have a look at rows returned&lt;/p&gt;
&lt;pre class="brush: sql"&gt;select * from testTable
&lt;/pre&gt;
&lt;p&gt;Below is the truncated result of this query.&lt;/p&gt;
&lt;p&gt;&lt;a href="http://beyondrelational.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/chintak/OrderBy1.PNG"&gt;&lt;img src="http://beyondrelational.com/resized-image.ashx/__size/550x0/__key/CommunityServer.Blogs.Components.WeblogFiles/chintak/OrderBy1.PNG" alt="Order By Example" border="0" style="border:1px solid black;" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Now, if we create covering below index and again look at the results, rows are returned in different orders.&lt;/p&gt;
&lt;pre class="brush: sql"&gt;Create index idx_testTable_c3 on testTable(c3) include (c1,c2,c4) 
go 
select * from testTable
&lt;/pre&gt;
&lt;p&gt;Below is the result returned after creating index&lt;/p&gt;
&lt;p&gt;&lt;a href="http://beyondrelational.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/chintak/OrderBy2.PNG"&gt;&lt;img src="http://beyondrelational.com/resized-image.ashx/__size/550x0/__key/CommunityServer.Blogs.Components.WeblogFiles/chintak/OrderBy2.PNG" alt="Order By example 2" border="0" style="border:1px solid black;" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Actually, SQL choose the plan which is the more efficient, when we run below queries, we are able to find the reason. &lt;/p&gt;
&lt;pre class="brush: sql"&gt;set statistics io on 
go 
select * from testTable with(index=0) 
go 
select * from testTable go
&lt;/pre&gt;
&lt;p&gt;Even we can look into why there are less pages when nonclustered index is used, with help of below query &lt;/p&gt;
&lt;pre class="brush: sql"&gt;select * from sys.dm_db_index_physical_stats(db_id(),object_id(&amp;#39;testTable&amp;#39;),NULL,NULL,&amp;#39;DETAILED&amp;#39;)
&lt;/pre&gt;</description></item><item><title>SQL Server - Changing Rows to Columns Using PIVOT</title><link>http://beyondrelational.com/live/blogs/paresh/archive/2012/02/18/sql-server-changing-rows-to-columns-using-pivot.aspx</link><pubDate>Sun, 19 Feb 2012 04:05:00 GMT</pubDate><guid isPermaLink="false">6e5011fa-7db5-4df3-bb79-9085c1d333b3:15409</guid><dc:creator>pprajapati</dc:creator><description>&lt;div dir="ltr" style="text-align:left;"&gt;
&lt;br /&gt;
During working with one logic, i got chance to work with PIVOT operation.&amp;nbsp;Sometime we need do require rowdata as column in our custom logic, then we can use some temp table and then populate agreegate data in temp table.&amp;nbsp;But With PIVOT we can do it very easily.&amp;nbsp;Let me prepare small example and explain as how how can we use PIVOT and get row data as column.&lt;br /&gt;
&lt;br /&gt;
Before go ahead to run the script of Pivot, we will create database and table objects.&lt;br /&gt;
&lt;br /&gt;
&lt;pre class="brush:sql"&gt;CREATE DATABASE DEMO
GO

USE DEMO
GO

-- Creating table for demo
IF (object_id(&amp;#39;TblPivot&amp;#39;,&amp;#39;U&amp;#39;) &amp;gt; 0)
DROP TABLE TblPivot

CREATE TABLE TblPivot
(
ItemCode int,
ItemName varchar(100),
ItemColour varchar(50)
)

GO

-- Inerting some sample records

INSERT INTO TblPivot
SELECT 1,&amp;#39;Samsung Mobile&amp;#39;,&amp;#39;Red&amp;#39;
UNION ALL
SELECT 2,&amp;#39;Nokia Mobile&amp;#39;,&amp;#39;Blue&amp;#39;
UNION ALL
SELECT 3,&amp;#39;Nokia Mobile&amp;#39;,&amp;#39;Green&amp;#39;
UNION ALL
SELECT 4,&amp;#39;Motorola Mobile&amp;#39;,&amp;#39;Red&amp;#39;
UNION ALL
SELECT 5,&amp;#39;Samsung Mobile&amp;#39;,&amp;#39;Green&amp;#39;
UNION ALL
SELECT 2,&amp;#39;Nokia Mobile&amp;#39;,&amp;#39;Blue&amp;#39;
UNION ALL
SELECT 1,&amp;#39;Samsung Mobile&amp;#39;,&amp;#39;Red&amp;#39;
UNION ALL
SELECT 2,&amp;#39;Nokia Mobile&amp;#39;,&amp;#39;Blue&amp;#39;

GO
&lt;/pre&gt;
&lt;br /&gt;
Now we will check the original table data and aggregated data using Pivot.&lt;br /&gt;
So we will run both script for the same.&lt;br /&gt;
&lt;br /&gt;
&lt;pre class="brush:sql"&gt;-- Getting table data
SELECT 
ItemCode, 
ItemName, 
ItemColour
from TblPivot
GO

-- Getting agreegated data using Pivot and converted rows to column
SELECT
*
 FROM
 (
    SELECT 
 ItemCode, 
 ItemName, 
 ItemColour
    FROM TblPivot
 ) AS P
PIVOT
(
  Count(ItemName) FOR ItemColour IN (Red, Blue, Green)
) AS pv

GO
&lt;/pre&gt;
&lt;br /&gt;
&lt;div class="separator" style="clear:both;text-align:left;"&gt;
&lt;a href="http://3.bp.blogspot.com/-nFQHUhQ1NaY/Tc5AtviktiI/AAAAAAAAAfo/yubOdwUfieA/s1600/Pivot_1.png" style="margin-left:1em;margin-right:1em;"&gt;&lt;img border="0" height="640" src="http://3.bp.blogspot.com/-nFQHUhQ1NaY/Tc5AtviktiI/AAAAAAAAAfo/yubOdwUfieA/s640/Pivot_1.png" width="512" alt="" /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
You can review here and see how the PIVOT is working. Let me share your experience with PIVOT operation.&lt;br /&gt;
&lt;/div&gt;</description></item><item><title>SSIS - Delete files older than retention period from folder with parameter using Script Task in SQL Server</title><link>http://beyondrelational.com/live/blogs/paresh/archive/2012/02/10/ssis-delete-files-older-than-retention-period-from-folder-with-parameter-using-script-task-in-sql-server.aspx</link><pubDate>Fri, 10 Feb 2012 14:03:00 GMT</pubDate><guid isPermaLink="false">6e5011fa-7db5-4df3-bb79-9085c1d333b3:15382</guid><dc:creator>pprajapati</dc:creator><description>&lt;div dir="ltr" style="text-align:left;"&gt;
After using some of the ways to delete the files from the&amp;nbsp;particular&amp;nbsp;folder like&amp;nbsp;&lt;a href="http://beyondrelational.com/blogs/paresh/archive/2011/12/30/ssis-delete-files-from-specified-folder-using-script-task-in-sql-server.aspx" target="_blank"&gt;&lt;strong&gt;Delete file using Script Task&lt;/strong&gt;&lt;/a&gt; and &amp;nbsp;&lt;a href="http://beyondrelational.com/blogs/paresh/archive/2011/12/23/ssis-delete-files-from-specified-folder-using-file-system-task-in-sql-server.aspx" target="_blank"&gt;&lt;strong&gt;File System Task&lt;/strong&gt;&lt;/a&gt; in SSIS. We have seen such methods and used&amp;nbsp;logic to get the files from the loop container and process to delete them and same thing applied for the scripts as well.&amp;nbsp;we also looked for the files deletion which are older than some&lt;strong&gt;&lt;span style="text-decoration:underline;"&gt;&amp;nbsp;&lt;a href="http://beyondrelational.com/blogs/paresh/archive/2012/02/04/ssis-delete-files-older-than-retention-period-from-specified-folder-using-script-task-in-sql-server.aspx" target="_blank"&gt;Retention&amp;nbsp;period with Script Task&lt;/a&gt;&lt;/span&gt;&lt;/strong&gt; also.&lt;br /&gt;
&lt;br /&gt;
In earlier posts we have not used any parameters in the scripts and directly applied folder path and retention period values there. But here i would like to use parameters for the folder path and&amp;nbsp;retention&amp;nbsp;period and pass through the scripts and delete them as per condition.&lt;br /&gt;
&lt;br /&gt;
1. Let check the files from the target folder.&lt;br /&gt;
&lt;br /&gt;
&lt;div class="separator" style="clear:both;text-align:center;"&gt;
&lt;/div&gt;
&lt;div class="separator" style="clear:both;text-align:center;"&gt;
&lt;a href="http://1.bp.blogspot.com/-U4Ss7HEZyvU/TvM69jF50NI/AAAAAAAABMA/U40LUTPZo9g/s1600/deletefile4_0.png" style="clear:left;float:left;margin-bottom:1em;margin-right:1em;"&gt;&lt;img border="0" height="312" src="http://1.bp.blogspot.com/-U4Ss7HEZyvU/TvM69jF50NI/AAAAAAAABMA/U40LUTPZo9g/s640/deletefile4_0.png" width="640" alt="" /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;&lt;br /&gt;
&lt;br /&gt;&lt;br /&gt;
&lt;br /&gt;&lt;br /&gt;
&lt;br /&gt;&lt;br /&gt;
&lt;br /&gt;&lt;br /&gt;
&lt;br /&gt;&lt;br /&gt;
&lt;br /&gt;&lt;br /&gt;
&lt;br /&gt;&lt;br /&gt;
&lt;br /&gt;&lt;br /&gt;
&lt;br /&gt;&lt;br /&gt;
&lt;br /&gt;&lt;br /&gt;
2. Create parameters and set the values. Here it is going to be delete the files which are older then 3 days from the&amp;nbsp;E:\ImagesBackup folder in this case.&lt;br /&gt;
&lt;br /&gt;
&lt;div class="separator" style="clear:both;text-align:center;"&gt;
&lt;/div&gt;
&lt;div class="separator" style="clear:both;text-align:center;"&gt;
&lt;/div&gt;
&lt;div class="separator" style="clear:both;text-align:center;"&gt;
&lt;a href="http://2.bp.blogspot.com/-FcJ1ygMy1mE/TvM7sJR_jII/AAAAAAAABM0/3ErvmvY1XrE/s1600/deletefile4_1.png" style="clear:left;float:left;margin-bottom:1em;margin-right:1em;"&gt;&lt;img border="0" height="140" src="http://2.bp.blogspot.com/-FcJ1ygMy1mE/TvM7sJR_jII/AAAAAAAABM0/3ErvmvY1XrE/s640/deletefile4_1.png" width="640" alt="" /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;&lt;br /&gt;
&lt;br /&gt;&lt;br /&gt;
&lt;br /&gt;&lt;br /&gt;
&lt;br /&gt;&lt;br /&gt;
&lt;br /&gt;&lt;br /&gt;
&lt;br /&gt;
3. Drag and drop File System Task&lt;br /&gt;
&lt;br /&gt;
&lt;div class="separator" style="clear:both;text-align:center;"&gt;
&lt;/div&gt;
&lt;div class="separator" style="clear:both;text-align:center;"&gt;
&lt;/div&gt;
&lt;div class="separator" style="clear:both;text-align:center;"&gt;
&lt;a href="http://3.bp.blogspot.com/-CyTAkEEkW1M/TvM76LwEgnI/AAAAAAAABNA/ajEwKxBt9Nk/s1600/deletefile4_2.png" style="clear:left;float:left;margin-bottom:1em;margin-right:1em;"&gt;&lt;img border="0" height="270" src="http://3.bp.blogspot.com/-CyTAkEEkW1M/TvM76LwEgnI/AAAAAAAABNA/ajEwKxBt9Nk/s640/deletefile4_2.png" width="640" alt="" /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;&lt;br /&gt;
&lt;br /&gt;&lt;br /&gt;
&lt;br /&gt;&lt;br /&gt;
&lt;br /&gt;&lt;br /&gt;
&lt;br /&gt;&lt;br /&gt;
&lt;br /&gt;&lt;br /&gt;
&lt;br /&gt;&lt;br /&gt;
&lt;br /&gt;&lt;br /&gt;
&lt;br /&gt;&lt;br /&gt;
&lt;br /&gt;
4. Put the parameters as ReadOnlyVariables&lt;br /&gt;
&lt;br /&gt;
&lt;div class="separator" style="clear:both;text-align:center;"&gt;
&lt;a href="http://3.bp.blogspot.com/-YVP1uU7witM/TvM8bOuAVCI/AAAAAAAABNM/Vj-O9qZ8lXk/s1600/deletefile4_3.png" style="clear:left;float:left;margin-bottom:1em;margin-right:1em;"&gt;&lt;img border="0" height="542" src="http://3.bp.blogspot.com/-YVP1uU7witM/TvM8bOuAVCI/AAAAAAAABNM/Vj-O9qZ8lXk/s640/deletefile4_3.png" width="640" alt="" /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;&lt;br /&gt;
&lt;br /&gt;&lt;br /&gt;
&lt;br /&gt;&lt;br /&gt;
&lt;br /&gt;&lt;br /&gt;
&lt;br /&gt;&lt;br /&gt;
&lt;br /&gt;&lt;br /&gt;
&lt;br /&gt;&lt;br /&gt;
&lt;br /&gt;&lt;br /&gt;
&lt;br /&gt;&lt;br /&gt;
&lt;br /&gt;&lt;br /&gt;
&lt;br /&gt;&lt;br /&gt;
&lt;br /&gt;&lt;br /&gt;
&lt;br /&gt;&lt;br /&gt;
&lt;br /&gt;&lt;br /&gt;
&lt;br /&gt;&lt;br /&gt;
&lt;br /&gt;&lt;br /&gt;
&lt;br /&gt;&lt;br /&gt;
&lt;br /&gt;&lt;br /&gt;
&lt;br /&gt;
5. Apply attached script in editor which have additional logic with condition to check the file lat&amp;nbsp;modified&amp;nbsp;date and check if older than specified retention period or not. Here you can see the parameters used in the script.&lt;br /&gt;
&lt;br /&gt;
&lt;div class="separator" style="clear:both;text-align:center;"&gt;
&lt;/div&gt;
&lt;div class="separator" style="clear:both;text-align:center;"&gt;
&lt;/div&gt;
&lt;div class="separator" style="clear:both;text-align:center;"&gt;
&lt;a href="http://1.bp.blogspot.com/-AnTo_WNfcOQ/TvM8rjPMM5I/AAAAAAAABNY/0RjlglyP5Xw/s1600/deletefile4_4.png" style="clear:left;float:left;margin-bottom:1em;margin-right:1em;"&gt;&lt;img border="0" height="368" src="http://1.bp.blogspot.com/-AnTo_WNfcOQ/TvM8rjPMM5I/AAAAAAAABNY/0RjlglyP5Xw/s640/deletefile4_4.png" width="640" alt="" /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;&lt;br /&gt;
&lt;br /&gt;&lt;br /&gt;
&lt;br /&gt;&lt;br /&gt;
&lt;br /&gt;&lt;br /&gt;
&lt;br /&gt;&lt;br /&gt;
&lt;br /&gt;&lt;br /&gt;
&lt;br /&gt;&lt;br /&gt;
&lt;br /&gt;&lt;br /&gt;
&lt;br /&gt;&lt;br /&gt;
&lt;br /&gt;&lt;br /&gt;
&lt;br /&gt;&lt;br /&gt;
&lt;br /&gt;&lt;br /&gt;
&lt;br /&gt;&lt;br /&gt;
&lt;span style="color:#0b5394;"&gt;Please note here we need to import system.IO namespace.&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
6. Turn on final step and run package. Files older than specified retention period&amp;nbsp;get deleted.&lt;br /&gt;
&lt;br /&gt;
&lt;div class="separator" style="clear:both;text-align:center;"&gt;
&lt;a href="http://2.bp.blogspot.com/-sc_dCAhT6mY/TvM8xEHV6LI/AAAAAAAABNk/bk-yUwdhK8k/s1600/deletefile4_5.png" style="clear:left;float:left;margin-bottom:1em;margin-right:1em;"&gt;&lt;img border="0" height="430" src="http://2.bp.blogspot.com/-sc_dCAhT6mY/TvM8xEHV6LI/AAAAAAAABNk/bk-yUwdhK8k/s640/deletefile4_5.png" width="640" alt="" /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;div class="separator" style="clear:both;text-align:center;"&gt;
&lt;/div&gt;
&lt;div class="separator" style="clear:both;text-align:center;"&gt;
&lt;/div&gt;
&lt;br /&gt;
You &amp;nbsp;can use the script below for the same as mentioned in above image,&lt;br /&gt;
&lt;br /&gt;
&lt;pre class="brush:sql"&gt;--// You need to apply below one line in &amp;quot;namespaces&amp;quot; region.
using System.IO;

--//You need to apply below lines inplace of &amp;nbsp;// TODO: Add your code here
int RetentionPeriod = Convert.ToInt32(Dts.Variables[&amp;quot;User::Period&amp;quot;].Value.ToString());
string directoryPath = Dts.Variables[&amp;quot;User::BackupFolder&amp;quot;].Value.ToString();
string[] oldFiles = System.IO.Directory.GetFiles(directoryPath, &amp;quot;*.*&amp;quot;);

foreach (string currFile in oldFiles)
  {
         FileInfo currFileInfo = new FileInfo(currFile);
              
            if (currFileInfo.LastWriteTime &amp;lt; (DateTime.Now.AddDays(-RetentionPeriod)))
                {
                    currFileInfo.Delete();
                }
            }
&lt;/pre&gt;
Hope you liked this post. Stay tuned for more.  &lt;/div&gt;</description></item><item><title>SSIS - Delete files older than retention period from specified folder using Script Task in SQL Server</title><link>http://beyondrelational.com/live/blogs/paresh/archive/2012/02/04/ssis-delete-files-older-than-retention-period-from-specified-folder-using-script-task-in-sql-server.aspx</link><pubDate>Sat, 04 Feb 2012 13:18:00 GMT</pubDate><guid isPermaLink="false">6e5011fa-7db5-4df3-bb79-9085c1d333b3:15316</guid><dc:creator>pprajapati</dc:creator><description>&lt;div dir="ltr" style="text-align:left;"&gt;
Earlier we have seen for the &lt;a href="http://beyondrelational.com/blogs/paresh/archive/2011/12/30/ssis-delete-files-from-specified-folder-using-script-task-in-sql-server.aspx" target="_blank"&gt;&lt;span style="font-size:large;"&gt;Delete file using Script Task&lt;/span&gt;&lt;/a&gt; and&amp;nbsp;&lt;a href="http://beyondrelational.com/blogs/paresh/archive/2011/12/23/ssis-delete-files-from-specified-folder-using-file-system-task-in-sql-server.aspx" target="_blank"&gt;&lt;span style="font-size:large;"&gt;files deletion using File System Task&lt;/span&gt;&lt;/a&gt; in SSIS. We have directly wrote the logic to get the files and delete from specified folder in the script for the Script Task. For File System Task we have Used Foreach Loop Container and variables to hold file names which are passed from earlier stage one by one and then finally used with File System Task to delete it.&lt;br /&gt;
&lt;br /&gt;
Here we have same but not to delete all the files inside passed folder but get deleted files which are older than specified days. This is nothing but minor change in script where we pass the folder path and retention period. Lets start the steps as following,&lt;br /&gt;
&lt;br /&gt;
1. Let check the files from the target folder.&lt;br /&gt;
&lt;br /&gt;
&lt;div class="separator" style="clear:both;text-align:center;"&gt;
&lt;a href="http://2.bp.blogspot.com/-FlO0C9E5IFU/TushRopSsMI/AAAAAAAABKs/T-AdTCQUUdA/s1600/deletefile3_0.png" style="clear:left;float:left;margin-bottom:1em;margin-right:1em;"&gt;&lt;img border="0" height="272" src="http://2.bp.blogspot.com/-FlO0C9E5IFU/TushRopSsMI/AAAAAAAABKs/T-AdTCQUUdA/s640/deletefile3_0.png" width="640" alt="" /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;&lt;br /&gt;
&lt;br /&gt;&lt;br /&gt;
&lt;br /&gt;&lt;br /&gt;
&lt;br /&gt;&lt;br /&gt;
&lt;br /&gt;&lt;br /&gt;
&lt;br /&gt;&lt;br /&gt;
&lt;br /&gt;&lt;br /&gt;
&lt;br /&gt;&lt;br /&gt;
&lt;br /&gt;&lt;br /&gt;
&lt;br /&gt;&lt;br /&gt;
2. Drag and drop Script Task.&lt;br /&gt;
&lt;br /&gt;
&lt;div class="separator" style="clear:both;text-align:center;"&gt;
&lt;/div&gt;
&lt;div class="separator" style="clear:both;text-align:center;"&gt;
&lt;a href="http://1.bp.blogspot.com/-gOKw4ZrAsfQ/TushcJrTheI/AAAAAAAABK0/shWADAXV0FM/s1600/deletefile3_1.png" style="clear:left;float:left;margin-bottom:1em;margin-right:1em;"&gt;&lt;img border="0" height="346" src="http://1.bp.blogspot.com/-gOKw4ZrAsfQ/TushcJrTheI/AAAAAAAABK0/shWADAXV0FM/s640/deletefile3_1.png" width="640" alt="" /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;&lt;br /&gt;
&lt;br /&gt;&lt;br /&gt;
&lt;br /&gt;&lt;br /&gt;
&lt;br /&gt;&lt;br /&gt;
&lt;br /&gt;&lt;br /&gt;
&lt;br /&gt;&lt;br /&gt;
&lt;br /&gt;&lt;br /&gt;
&lt;br /&gt;&lt;br /&gt;
&lt;br /&gt;&lt;br /&gt;
&lt;br /&gt;&lt;br /&gt;
&lt;br /&gt;&lt;br /&gt;
&lt;br /&gt;&lt;br /&gt;
3. Open script editor from the properties.&lt;br /&gt;
&lt;br /&gt;
&lt;div class="separator" style="clear:both;text-align:center;"&gt;
&lt;/div&gt;
&lt;div class="separator" style="clear:both;text-align:center;"&gt;
&lt;a href="http://2.bp.blogspot.com/-SP5FhW40Ls8/TushiqK2JbI/AAAAAAAABK8/pOUQM8wHuSE/s1600/deletefile3_2.png" style="clear:left;float:left;margin-bottom:1em;margin-right:1em;"&gt;&lt;img border="0" height="544" src="http://2.bp.blogspot.com/-SP5FhW40Ls8/TushiqK2JbI/AAAAAAAABK8/pOUQM8wHuSE/s640/deletefile3_2.png" width="640" alt="" /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;&lt;br /&gt;
&lt;br /&gt;&lt;br /&gt;
&lt;br /&gt;&lt;br /&gt;
&lt;br /&gt;&lt;br /&gt;
&lt;br /&gt;&lt;br /&gt;
&lt;br /&gt;&lt;br /&gt;
&lt;br /&gt;&lt;br /&gt;
&lt;br /&gt;&lt;br /&gt;
&lt;br /&gt;&lt;br /&gt;
&lt;br /&gt;&lt;br /&gt;
&lt;br /&gt;&lt;br /&gt;
&lt;br /&gt;&lt;br /&gt;
&lt;br /&gt;&lt;br /&gt;
&lt;br /&gt;&lt;br /&gt;
&lt;br /&gt;&lt;br /&gt;
&lt;br /&gt;&lt;br /&gt;
&lt;br /&gt;&lt;br /&gt;
&lt;br /&gt;&lt;br /&gt;
&lt;br /&gt;&lt;br /&gt;
4. Apply attached script in editor which have additional logic with condition to check the file lat&amp;nbsp;modified&amp;nbsp;date and check if older than specified retention period or not.&lt;br /&gt;
&lt;br /&gt;
&lt;div class="separator" style="clear:both;text-align:center;"&gt;
&lt;/div&gt;
&lt;div class="separator" style="clear:both;text-align:center;"&gt;
&lt;a href="http://4.bp.blogspot.com/-tCKDdklF7Po/TusiAyYl62I/AAAAAAAABLE/9G62pdnrnG0/s1600/deletefile3_3.png" style="clear:left;float:left;margin-bottom:1em;margin-right:1em;"&gt;&lt;img border="0" height="378" src="http://4.bp.blogspot.com/-tCKDdklF7Po/TusiAyYl62I/AAAAAAAABLE/9G62pdnrnG0/s640/deletefile3_3.png" width="640" alt="" /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;&lt;br /&gt;
&lt;br /&gt;&lt;br /&gt;
&lt;br /&gt;&lt;br /&gt;
&lt;br /&gt;&lt;br /&gt;
&lt;br /&gt;&lt;br /&gt;
&lt;br /&gt;&lt;br /&gt;
&lt;br /&gt;&lt;br /&gt;
&lt;br /&gt;&lt;br /&gt;
&lt;br /&gt;&lt;br /&gt;
&lt;br /&gt;&lt;br /&gt;
&lt;br /&gt;&lt;br /&gt;
&lt;br /&gt;&lt;br /&gt;
&lt;br /&gt;&lt;br /&gt;
&lt;span style="color:#0b5394;"&gt;Please note here we need to import system.IO namespace.&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
5. Turn on final step and run package. Files older than specified retention period&amp;nbsp;get deleted.&lt;br /&gt;
&lt;br /&gt;
&lt;div class="separator" style="clear:both;text-align:center;"&gt;
&lt;/div&gt;
&lt;div class="separator" style="clear:both;text-align:center;"&gt;
&lt;a href="http://4.bp.blogspot.com/-8QOxRoVrpAw/TusiMIb3b3I/AAAAAAAABLM/RXWA8Oe3Vm8/s1600/deletefile3_4.png" style="clear:left;float:left;margin-bottom:1em;margin-right:1em;"&gt;&lt;img border="0" height="472" src="http://4.bp.blogspot.com/-8QOxRoVrpAw/TusiMIb3b3I/AAAAAAAABLM/RXWA8Oe3Vm8/s640/deletefile3_4.png" width="640" alt="" /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;&lt;br /&gt;
&lt;br /&gt;&lt;br /&gt;
&lt;br /&gt;&lt;br /&gt;
&lt;br /&gt;&lt;br /&gt;
&lt;br /&gt;&lt;br /&gt;
&lt;br /&gt;&lt;br /&gt;
&lt;br /&gt;&lt;br /&gt;
&lt;br /&gt;&lt;br /&gt;
&lt;br /&gt;&lt;br /&gt;
&lt;br /&gt;&lt;br /&gt;
&lt;br /&gt;&lt;br /&gt;
&lt;br /&gt;&lt;br /&gt;
&lt;br /&gt;&lt;br /&gt;
&lt;br /&gt;&lt;br /&gt;
&lt;br /&gt;&lt;br /&gt;
&lt;br /&gt;&lt;br /&gt;
&lt;/div&gt;
&lt;p&gt;
You can also find script code here,&lt;/p&gt;
&lt;pre class="brush:sql"&gt;--// You need to apply below one line in &amp;quot;namespaces&amp;quot; region.
using System.IO;

--//You need to apply below lines inplace of &amp;nbsp;// TODO: Add your code here
int RetentionPeriod = 3;
string directoryPath = @&amp;quot;E:\ImagesBackup&amp;quot;;
string[] oldFiles = System.IO.Directory.GetFiles(directoryPath, &amp;quot;*.png&amp;quot;);
     foreach (string currFile in oldFiles)
            {
                FileInfo currFileInfo = new FileInfo(currFile);
                if (currFileInfo.LastWriteTime &amp;lt; (DateTime.Now.AddDays(-RetentionPeriod)))
                {
                    currFileInfo.Delete();
                }
            }
&lt;/pre&gt;
&lt;p&gt;
&lt;br /&gt;
&lt;br /&gt;
Hope you liked this post. Stay tuned for more.&lt;/p&gt;</description></item><item><title>Error encountered in SQL Server - Alter failed for Login sa. Cannot set a credential for principal 'sa'.</title><link>http://beyondrelational.com/live/blogs/paresh/archive/2012/01/27/error-encountered-in-sql-server-alter-failed-for-login-sa-cannot-set-a-credential-for-principal-sa.aspx</link><pubDate>Sat, 28 Jan 2012 02:19:00 GMT</pubDate><guid isPermaLink="false">6e5011fa-7db5-4df3-bb79-9085c1d333b3:15250</guid><dc:creator>pprajapati</dc:creator><description>&lt;div style="text-align:left;" dir="ltr"&gt;
Recently when i worked with SQL Server security, i encountered with one error while trying to modify &amp;#39;SA&amp;#39; account properties.&amp;nbsp;The exception details looks following,&lt;br /&gt;
&lt;blockquote class="tr_bq"&gt;
&lt;span style="color:red;"&gt;Alter failed for Login sa. Cannot set a credential for principal &amp;#39;sa&amp;#39;.&lt;/span&gt;&lt;/blockquote&gt;
Also you can see the image below for the same.&lt;br /&gt;
&lt;br /&gt;
&lt;div style="clear:both;text-align:center;" class="separator"&gt;
&lt;/div&gt;
&lt;div style="clear:both;text-align:center;" class="separator"&gt;
&lt;a style="clear:left;float:left;margin-bottom:1em;margin-right:1em;" href="http://1.bp.blogspot.com/-cs5kvqxb5wE/Txabq6UMTiI/AAAAAAAABZE/xWGnVRabAAw/s1600/SaEnable1.png"&gt;&lt;img width="640" src="http://1.bp.blogspot.com/-cs5kvqxb5wE/Txabq6UMTiI/AAAAAAAABZE/xWGnVRabAAw/s640/SaEnable1.png" height="576" border="0" alt="" /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;&lt;br /&gt;
&lt;br /&gt;&lt;br /&gt;
&lt;br /&gt;&lt;br /&gt;
&lt;br /&gt;&lt;br /&gt;
&lt;br /&gt;&lt;br /&gt;
&lt;br /&gt;&lt;br /&gt;
&lt;br /&gt;&lt;br /&gt;
&lt;br /&gt;&lt;br /&gt;
&lt;br /&gt;&lt;br /&gt;
&lt;br /&gt;&lt;br /&gt;
&lt;br /&gt;&lt;br /&gt;
&lt;br /&gt;&lt;br /&gt;
&lt;br /&gt;&lt;br /&gt;
&lt;br /&gt;&lt;br /&gt;
&lt;br /&gt;&lt;br /&gt;
&lt;br /&gt;&lt;br /&gt;
&lt;br /&gt;&lt;br /&gt;
&lt;br /&gt;&lt;br /&gt;
&lt;br /&gt;&lt;br /&gt;
&lt;br /&gt;&lt;br /&gt;
The &lt;span style="font-size:large;"&gt;&lt;strong&gt;fix&lt;/strong&gt; &lt;/span&gt;for the error is the option &amp;quot;&lt;span style="color:#0b5394;"&gt;&lt;strong&gt;Map to Credential&lt;/strong&gt;&lt;/span&gt;&amp;quot; is checked in the &amp;quot;General&amp;quot; tab of the Login Properties Page as mentioned below,&lt;br /&gt;
&lt;br /&gt;
&lt;div style="clear:both;text-align:center;" class="separator"&gt;
&lt;a style="clear:left;float:left;margin-bottom:1em;margin-right:1em;" href="http://3.bp.blogspot.com/-S1n5xSqGTsU/TxabcOPkHuI/AAAAAAAABY8/EeYQzhpnXKo/s1600/SaEnable2.png"&gt;&lt;img width="640" src="http://3.bp.blogspot.com/-S1n5xSqGTsU/TxabcOPkHuI/AAAAAAAABY8/EeYQzhpnXKo/s640/SaEnable2.png" height="574" border="0" alt="" /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;</description></item><item><title>Generate test data using DBGen</title><link>http://beyondrelational.com/live/blogs/geniiius/archive/2012/01/24/generate-test-data-using-dbgen.aspx</link><pubDate>Tue, 24 Jan 2012 06:00:00 GMT</pubDate><guid isPermaLink="false">6e5011fa-7db5-4df3-bb79-9085c1d333b3:15302</guid><dc:creator>Geniiius</dc:creator><description>&lt;p&gt;Over the last couple of months I have on several occasions found myself in need of test data for demos, blogposts etc. You all know AdventureWorks, which will work for a lot of demoing stuff. But the amount of data is limited, and if you are demoing stuff about performance, AdventureWorks just isn’t that good.&lt;/p&gt;
&lt;p&gt;I started looking around for tools, and thought I would have a look at &lt;a href="http://www.tpc.org"&gt;TPC&lt;/a&gt;.&amp;nbsp; My goal was not to be able to compare performance and transaction loads, but simply to generate data sets a bit bigger than AdventureWorks. So I found the TPC-H &lt;a href="http://www.tpc.org/tpch/spec/tpch_2_14_3.zip"&gt;DBGen&lt;/a&gt;. In this blog post I will show you step by step how to use that tool to generate a database with a set of tables with data volumes large enough to be able to demonstrate performance tuning stuff.&lt;/p&gt;
&lt;h2&gt;1. Download DBGen&lt;/h2&gt;
&lt;p&gt;Download DBGen from &lt;a title="http://www.tpc.org/tpch/spec/tpch_2_14_3.zip" href="http://www.tpc.org/tpch/spec/tpch_2_14_3.zip"&gt;http://www.tpc.org/tpch/spec/tpch_2_14_3.zip&lt;/a&gt; and extract it. In this guide I extracted the zip file to C:\tpch_2_14_3\&lt;/p&gt;
&lt;p&gt;&lt;a href="http://www.geniiius.com/wp-content/uploads/image43.png"&gt;&lt;img style="background-image:none;border-bottom:0px;border-left:0px;padding-left:0px;padding-right:0px;display:inline;border-top:0px;border-right:0px;padding-top:0px;" title="image" border="0" alt="image" src="http://www.geniiius.com/wp-content/uploads/image_thumb42.png" width="443" height="246" /&gt;&lt;/a&gt;&lt;br /&gt;This is the project that we need to build to get the executable.&lt;/p&gt;
&lt;h2&gt;2. Build the solution&lt;/h2&gt;
&lt;p&gt;Now open C:\tpch_2_14_3\dbgen\tpch.sln in Visual Studio. Depending on your Visual Studio version, you might be faced with a conversion wizard. Just click Finish to execute the conversion. All you need to do, is to build the entire solution. I had some errors because of some locked files, so I had to manually delete all files from the C:\tpch_2_14_3\dbgen\Debug folder before I could compile the solution. The result is the file C:\tpch_2_14_3\dbgen\Debug\dbgen.exe.&lt;/p&gt;
&lt;h2&gt;3. Generate data using dbgen.exe&lt;/h2&gt;
&lt;p&gt;Now we need to execution dbgen.exe. If we execute the command with –h we get some help:&lt;/p&gt;
&lt;p&gt;&lt;a href="http://www.geniiius.com/wp-content/uploads/image44.png"&gt;&lt;img style="background-image:none;border-bottom:0px;border-left:0px;padding-left:0px;padding-right:0px;display:inline;border-top:0px;border-right:0px;padding-top:0px;" title="image" border="0" alt="image" src="http://www.geniiius.com/wp-content/uploads/image_thumb43.png" width="555" height="489" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;If we simply run dbgen.exe, it default to generating 1 GB of data, divided into 8 different tables (customers, nation, lineitem, orders, parts, partsupp, region, supplier). The –s parameter specifies a scale factor, so –s 10 gives us 10GB, and –s 100 generates 100GB of data. Let’s just try the default:&lt;/p&gt;
&lt;p&gt;&lt;a href="http://www.geniiius.com/wp-content/uploads/image45.png"&gt;&lt;img style="background-image:none;border-bottom:0px;border-left:0px;padding-left:0px;padding-right:0px;display:inline;border-top:0px;border-right:0px;padding-top:0px;" title="image" border="0" alt="image" src="http://www.geniiius.com/wp-content/uploads/image_thumb44.png" width="561" height="116" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Whoops, we got an error! Why this is, I’m not sure, but I found the solution to be simple: Copy the file dbgen.exe one level up, so it is located in the C:\tpch_2_14_3\dbgen folder, and try again:&lt;/p&gt;
&lt;p&gt;&lt;a href="http://www.geniiius.com/wp-content/uploads/image46.png"&gt;&lt;img style="background-image:none;border-bottom:0px;border-left:0px;padding-left:0px;padding-right:0px;display:inline;border-top:0px;border-right:0px;padding-top:0px;" title="image" border="0" alt="image" src="http://www.geniiius.com/wp-content/uploads/image_thumb45.png" width="570" height="204" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;The –v gives verbose output. Now it generates files for each table. Depending on the speed of your system, this may take a few minutes.&lt;/p&gt;
&lt;p&gt;The resulting files will be located in the same directory as dbgen.exe. The list of generated files is:&lt;/p&gt;
&lt;p&gt;&lt;a href="http://www.geniiius.com/wp-content/uploads/image47.png"&gt;&lt;img style="background-image:none;border-bottom:0px;border-left:0px;padding-left:0px;padding-right:0px;display:inline;border-top:0px;border-right:0px;padding-top:0px;" title="image" border="0" alt="image" src="http://www.geniiius.com/wp-content/uploads/image_thumb46.png" width="497" height="244" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;h2&gt;4. Create database and tables&lt;/h2&gt;
&lt;p&gt;The next we need to do, is create an empty database, and create the tables.&lt;/p&gt;
&lt;pre class="code"&gt;CREATE DATABASE DemoData
GO
&lt;/pre&gt;
&lt;p&gt;The schema we need, is available in the file C:\tpch_2_14_3\dbgen\dss.ddl and it looks like this:&lt;/p&gt;
&lt;pre class="code"&gt;-- Sccsid:     @(#)dss.ddl    2.1.8.1
CREATE TABLE NATION  ( N_NATIONKEY  INTEGER NOT NULL,
                            N_NAME       CHAR(25) NOT NULL,
                            N_REGIONKEY  INTEGER NOT NULL,
                            N_COMMENT    VARCHAR(152));

CREATE TABLE REGION  ( R_REGIONKEY  INTEGER NOT NULL,
                            R_NAME       CHAR(25) NOT NULL,
                            R_COMMENT    VARCHAR(152));

CREATE TABLE PART  ( P_PARTKEY     INTEGER NOT NULL,
                          P_NAME        VARCHAR(55) NOT NULL,
                          P_MFGR        CHAR(25) NOT NULL,
                          P_BRAND       CHAR(10) NOT NULL,
                          P_TYPE        VARCHAR(25) NOT NULL,
                          P_SIZE        INTEGER NOT NULL,
                          P_CONTAINER   CHAR(10) NOT NULL,
                          P_RETAILPRICE DECIMAL(15,2) NOT NULL,
                          P_COMMENT     VARCHAR(23) NOT NULL );

CREATE TABLE SUPPLIER ( S_SUPPKEY     INTEGER NOT NULL,
                             S_NAME        CHAR(25) NOT NULL,
                             S_ADDRESS     VARCHAR(40) NOT NULL,
                             S_NATIONKEY   INTEGER NOT NULL,
                             S_PHONE       CHAR(15) NOT NULL,
                             S_ACCTBAL     DECIMAL(15,2) NOT NULL,
                             S_COMMENT     VARCHAR(101) NOT NULL);

CREATE TABLE PARTSUPP ( PS_PARTKEY     INTEGER NOT NULL,
                             PS_SUPPKEY     INTEGER NOT NULL,
                             PS_AVAILQTY    INTEGER NOT NULL,
                             PS_SUPPLYCOST  DECIMAL(15,2)  NOT NULL,
                             PS_COMMENT     VARCHAR(199) NOT NULL );

CREATE TABLE CUSTOMER ( C_CUSTKEY     INTEGER NOT NULL,
                             C_NAME        VARCHAR(25) NOT NULL,
                             C_ADDRESS     VARCHAR(40) NOT NULL,
                             C_NATIONKEY   INTEGER NOT NULL,
                             C_PHONE       CHAR(15) NOT NULL,
                             C_ACCTBAL     DECIMAL(15,2)   NOT NULL,
                             C_MKTSEGMENT  CHAR(10) NOT NULL,
                             C_COMMENT     VARCHAR(117) NOT NULL);

CREATE TABLE ORDERS  ( O_ORDERKEY       INTEGER NOT NULL,
                           O_CUSTKEY        INTEGER NOT NULL,
                           O_ORDERSTATUS    CHAR(1) NOT NULL,
                           O_TOTALPRICE     DECIMAL(15,2) NOT NULL,
                           O_ORDERDATE      DATE NOT NULL,
                           O_ORDERPRIORITY  CHAR(15) NOT NULL,
                           O_CLERK          CHAR(15) NOT NULL,
                           O_SHIPPRIORITY   INTEGER NOT NULL,
                           O_COMMENT        VARCHAR(79) NOT NULL);

CREATE TABLE LINEITEM ( L_ORDERKEY    INTEGER NOT NULL,
                             L_PARTKEY     INTEGER NOT NULL,
                             L_SUPPKEY     INTEGER NOT NULL,
                             L_LINENUMBER  INTEGER NOT NULL,
                             L_QUANTITY    DECIMAL(15,2) NOT NULL,
                             L_EXTENDEDPRICE  DECIMAL(15,2) NOT NULL,
                             L_DISCOUNT    DECIMAL(15,2) NOT NULL,
                             L_TAX         DECIMAL(15,2) NOT NULL,
                             L_RETURNFLAG  CHAR(1) NOT NULL,
                             L_LINESTATUS  CHAR(1) NOT NULL,
                             L_SHIPDATE    DATE NOT NULL,
                             L_COMMITDATE  DATE NOT NULL,
                             L_RECEIPTDATE DATE NOT NULL,
                             L_SHIPINSTRUCT CHAR(25) NOT NULL,
                             L_SHIPMODE     CHAR(10) NOT NULL,
                             L_COMMENT      VARCHAR(44) NOT NULL);
&lt;/pre&gt;
&lt;p&gt;If you want referential integrity on your tables, you can find help in this file: C:\tpch_2_14_3\dbgen\dss.ri&lt;/p&gt;
&lt;h2&gt;5. Load data into tables&lt;/h2&gt;
&lt;p&gt;Now we simply need to execute the following commands to import the data:&lt;/p&gt;
&lt;pre class="code"&gt;USE DemoData
GO
BULK INSERT part FROM &amp;#39;C:\tpch_2_14_3\dbgen\part.tbl&amp;#39; WITH (TABLOCK, DATAFILETYPE=&amp;#39;char&amp;#39;, CODEPAGE=&amp;#39;raw&amp;#39;, FIELDTERMINATOR = &amp;#39;|&amp;#39;)
BULK INSERT customer FROM &amp;#39;C:\tpch_2_14_3\dbgen\customer.tbl&amp;#39; WITH (TABLOCK, DATAFILETYPE=&amp;#39;char&amp;#39;, CODEPAGE=&amp;#39;raw&amp;#39;, FIELDTERMINATOR = &amp;#39;|&amp;#39;)
BULK INSERT orders FROM &amp;#39;C:\tpch_2_14_3\dbgen\orders.tbl&amp;#39; WITH (TABLOCK, DATAFILETYPE=&amp;#39;char&amp;#39;, CODEPAGE=&amp;#39;raw&amp;#39;, FIELDTERMINATOR = &amp;#39;|&amp;#39;)
BULK INSERT partsupp FROM &amp;#39;C:\tpch_2_14_3\dbgen\partsupp.tbl&amp;#39; WITH (TABLOCK, DATAFILETYPE=&amp;#39;char&amp;#39;, CODEPAGE=&amp;#39;raw&amp;#39;, FIELDTERMINATOR = &amp;#39;|&amp;#39;)
BULK INSERT supplier FROM &amp;#39;c:\tpch_2_14_3\dbgen\supplier.tbl&amp;#39; WITH (TABLOCK, DATAFILETYPE=&amp;#39;char&amp;#39;, CODEPAGE=&amp;#39;raw&amp;#39;, FIELDTERMINATOR = &amp;#39;|&amp;#39;)
BULK INSERT lineitem FROM &amp;#39;C:\tpch_2_14_3\dbgen\lineitem.tbl&amp;#39; WITH (TABLOCK, DATAFILETYPE=&amp;#39;char&amp;#39;, CODEPAGE=&amp;#39;raw&amp;#39;, FIELDTERMINATOR = &amp;#39;|&amp;#39;)
BULK INSERT nation FROM &amp;#39;C:\tpch_2_14_3\dbgen\nation.tbl&amp;#39; WITH (TABLOCK, DATAFILETYPE=&amp;#39;char&amp;#39;, CODEPAGE=&amp;#39;raw&amp;#39;, FIELDTERMINATOR = &amp;#39;|&amp;#39;)
BULK INSERT region FROM &amp;#39;C:\tpch_2_14_3\dbgen\region.tbl&amp;#39; WITH (TABLOCK, DATAFILETYPE=&amp;#39;char&amp;#39;, CODEPAGE=&amp;#39;raw&amp;#39;, FIELDTERMINATOR = &amp;#39;|&amp;#39;)
&lt;/pre&gt;
&lt;p&gt;And that’s it &lt;img style="border-bottom-style:none;border-left-style:none;border-top-style:none;border-right-style:none;" class="wlEmoticon wlEmoticon-smile" alt="Smiley" src="http://www.geniiius.com/wp-content/uploads/wlEmoticon-smile8.png" /&gt;&lt;/p&gt;
&lt;p&gt;Using this guide we can easily create 1, 10 or hundreds of GB of data, giving us the base we need to truly demonstrate the effect of performance tuning. This demo database will be used in later blog posts about query analyzing and performance optimizing. At some point I will also look into using the TPC tools for testing the transactional capacity of different systems, to be able to see the effect of configuration changes, hardware upgrades and other things we might wanna change to improve a system.&lt;/p&gt;
&lt;div class="InlineAdBox"&gt;&lt;b&gt;Republished with author&amp;#39;s permission. See the original post &lt;a href="http://www.geniiius.com/blog/generate-test-data-using-dbgen/" target="_blank"&gt;here.&lt;/a&gt; &lt;/b&gt;&lt;/div&gt;</description></item><item><title>TOP WITH TIES</title><link>http://beyondrelational.com/live/blogs/geniiius/archive/2012/01/17/top-with-ties.aspx</link><pubDate>Tue, 17 Jan 2012 06:00:00 GMT</pubDate><guid isPermaLink="false">6e5011fa-7db5-4df3-bb79-9085c1d333b3:15303</guid><dc:creator>Geniiius</dc:creator><description>&lt;p&gt;I have been working with SQL Server for quite a few years now, and it still happens quite often that I discover new cool things to do in t-sql. My latest discovery is not a new feature at all, because it was introduced back in SQL Server 2005 – but for some reason I haven’t come across it before. So I thought I might share it with you &lt;img style="border-bottom-style:none;border-left-style:none;border-top-style:none;border-right-style:none;" class="wlEmoticon wlEmoticon-smile" alt="Smiley" src="http://www.geniiius.com/wp-content/uploads/wlEmoticon-smile6.png" /&gt;&lt;/p&gt;
&lt;p&gt;Consider the following example:&lt;/p&gt;
&lt;pre class="code"&gt;CREATE TABLE AggregatedClientRequests
(
    Id INT IDENTITY PRIMARY KEY,
    ClientIp VARCHAR(200) NOT NULL,
    NumOfRequests INT NOT NULL
)
GO

INSERT INTO AggregatedClientRequests (ClientIp, NumOfRequests)
VALUES
    (&amp;#39;1.1.1.1&amp;#39;, 5100),
    (&amp;#39;2.2.2.2&amp;#39;, 10000),
    (&amp;#39;3.3.3.3&amp;#39;, 200),
    (&amp;#39;3.3.3.3&amp;#39;, 44000),
    (&amp;#39;4.4.4.4&amp;#39;, 2200),
    (&amp;#39;5.5.5.5&amp;#39;, 10000),
    (&amp;#39;6.6.6.6&amp;#39;, 31000),
    (&amp;#39;7.7.7.7&amp;#39;, 100),
    (&amp;#39;8.8.8.8&amp;#39;, 300),
    (&amp;#39;9.9.9.9&amp;#39;, 10000)
GO
&lt;/pre&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;This table holds an aggegated value of the number of requests a given ClientIp has made on a system. Now you want to identify the top three ClientIps that have generated the most requests. That easy, right? Without thinking too much about it, I would have written something like this:&lt;/p&gt;
&lt;pre class="code"&gt;SELECT TOP (3) *
FROM AggregatedClientRequests
ORDER BY NumOfRequests DESC
&lt;/pre&gt;
&lt;p&gt;&lt;a href="http://www.geniiius.com/wp-content/uploads/image38.png"&gt;&lt;img style="background-image:none;border-bottom:0px;border-left:0px;margin:0px;padding-left:0px;padding-right:0px;display:inline;border-top:0px;border-right:0px;padding-top:0px;" title="image" border="0" alt="image" src="http://www.geniiius.com/wp-content/uploads/image_thumb38.png" width="220" height="111" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;That looks right… or does it? What about the ClientIps ‘5.5.5.5’ and ‘9.9.9.9’ ? They also generated 10.000 requests, so they are actually equally to the ‘2.2.2.2’ ip. So which one of the three with 10.000 request should I return?. If I want those returned as well (think of a use case where the top three are sales persons that should have a bonus), how could I do that? That’s actually pretty simple by using the TOP WITH TIES clause like this:&lt;/p&gt;
&lt;pre class="code"&gt;SELECT TOP (3) WITH TIES *
FROM AggregatedClientRequests
ORDER BY NumOfRequests DESC
&lt;/pre&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Now it get this back:&lt;/p&gt;
&lt;p&gt;&lt;a href="http://www.geniiius.com/wp-content/uploads/image39.png"&gt;&lt;img style="background-image:none;border-bottom:0px;border-left:0px;margin:0px;padding-left:0px;padding-right:0px;display:inline;border-top:0px;border-right:0px;padding-top:0px;" title="image" border="0" alt="image" src="http://www.geniiius.com/wp-content/uploads/image_thumb39.png" width="233" height="165" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Notice that I actually get 5 rows returned, even though my TOP clause stated that I only wanted three! The WITH TIES clause looks at the last row of the TOP (3) rows, and add all other rows with identical values.&lt;/p&gt;
&lt;p&gt;How simple is that?! I don’t even want to think about how the query would look to achieve the same thing without using the WITH TIES clause. Perhaps you will give it a go?&lt;/p&gt;

&lt;div class="InlineAdBox"&gt;&lt;b&gt;Republished with author&amp;#39;s permission. See the original post &lt;a href="http://www.geniiius.com/blog/top-with-ties/" target="_blank"&gt;here.&lt;/a&gt; &lt;/b&gt;&lt;/div&gt;</description></item><item><title>SQL Server - Custom Database Role</title><link>http://beyondrelational.com/live/blogs/paresh/archive/2012/01/13/sql-server-custom-database-role.aspx</link><pubDate>Fri, 13 Jan 2012 13:53:00 GMT</pubDate><guid isPermaLink="false">6e5011fa-7db5-4df3-bb79-9085c1d333b3:15198</guid><dc:creator>pprajapati</dc:creator><description>&lt;div dir="ltr" style="text-align:left;"&gt;
Recently while working with database security, I learned database roles as how the each role used. Apart from the server level roles if we need to require to assign access/rights to particular databases level then we need to go through database level roles.&lt;br /&gt;
&lt;br /&gt;
Following are the fixed database level roles as per &lt;a href="http://msdn.microsoft.com/en-us/library/ms189121.aspx" target="_blank"&gt;MSDN&lt;/a&gt;,&lt;br /&gt;
&lt;strong&gt;db_owner :&lt;/strong&gt;
Members of the db_owner fixed database role can perform all configuration and maintenance activities on the database, and can also drop the database.&lt;br /&gt;
&lt;strong&gt;db_securityadmin :&lt;/strong&gt;
Members of the db_securityadmin fixed database role can modify role membership and manage permissions. Adding principals to this role could enable unintended privilege escalation.&lt;br /&gt;
&lt;strong&gt;db_accessadmin :&lt;/strong&gt;
Members of the db_accessadmin fixed database role can add or remove access to the database for Windows logins, Windows groups, and SQL Server logins.&lt;br /&gt;
&lt;strong&gt;db_backupoperator :&lt;/strong&gt;
Members of the db_backupoperator fixed database role can back up the database.&lt;br /&gt;
&lt;strong&gt;db_ddladmin :&lt;/strong&gt;
Members of the db_ddladmin fixed database role can run any Data Definition Language (DDL) command in a database.&lt;br /&gt;
&lt;strong&gt;db_datawriter :&lt;/strong&gt;
Members of the db_datawriter fixed database role can add, delete, or change data in all user tables.&lt;br /&gt;
&lt;strong&gt;db_datareader :
&lt;/strong&gt;Members of the db_datareader fixed database role can read all data from all user tables.&lt;br /&gt;
&lt;strong&gt;db_denydatawriter :&lt;/strong&gt;
Members of the db_denydatawriter fixed database role cannot add, modify, or delete any data in the user tables within a database.&lt;br /&gt;
&lt;strong&gt;db_denydatareader :
&lt;/strong&gt;Members of the db_denydatareader fixed database role cannot read any data in the user tables within a database.&lt;br /&gt;
&lt;br /&gt;
&lt;div class="separator" style="clear:both;text-align:center;"&gt;
&lt;a href="http://4.bp.blogspot.com/-zaQtyTnHKZ8/Tw_SsTYDWEI/AAAAAAAABW0/n9RI--LrhQo/s1600/DBroles_1.png" style="clear:left;float:left;margin-bottom:1em;margin-right:1em;"&gt;&lt;img border="0" height="574" src="http://4.bp.blogspot.com/-zaQtyTnHKZ8/Tw_SsTYDWEI/AAAAAAAABW0/n9RI--LrhQo/s640/DBroles_1.png" width="640" alt="" /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;&lt;br /&gt;
&lt;br /&gt;&lt;br /&gt;
&lt;br /&gt;&lt;br /&gt;
&lt;br /&gt;&lt;br /&gt;
&lt;br /&gt;&lt;br /&gt;
&lt;br /&gt;&lt;br /&gt;
&lt;br /&gt;&lt;br /&gt;
&lt;br /&gt;&lt;br /&gt;
&lt;br /&gt;&lt;br /&gt;
&lt;br /&gt;&lt;br /&gt;
&lt;br /&gt;&lt;br /&gt;
&lt;br /&gt;&lt;br /&gt;
&lt;br /&gt;&lt;br /&gt;
&lt;br /&gt;&lt;br /&gt;
&lt;br /&gt;&lt;br /&gt;
&lt;br /&gt;&lt;br /&gt;
&lt;br /&gt;&lt;br /&gt;
&lt;br /&gt;&lt;br /&gt;
&lt;br /&gt;&lt;br /&gt;
&lt;br /&gt;&lt;br /&gt;
You can see the image for all above fixed database roles.&amp;nbsp;Now we will see how can we use the roles and bind with users. Let&amp;#39;s create a small demo with example.&lt;br /&gt;
&lt;br /&gt;
Here i am creating required objects used for demo, So let&amp;#39;s do that.&lt;br /&gt;
&lt;br /&gt;
&lt;pre class="brush:sql"&gt;USE demo
GO

CREATE TABLE SampleTable1
(
Id int,
Name varchar(10)
)
GO

CREATE TABLE SampleTable2
(
Id int,
Name varchar(10)
)
GO

CREATE PROCEDURE SampleSP1
AS 
BEGIN
SET NOCOUNT ON
SELECT * FROM SampleTable1
End
GO

CREATE PROCEDURE SampleSP2
AS 
BEGIN
SET NOCOUNT ON
SELECT * FROM SampleTable2
End
GO
&lt;/pre&gt;
&lt;br /&gt;
Now here i want assigned to the access to user as following,&lt;br /&gt;
1. User can see the data from SampleTable2 table.&lt;br /&gt;
2. User can perform select/insert/update operation on&amp;nbsp;SampleTable1 table, not delete operation.&lt;br /&gt;
3. Can execute stored procedure&amp;nbsp;SampleSP1.&lt;br /&gt;
4. Can not execute stored procedure&amp;nbsp;SampleSP2.
&lt;br /&gt;
&lt;br /&gt;
&lt;strong&gt;&lt;span style="color:#0b5394;"&gt;Workaround 1:&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;
If we assigned fixed database roles to User like db_datareader and db_datawriter for&amp;nbsp;particular&amp;nbsp;database, then user can perform all DML operation on all tables, views for the database. Even if we assigned EXECUTE permission to user then user can execute all the stored procedures.&lt;br /&gt;
&lt;br /&gt;
After all these permission we need to deny permission from the user for some of the tables and stored procedures which are not required to be&amp;nbsp;accessed.&lt;br /&gt;
&lt;br /&gt;
&lt;strong&gt;&lt;span style="color:#0b5394;"&gt;Workaround 2:&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;
Instead of doing above such stuffs, We will create a new custom database level roles and assigned requited access to user for the objects.&lt;br /&gt;
&lt;br /&gt;
&lt;pre class="brush:sql"&gt;USE demo
GO

CREATE LOGIN [SupportUser] 
WITH PASSWORD=N&amp;#39;SupportUser&amp;#39;, 
 DEFAULT_DATABASE=[master], 
 DEFAULT_LANGUAGE=[us_english], 
 CHECK_EXPIRATION=OFF, 
 CHECK_POLICY=OFF
GO

CREATE USER [SupportUser] FOR LOGIN [SupportUser]
GO

CREATE ROLE [SupportRole] 
Go

GRANT SELECT ON SampleTable2 TO [SupportRole];
GRANT SELECT,INSERT,UPDATE ON SampleTable1 to [SupportRole];
GRANT EXEC ON SampleSP1 to [SupportRole]
GO

EXEC sp_addrolemember N&amp;#39;SupportRole&amp;#39;, N&amp;#39;SupportUser&amp;#39;
GO
&lt;/pre&gt;
&lt;br /&gt;
Let&amp;#39;s connect the SQL Server instance with this newly created user and see the access rights,&lt;br /&gt;
&lt;br /&gt;
&lt;pre class="brush:sql"&gt;USE demo
GO

PRINT &amp;#39;Inserting in SampleTable1&amp;#39;
GO
INSERT INTO SampleTable1
 (
 Id, 
 Name
 )
SELECT 
 1,
 &amp;#39;Sample1&amp;#39;
GO

PRINT &amp;#39;Inserting in SampleTable2&amp;#39;
GO
INSERT INTO SampleTable2
 (
 Id, 
 Name
 )
SELECT 
 1,
 &amp;#39;Sample2&amp;#39;
GO

PRINT &amp;#39;Deleting from SampleTable1&amp;#39;
GO
DELETE FROM SampleTable1
GO

PRINT &amp;#39;Viewing from SampleTable1&amp;#39;
GO
SELECT * FROM SampleTable2
GO
SELECT * FROM SampleTable1
GO


PRINT &amp;#39;Executing SampleSP11&amp;#39;
GO
EXEC SampleSP1
GO
PRINT &amp;#39;Executing SampleSP2&amp;#39;
GO
EXEC SampleSP2
GO
&lt;/pre&gt;
&lt;br /&gt;
You can see the below image to see the access of running user,&lt;br /&gt;
&lt;br /&gt;
&lt;div class="separator" style="clear:both;text-align:center;"&gt;
&lt;a href="http://1.bp.blogspot.com/-EyaFnrKGH_Q/Tw_TNLhMiKI/AAAAAAAABW8/Nn8gEh5v23s/s1600/DBroles_2.png" style="clear:left;float:left;margin-bottom:1em;margin-right:1em;"&gt;&lt;img border="0" height="518" src="http://1.bp.blogspot.com/-EyaFnrKGH_Q/Tw_TNLhMiKI/AAAAAAAABW8/Nn8gEh5v23s/s640/DBroles_2.png" width="640" alt="" /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;&lt;br /&gt;
&lt;br /&gt;&lt;br /&gt;
&lt;br /&gt;&lt;br /&gt;
&lt;br /&gt;&lt;br /&gt;
&lt;br /&gt;&lt;br /&gt;
&lt;br /&gt;&lt;br /&gt;
&lt;br /&gt;&lt;br /&gt;
&lt;br /&gt;&lt;br /&gt;
&lt;br /&gt;&lt;br /&gt;
&lt;br /&gt;&lt;br /&gt;
&lt;br /&gt;&lt;br /&gt;
&lt;br /&gt;&lt;br /&gt;
&lt;br /&gt;&lt;br /&gt;
&lt;br /&gt;&lt;br /&gt;
&lt;br /&gt;&lt;br /&gt;
&lt;br /&gt;&lt;br /&gt;
&lt;br /&gt;&lt;br /&gt;
&lt;br /&gt;&lt;br /&gt;
Main benefit of the custom database role is role can be assigned to multiple users. You can see below script where i have assigned same role to different user. So once role created it can &amp;nbsp;be assigned to multiple users.&lt;br /&gt;
&lt;br /&gt;
&lt;pre class="brush:sql"&gt;USE demo
GO

CREATE LOGIN [DBAUser] 
WITH PASSWORD=N&amp;#39;DBAUser&amp;#39;, 
 DEFAULT_DATABASE=[master], 
 DEFAULT_LANGUAGE=[us_english], 
 CHECK_EXPIRATION=OFF, 
 CHECK_POLICY=OFF
GO

CREATE USER [DBAUser] FOR LOGIN [DBAUser]
GO

EXEC sp_addrolemember N&amp;#39;SupportRole&amp;#39;, N&amp;#39;DBAUser&amp;#39;
GO
&lt;/pre&gt;
&lt;br /&gt;
Hope you liked this post.
&lt;/div&gt;</description></item><item><title>SQL Server 2012 FileTable – Part 2</title><link>http://beyondrelational.com/live/blogs/geniiius/archive/2012/01/12/sql-server-2012-filetable-part-2.aspx</link><pubDate>Thu, 12 Jan 2012 06:00:00 GMT</pubDate><guid isPermaLink="false">6e5011fa-7db5-4df3-bb79-9085c1d333b3:15304</guid><dc:creator>Geniiius</dc:creator><description>&lt;p&gt;In this weeks blog post we will have a look at how easy it is to combine FileTables and FullText Search. Last week we had a look at some of the basics of the new FileTable feature – if you missed out on last week blog post, you can read it here – &lt;a href="http://www.geniiius.com/blog/sql-server-2012-filetable-part-1/" target="_blank"&gt;FileTable Part 1&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;To get the full effect of this powerful combination, it is highly recommended that you install “Microsoft Office 2010 Filter packs”. to check if you have that installed take a look at your installed programs and look after something like this:&lt;/p&gt;
&lt;p&gt;&lt;a href="http://www.geniiius.com/wp-content/uploads/image40.png"&gt;&lt;img style="background-image:none;border-right-width:0px;padding-left:0px;padding-right:0px;display:inline;border-top-width:0px;border-bottom-width:0px;border-left-width:0px;padding-top:0px;" title="image" border="0" alt="image" src="http://www.geniiius.com/wp-content/uploads/image_thumb40.png" width="491" height="140" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;if not, you can download and install it from here – &lt;a href="http://www.microsoft.com/download/en/details.aspx?id=17062" target="_blank"&gt;Microsoft Filter Pack 2.0&lt;/a&gt;. By installing this feature Full Text Search will now have the ability to index the content of Microsoft Word and many other file types. To se a complete list of the file types supported in your setup, run the following query:&lt;/p&gt;
&lt;pre class="code"&gt;select * from sys.fulltext_document_types
&lt;/pre&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;After installing the Microsoft filter pack, you should have support for more than 150 document_types.&lt;/p&gt;
&lt;p&gt;Ok, let’s get started with the proper demo stuff, I’ll be using the same table structure as I did in Part 1 of this series. I am not going to post the code once again, so you’ll have to go back to Part 1 and get it from there. I start out with an empty table and an empty FileTable folder. Before I do anything else I’ll create a text document with the following text in it: “AGF please buy back Morten Duncan Rasmussen” – I save the document and name it Duncan.txt.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Fulltext Search&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;First of all, we need a FullText catalog, I ‘ll create that like this:&lt;/p&gt;
&lt;pre class="code"&gt;CREATE FULLTEXT CATALOG MyFullTextCatalog AS DEFAULT
GO
&lt;/pre&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Next step is to create a FullText Index on the FileTable table that we have, the interesting column is the file_stream column, this is where the content of the document is stored. As with any other FullText Index we need a Unique key index to build the index with, this is where a quick lookup in the sys.indexes is handy.&lt;/p&gt;
&lt;p&gt;Another thing that you might notice is that I use language 1030, this is the code for Danish word breaker. Change tracking is set to auto and I’m using the system stop list. This is not a detailed FullText blog post, so I’ll not go into further details with that right now.&lt;/p&gt;
&lt;p&gt;Here is the code to create the FullText Index:&lt;/p&gt;
&lt;pre class="code"&gt;CREATE FULLTEXT INDEX ON dbo.MyDocumentStore
(
    name LANGUAGE 1030,
    file_stream TYPE COLUMN file_type LANGUAGE 1030
)
KEY INDEX PK__MyDocume__5A5B77D54AAAEEEA
ON MyFullTextCatalog
WITH
    CHANGE_TRACKING AUTO,
    STOPLIST = SYSTEM
GO
&lt;/pre&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Now everything is configured, and we are ready to write some FullText queries against the documents in our FileTable folder. Here is some examples:&lt;/p&gt;
&lt;pre class="code"&gt;-- My Surname should not be found in the text
SELECT
    stream_id, name, file_stream.GetFileNamespacePath(1,1) as FileLocation
FROM dbo.MyDocumentStore
WHERE CONTAINS(file_stream, &amp;#39;Schmidt&amp;#39;)

-- Geniiius APS or http://www.Geniiius.com/blog/?
SELECT
    stream_id, name, file_stream.GetFileNamespacePath(1,1) as FileLocation
FROM dbo.MyDocumentStore
WHERE CONTAINS(file_stream, &amp;#39;&amp;quot;Geniiius Aps&amp;quot; OR &amp;quot;http://www.Geniiius.com/blog/&amp;quot;&amp;#39;)

-- The best team on the planet &lt;img src="http://www.geniiius.com/wp-includes/images/smilies/icon_smile.gif" alt=":)" class="wp-smiley" /&gt;
SELECT
    stream_id, name, file_stream.GetFileNamespacePath(1,1) as FileLocation
FROM dbo.MyDocumentStore
WHERE CONTAINS(file_stream, &amp;#39;AGF&amp;#39;)
&lt;/pre&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;No surprise that only the last query return some rows. Now let’s do some more testing, and because that Change Tracking is set to auto this should be very easy. I’ll create a Microsoft PowerPoint document, copy it to my FileTable folder and seconds after I should be able to query the content from SQL Server. Let’s try.&lt;/p&gt;
&lt;p&gt;This is how my PowerPoint document looks:&lt;/p&gt;
&lt;p&gt;&lt;a href="http://www.geniiius.com/wp-content/uploads/image42.png"&gt;&lt;img style="background-image:none;border-right-width:0px;padding-left:0px;padding-right:0px;display:inline;border-top-width:0px;border-bottom-width:0px;border-left-width:0px;padding-top:0px;" title="image" border="0" alt="image" src="http://www.geniiius.com/wp-content/uploads/image_thumb41.png" width="309" height="229" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Now let’s us try to rerun the three queries again, and wupaa all three of them return results. Why is the fist one returning rows you might ask? The first query return rows because of the meta data on the file, where my name in the auther.&lt;/p&gt;
&lt;p&gt;Is this a cool feature or what &lt;img style="border-bottom-style:none;border-left-style:none;border-top-style:none;border-right-style:none;" class="wlEmoticon wlEmoticon-smile" alt="Smile" src="http://www.geniiius.com/wp-content/uploads/wlEmoticon-smile7.png" /&gt; Happy Searching.&lt;/p&gt;
&lt;div class="InlineAdBox"&gt;&lt;b&gt;Republished with author&amp;#39;s permission. See the original post &lt;a href="http://www.geniiius.com/blog/sql-server-2012-filetable-part-2/" target="_blank"&gt;here.&lt;/a&gt; &lt;/b&gt;&lt;/div&gt;</description></item><item><title>SQL Server - Archive old database backup files using TSQL Script</title><link>http://beyondrelational.com/live/blogs/paresh/archive/2012/01/07/sql-server-archive-old-database-backup-files-using-tsql-script.aspx</link><pubDate>Sat, 07 Jan 2012 13:37:00 GMT</pubDate><guid isPermaLink="false">6e5011fa-7db5-4df3-bb79-9085c1d333b3:15161</guid><dc:creator>pprajapati</dc:creator><description>&lt;div dir="ltr" style="text-align:left;"&gt;
I experienced into one issues for database backups were failed. And this was due to space issues on disk drive. This disk drive is spacific to allocated for the database backups only.&lt;br /&gt;
&lt;br /&gt;
The space was eaten by this database backups and this drive contains so many old backups. I have manually deleted all files and continue this activity so many days.If you create a&amp;nbsp;maintenance&amp;nbsp;plans then it have option to delete old backups files.&amp;nbsp;But i have the stored procedure for the database backups. So i do not have option to delete old and unused database backup files.&lt;br /&gt;
&lt;br /&gt;
Finally, I have created a script to clean those old backups. I have created one stored procedure in which you need to pass there parameters,&amp;nbsp;One is Backup type as want to delete full, differential or transaction log backups.&amp;nbsp;Second is From days and third one is End day.&lt;br /&gt;
&lt;br /&gt;
Please make sure XP_CMDSHELL is enabled in database instance as thisis require to enable it to delete database backup files to be deleted physically.&lt;br /&gt;
Here id query to enable it.&lt;br /&gt;
&lt;br /&gt;
&lt;pre class="brush:sql"&gt;USE MASTER
GO

EXEC SP_CONFIGURE &amp;#39;show advanced options&amp;#39;,1
GO
EXEC SP_CONFIGURE &amp;#39;XP_CMDSHELL&amp;#39;,1
GO
RECONFIGURE
GO
&lt;/pre&gt;
&lt;br /&gt;
I have already told you as i have created script to delete the old DATABASEPROPERTY backups, please find below SP for the same.&lt;br /&gt;
&lt;br /&gt;
&lt;pre class="brush:sql"&gt;SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[DeleteDBBackupOldFiles]
@BackupType char(1) = &amp;#39;D&amp;#39;, -- &amp;#39;D&amp;#39;-Full, &amp;#39;I&amp;#39;-Differential, &amp;#39;L&amp;#39;-Log backup type
@StartDayFromToday int,
@EndDayFromToday int
AS
BEGIN
SET NOCOUNT ON

DECLARE @IsFileExists int
DECLARE @DeletedFile VARCHAR(500)
DECLARE @OldFiles VARCHAR(500)

DECLARE OldFiles CURSOR FAST_FORWARD  FOR
SELECT 
bmf.physical_device_name
from msdb.dbo.backupset bs 
INNER JOIN msdb.dbo.backupmediafamily bmf
ON (bs.media_set_id=bmf.media_set_id)
WHERE DEVICE_TYPE = 2 
AND TYPE = @BackupType 
AND BACKUP_START_DATE &amp;lt; = GETDATE() - @StartDayFromToday
AND BACKUP_START_DATE &amp;gt; = GETDATE() - @EndDayFromToday
-- AND DATEDIFF(DAY,BACKUP_START_DATE,GETDATE()) &amp;gt; BETWEEN @StartDayFromToday and @EndDayFromToday 

OPEN OldFiles

FETCH NEXT FROM OldFiles INTO @OldFiles

WHILE @@FETCH_STATUS =0
BEGIN

EXEC XP_FILEEXIST @OldFiles,@IsFileExists OUTPUT
IF @IsFileExists=1
BEGIN

PRINT &amp;#39;Deleted File : &amp;#39; + @DeletedFile

SET @DeletedFile = &amp;#39;DEL &amp;#39; + @OldFiles

EXEC XP_CMDSHELL @DeletedFile

END
FETCH NEXT FROM OldFiles INTO @OldFiles
END
CLOSE OldFiles
DEALLOCATE OldFiles
END
&lt;/pre&gt;
&lt;br /&gt;
Finally after creating a stored procedures , it is time to run and clean the old database backups. After running it will remove all the old database baclups as per specified parameters. Like we have passed &amp;#39;D&amp;#39;,3 and 10 with SP, So i will delete Full database backups whicl are older then 3 days ago and 10 days before created.&lt;br /&gt;
&lt;br /&gt;
&lt;pre class="brush:sql"&gt;EXEC [DeleteDBBackupOldFiles] 
  @BackupType  = &amp;#39;D&amp;#39;,
  @StartDayFromToday = 3,
  @EndDayFromToday = 10
&lt;/pre&gt;
&lt;br /&gt;
Which method you are using for old databsee backup&amp;nbsp;maintenance?&amp;nbsp;You can read my earlier posts for delete files using &lt;a href="http://beyondrelational.com/blogs/paresh/archive/2011/12/23/ssis-delete-files-from-specified-folder-using-file-system-task-in-sql-server.aspx" target="_blank"&gt;&lt;span style="font-size:large;"&gt;File System Task&lt;/span&gt;&lt;/a&gt; and &lt;a href="http://beyondrelational.com/blogs/paresh/archive/2011/12/30/ssis-delete-files-from-specified-folder-using-script-task-in-sql-server.aspx" target="_blank"&gt;&lt;span style="font-size:large;"&gt;Script Task&lt;/span&gt;&lt;/a&gt; in SSIS.&lt;br /&gt;
&lt;/div&gt;</description></item></channel></rss>