<?xml version="1.0" encoding="UTF-8"?><!-- generator="wordpress.com" -->
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	>

<channel>
	<title>sql-server-backup &amp;laquo; WordPress.com Tag Feed</title>
	<link>http://en.wordpress.com/tag/sql-server-backup/</link>
	<description>Feed of posts on WordPress.com tagged "sql-server-backup"</description>
	<pubDate>Tue, 08 Dec 2009 18:15:46 +0000</pubDate>

	<generator>http://en.wordpress.com/tags/</generator>
	<language>en</language>

<item>
<title><![CDATA[Backup and Restore SQL Server databases programmatically with SMO]]></title>
<link>http://esersahin.wordpress.com/2009/10/29/backup-and-restore-sql-server-databases-programmatically-with-smo/</link>
<pubDate>Thu, 29 Oct 2009 13:06:56 +0000</pubDate>
<dc:creator>esersahin</dc:creator>
<guid>http://esersahin.wordpress.com/2009/10/29/backup-and-restore-sql-server-databases-programmatically-with-smo/</guid>
<description><![CDATA[http://www.mssqltips.com/tip.asp?tip=1849 Problem In my last set of tips, I discussed SMO at a basic]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p><a href="http://www.mssqltips.com/tip.asp?tip=1849">http://www.mssqltips.com/tip.asp?tip=1849</a></p>
<p><span style="text-decoration:underline;"><strong>Problem<br />
</strong></span>In my last set of tips, I discussed SMO at a basic level.  In this tip I am going to provide examples to SQL Server Database Administrators on how to backup and restore SQL Server databases with SMO.  I will start with how you can issue different types (Full, Differential and Log) of backups with SMO and how to restore them when required programmatically using SMO.</p>
<p><strong><span style="text-decoration:underline;">Solution<br />
</span></strong>As I discussed in my last tip, SMO provides utility classes for specific tasks. For backup and restore, it provides two main utility classes (<strong>Backup</strong> and <strong>Restore</strong>) which are available in <strong>Microsoft.SqlServer.Management.Smo</strong> namespace.</p>
<p>Before you start writing SMO code, you need to reference several assemblies which contain the SMO namespaces. For more details on these assemblies and how properly to reference them in your code, refer to my tip <a href="http://www.mssqltips.com/tip.asp?tip=1826">Getting started with SQL Server Management Objects (SMO)</a>.</p>
<p><strong><em>Examples</em></strong></p>
<p><strong>C# Code Block 1 &#8211; Full Backups</strong> &#8211; This example shows how to issue full database backups with SMO. First, create an instance of the <strong>Backup</strong> class and set the associated properties. With the <strong>Action</strong> property you can specify the type of backup such as full, files or log backup. With the <strong>Database</strong> property specify the name of the database being backed up.  The device is the backup media type such as disk or tape, so you need to add a device (one or more) to the <strong>Devices</strong> collection of backup instance. With the <strong>BackupSetName</strong> and <strong>BackupSetDescription</strong> properties you can specify the name and description for the backup set.  The <strong>Backup</strong> class also has a property called <strong>ExpirationDate</strong> which indicates how long backup data is considered valid and to expire the backup after that date. The backup object instance generates several events during the backup operation, we can write event-handlers for these events and wire them up with events. This is what I am doing for progress monitoring.  I am wiring up CompletionStatusInPercent and Backup_Completed methods (event-handlers) with <strong>PercentComplete </strong>and <strong>Complete</strong> events of backup object instance.  Finally, I am calling the <strong>SqlBackup</strong> method for starting up the backup operation, SMO provides a variant of this method called <strong>SqlBackupAsync</strong> if you want to start the backup operation asynchronously.</p>
<table border="1" cellspacing="0" cellpadding="0" width="600">
<tbody>
<tr>
<td><strong>C# Code Block 1 &#8211; Full Database Backup</strong></td>
</tr>
<tr>
<td align="left">Backup bkpDBFull = new Backup();<br />
/* Specify whether you want to back up database or files or log */<br />
bkpDBFull.Action = BackupActionType.Database;<br />
/* Specify the name of the database to back up */<br />
bkpDBFull.Database = myDatabase.Name;<br />
/* You can take backup on several media type (disk or tape), here I am<br />
 * using File type and storing backup on the file system */<br />
bkpDBFull.Devices.AddDevice(@&#8221;D:\AdventureWorksFull.bak&#8221;, DeviceType.File);<br />
bkpDBFull.BackupSetName = &#8220;Adventureworks database Backup&#8221;;<br />
bkpDBFull.BackupSetDescription = &#8220;Adventureworks database &#8211; Full Backup&#8221;;<br />
/* You can specify the expiration date for your backup data<br />
 * after that date backup data would not be relevant */<br />
bkpDBFull.ExpirationDate = DateTime.Today.AddDays(10);<br />
 <br />
/* You can specify Initialize = false (default) to create a new<br />
 * backup set which will be appended as last backup set on the media. You<br />
 * can specify Initialize = true to make the backup as first set on the<br />
 * medium and to overwrite any other existing backup sets if the all the<br />
 * backup sets have expired and specified backup set name matches with<br />
 * the name on the medium */<br />
bkpDBFull.Initialize = false;<br />
 <br />
/* Wiring up events for progress monitoring */<br />
bkpDBFull.PercentComplete += CompletionStatusInPercent;<br />
bkpDBFull.Complete += Backup_Completed;<br />
 <br />
/* SqlBackup method starts to take back up<br />
 * You can also use SqlBackupAsync method to perform the backup<br />
 * operation asynchronously */<br />
bkpDBFull.SqlBackup(myServer);</td>
</tr>
<tr>
<td>private static void CompletionStatusInPercent(object sender, PercentCompleteEventArgs args)<br />
{<br />
    Console.Clear();<br />
    Console.WriteLine(&#8220;Percent completed: {0}%.&#8221;, args.Percent);<br />
}<br />
private static void Backup_Completed(object sender, ServerMessageEventArgs args)<br />
{<br />
    Console.WriteLine(&#8220;Hurray&#8230;Backup completed.&#8221; );<br />
    Console.WriteLine(args.Error.Message);<br />
}<br />
private static void Restore_Completed(object sender, ServerMessageEventArgs args)<br />
{<br />
    Console.WriteLine(&#8220;Hurray&#8230;Restore completed.&#8221;);<br />
    Console.WriteLine(args.Error.Message);<br />
}</td>
</tr>
<tr>
<td><strong>Result:</strong></td>
</tr>
</tbody>
</table>
<p><strong>C# Code Block 2 Differential Backups </strong>- The process of issuing differential backups is not much different from issuing full backups. To issue a differential backup, set the property <strong>Incremental = true</strong>. If you set this property the incremental/differential backup will be taken since last full backup.</p>
<table border="1" cellspacing="0" cellpadding="0" width="600" align="center">
<tbody>
<tr>
<td><strong>C# Code Block 2 &#8211; Differential Database Backup</strong></td>
</tr>
<tr>
<td align="left">Backup bkpDBDifferential = new Backup();<br />
/* Specify whether you want to backup database, files or log */<br />
bkpDBDifferential.Action = BackupActionType.Database;<br />
/* Specify the name of the database to backup */<br />
bkpDBDifferential.Database = myDatabase.Name;<br />
/* You can issue backups on several media types (disk or tape), here I am * using the File type and storing the backup on the file system */<br />
bkpDBDifferential.Devices.AddDevice(@&#8221;D:\AdventureWorksDifferential.bak&#8221;, DeviceType.File);<br />
bkpDBDifferential.BackupSetName = &#8220;Adventureworks database Backup&#8221;;<br />
bkpDBDifferential.BackupSetDescription = &#8220;Adventureworks database &#8211; Differential Backup&#8221;;<br />
/* You can specify the expiration date for your backup data<br />
 * after that date backup data would not be relevant */<br />
bkpDBDifferential.ExpirationDate = DateTime.Today.AddDays(10);<br />
 <br />
/* You can specify Initialize = false (default) to create a new<br />
 * backup set which will be appended as last backup set on the media.<br />
 * You can specify Initialize = true to make the backup as the first set<br />
 * on the medium and to overwrite any other existing backup sets if the<br />
 * backup sets have expired and specified backup set name matches<br />
 * with the name on the medium */<br />
bkpDBDifferential.Initialize = false;<br />
 <br />
/* You can specify Incremental = false (default) to perform full backup<br />
 * or Incremental = true to perform differential backup since most recent<br />
 * full backup */<br />
bkpDBDifferential.Incremental = true;<br />
 <br />
/* Wiring up events for progress monitoring */<br />
bkpDBDifferential.PercentComplete += CompletionStatusInPercent;<br />
bkpDBDifferential.Complete += Backup_Completed;<br />
 <br />
/* SqlBackup method starts to take back up<br />
 * You cab also use SqlBackupAsync method to perform backup<br />
 * operation asynchronously */<br />
bkpDBDifferential.SqlBackup(myServer);</td>
</tr>
<tr>
<td><strong>Result:</strong></td>
</tr>
</tbody>
</table>
<p><strong>C# Code Block 3 Transaction Log Backups </strong>- Again the process of issuing transactional log backup is not much different from issuing full backups. To issue transactional log backups, set the property <strong>Action = BackupActionType.Log</strong> instead of <strong>BackupActionType.Database</strong> as in the case of a full backup.</p>
<table border="1" cellspacing="0" cellpadding="0" width="600" align="center">
<tbody>
<tr>
<td><strong>C# Code Block 3 &#8211; Transaction Log Backup</strong></td>
</tr>
<tr>
<td align="left">Backup bkpDBLog = new Backup();<br />
/* Specify whether you want to back up database or files or log */<br />
bkpDBLog.Action = BackupActionType.Log;<br />
/* Specify the name of the database to back up */<br />
bkpDBLog.Database = myDatabase.Name;<br />
/* You can take backup on several media type (disk or tape), here I am<br />
 * using File type and storing backup on the file system */<br />
bkpDBLog.Devices.AddDevice(@&#8221;D:\AdventureWorksLog.bak&#8221;, DeviceType.File);<br />
bkpDBLog.BackupSetName = &#8220;Adventureworks database Backup&#8221;;<br />
bkpDBLog.BackupSetDescription = &#8220;Adventureworks database &#8211; Log Backup&#8221;;<br />
/* You can specify the expiration date for your backup data<br />
 * after that date backup data would not be relevant */<br />
bkpDBLog.ExpirationDate = DateTime.Today.AddDays(10);<br />
 <br />
/* You can specify Initialize = false (default) to create a new<br />
 * backup set which will be appended as last backup set on the media. You<br />
 * can specify Initialize = true to make the backup as first set on the<br />
 * medium and to overwrite any other existing backup sets if the all the<br />
 * backup sets have expired and specified backup set name matches with<br />
 * the name on the medium */<br />
bkpDBLog.Initialize = false;<br />
 <br />
/* Wiring up events for progress monitoring */<br />
bkpDBLog.PercentComplete += CompletionStatusInPercent;<br />
bkpDBLog.Complete += Backup_Completed;<br />
 <br />
/* SqlBackup method starts to take back up<br />
 * You cab also use SqlBackupAsync method to perform backup<br />
 * operation asynchronously */<br />
bkpDBLog.SqlBackup(myServer);</td>
</tr>
<tr>
<td><strong>Result:</strong></td>
</tr>
</tbody>
</table>
<p><strong>C# Code Block 4 Backup with Compression </strong>- SQL Server 2008 introduces a new feature to issues <a href="http://www.mssqltips.com/tip.asp?tip=1513">backups in a compressed form</a>.  As such, SMO for SQL Server 2008 has been enhanced to support this feature. If you look at the image below you will notice the compressed backup size is almost 25% of full backup, though the level of compression depends on the several factors.</p>
<table border="1" cellspacing="0" cellpadding="0" width="600" align="center">
<tbody>
<tr>
<td><strong>C# Code Block 4 &#8211; Backup with Compression (SQL Server 2008)</strong></td>
</tr>
<tr>
<td align="left">Backup bkpDBFullWithCompression = new Backup();<br />
/* Specify whether you want to back up database or files or log */<br />
bkpDBFullWithCompression.Action = BackupActionType.Database;<br />
/* Specify the name of the database to back up */<br />
bkpDBFullWithCompression.Database = myDatabase.Name;<br />
/* You can use back up compression technique of SQL Server 2008,<br />
 * specify CompressionOption property to On for compressed backup */<br />
bkpDBFullWithCompression.CompressionOption = BackupCompressionOptions.On;<br />
bkpDBFullWithCompression.Devices.AddDevice(@&#8221;D:\AdventureWorksFullWithCompression.bak&#8221;, DeviceType.File);<br />
bkpDBFullWithCompression.BackupSetName = &#8220;Adventureworks database Backup &#8211; Compressed&#8221;;<br />
bkpDBFullWithCompression.BackupSetDescription = &#8220;Adventureworks database &#8211; Full Backup with Compressin &#8211; only in SQL Server 2008&#8243;;<br />
bkpDBFullWithCompression.SqlBackup(myServer);</td>
</tr>
<tr>
<td><strong>Result:</strong></td>
</tr>
</tbody>
</table>
<p><strong>C# Code Block 5 Full or Differential Restores</strong> &#8211; Thus far we have worked through SMO backup examples. Now let&#8217;s change gears to restore with SMO.  SMO provides a <strong>Restore</strong> class to restore a database, similar to the <strong>Backup</strong> class.  With these classes it is necessary to specify the <strong>Action</strong> property to indicate the type of restore i.e. database, files or log.  In a scenario where if you have additional differential or log backups to be restored after it is necessary to specify the <strong>NoRecovery = true</strong> except for the final restore.  In this example, I am wiring up events of the Restore object instance to event-handlers for progress monitoring. Finally the <strong>SqlRestore</strong> method is called to start the restoration. If you want to start the restore operation asynchronously you would need to call <strong>SqlRestoreAsync</strong> method instead.</p>
<table border="1" cellspacing="0" cellpadding="0" width="600" align="center">
<tbody>
<tr>
<td><strong>C# Code Block 5 &#8211; Database Restore &#8211; Full or Differential</strong></td>
</tr>
<tr>
<td align="left">Restore restoreDB = new Restore();<br />
restoreDB.Database = myDatabase.Name;<br />
/* Specify whether you want to restore database, files or log */<br />
restoreDB.Action = RestoreActionType.Database;<br />
restoreDB.Devices.AddDevice(@&#8221;D:\AdventureWorksFull.bak&#8221;, DeviceType.File);<br />
 <br />
/* You can specify ReplaceDatabase = false (default) to not create a new<br />
 * database, the specified database must exist on SQL Server<br />
 * instance. If you can specify ReplaceDatabase = true to create new<br />
 * database image regardless of the existence of specified database with<br />
 * the same name */<br />
restoreDB.ReplaceDatabase = true; <br />
 <br />
/* If you have a differential or log restore after the current restore,<br />
 * you would need to specify NoRecovery = true, this will ensure no<br />
 * recovery performed and subsequent restores are allowed. It means it<br />
 * the database will be in a restoring state. */<br />
restoreDB.NoRecovery = true;<br />
 <br />
/* Wiring up events for progress monitoring */<br />
restoreDB.PercentComplete += CompletionStatusInPercent;<br />
restoreDB.Complete += Restore_Completed;<br />
 <br />
/* SqlRestore method starts to restore the database<br />
 * You can also use SqlRestoreAsync method to perform restore<br />
 * operation asynchronously */<br />
restoreDB.SqlRestore(myServer);</td>
</tr>
<tr>
<td><strong>Result:</strong></td>
</tr>
</tbody>
</table>
<p>To restore a database SQL Server needs to acquire exclusive lock on the database being restored.  If you try to restore a database which is in use, SQL Server will throw the following exception:</p>
<p><strong>C# Code Block 6 Transaction Log Restore</strong> &#8211; The process of restoring a transactional log is similar to restoring a full or differential backup. While restoring a transactional log, it is necessary to set the property <strong>Action = RestoreActionType.Log</strong> instead of <strong>RestoreActionType.Database</strong> as in case of full/differential restore.  Here is an example:</p>
<table border="1" cellspacing="0" cellpadding="0" width="600" align="center">
<tbody>
<tr>
<td><strong>C# Code Block 6 &#8211; Database Restore &#8211; Log</strong></td>
</tr>
<tr>
<td align="left">Restore restoreDBLog = new Restore();<br />
restoreDBLog.Database = myDatabase.Name;<br />
restoreDBLog.Action = RestoreActionType.Log;<br />
restoreDBLog.Devices.AddDevice(@&#8221;D:\AdventureWorksLog.bak&#8221;, DeviceType.File);<br />
 <br />
/* You can specify NoRecovery = false (default) so that transactions are<br />
 * rolled forward and recovered. */<br />
restoreDBLog.NoRecovery = false;<br />
 <br />
/* Wiring up events for progress monitoring */<br />
restoreDBLog.PercentComplete += CompletionStatusInPercent;<br />
restoreDBLog.Complete += Restore_Completed;<br />
 <br />
/* SqlRestore method starts to restore database<br />
 * You cab also use SqlRestoreAsync method to perform restore<br />
 * operation asynchronously */<br />
restoreDBLog.SqlRestore(myServer);</td>
</tr>
<tr>
<td><strong>Result:</strong></td>
</tr>
</tbody>
</table>
<p><strong>C# Code Block 7 Database Restore to a new location</strong> &#8211; At times you need to create a new database and restore to a new physical location which differs from the original database. For that purpose, the <strong>Restore</strong> class has the <strong>RelocateFiles</strong> collection which can be completed for each file with the new location as shown in the code below.</p>
<table border="1" cellspacing="0" cellpadding="0" width="600" align="center">
<tbody>
<tr>
<td><strong>C# Code Block 7 Database Restore &#8211; Different location</strong></td>
</tr>
<tr>
<td align="left">Restore restoreDB = new Restore();<br />
restoreDB.Database = myDatabase.Name + &#8220;New&#8221;;<br />
/* Specify whether you want to restore database or files or log etc */<br />
restoreDB.Action = RestoreActionType.Database;<br />
restoreDB.Devices.AddDevice(@&#8221;D:\AdventureWorksFull.bak&#8221;, DeviceType.File);<br />
 <br />
/* You can specify ReplaceDatabase = false (default) to not create a new<br />
 * database, the specified database must exist on SQL Server instance.<br />
 * You can specify ReplaceDatabase = true to create new database<br />
 * regardless of the existence of specified database */<br />
restoreDB.ReplaceDatabase = true;<br />
 <br />
/* If you have a differential or log restore to be followed, you would<br />
 * specify NoRecovery = true, this will ensure no recovery is done<br />
 * after the restore and subsequent restores are completed. The database<br />
 * would be in a recovered state. */<br />
restoreDB.NoRecovery = false;<br />
 <br />
/* RelocateFiles collection allows you to specify the logical file names<br />
 * and physical file names (new locations) if you want to restore to a<br />
 * different location.*/<br />
restoreDB.RelocateFiles.Add(new RelocateFile(&#8220;AdventureWorks_Data&#8221;, @&#8221;D:\AdventureWorksNew_Data.mdf&#8221;));<br />
restoreDB.RelocateFiles.Add(new RelocateFile(&#8220;AdventureWorks_Log&#8221;, @&#8221;D:\AdventureWorksNew_Log.ldf&#8221;));<br />
 <br />
/* Wiring up events for progress monitoring */<br />
restoreDB.PercentComplete += CompletionStatusInPercent;<br />
restoreDB.Complete += Restore_Completed;<br />
 <br />
/* SqlRestore method starts to restore database<br />
 * You can also use SqlRestoreAsync method to perform restore<br />
 * operation asynchronously */<br />
restoreDB.SqlRestore(myServer);</td>
</tr>
<tr>
<td><strong>Result:</strong><br />
 </td>
</tr>
</tbody>
</table>
<p>Complete code listing (created on SQL Server 2008 and Visual Studio 2008, though there is not much difference if you are using it on SQL Server 2005 and Visual Studio 2005) can be found in the below text box.</p>
<p>using System;<br />
using System.Collections.Generic;<br />
using System.Text;<br />
using Microsoft.SqlServer.Management.Smo;<br />
using Microsoft.SqlServer.Management.Common;<br />
namespace BackupAndRestoreWithSMO2008<br />
{<br />
    class Program<br />
    {<br />
        static void Main(string[] args)<br />
        {<br />
            Server myServer = new Server(@&#8221;ARSHADALI-LAP\ARSHADALI&#8221;);<br />
            try<br />
            {<br />
                //Using windows authentication<br />
                myServer.ConnectionContext.LoginSecure = true;<br />
                myServer.ConnectionContext.Connect();<br />
                Database myDatabase = myServer.Databases["AdventureWorks"];<br />
                BackupDatabaseFull(myServer, myDatabase);<br />
                //BackupDatabaseDifferential(myServer, myDatabase);<br />
                //BackupDatabaseLog(myServer, myDatabase);<br />
                //BackupDatabaseFullWithCompression(myServer, myDatabase);<br />
               <br />
                RestoreDatabase(myServer, myDatabase);<br />
                //RestoreDatabaseLog(myServer, myDatabase);<br />
                //RestoreDatabaseWithDifferentNameAndLocation(myServer, myDatabase);<br />
            }<br />
            catch (Exception ex)<br />
            {<br />
                Console.WriteLine(ex.Message);<br />
                Console.WriteLine(ex.InnerException.Message);<br />
            }<br />
            finally<br />
            {<br />
                if (myServer.ConnectionContext.IsOpen)<br />
                    myServer.ConnectionContext.Disconnect();<br />
                Console.WriteLine(&#8220;Press any key to terminate&#8230;&#8221;);<br />
                Console.ReadKey();<br />
            }<br />
        }<br />
        private static void BackupDatabaseFull(Server myServer, Database myDatabase)<br />
        {<br />
            Backup bkpDBFull = new Backup();<br />
            /* Specify whether you want to back up database or files or log */<br />
            bkpDBFull.Action = BackupActionType.Database;<br />
            /* Specify the name of the database to back up */<br />
            bkpDBFull.Database = myDatabase.Name;<br />
            /* You can take backup on several media type (disk or tape), here I am using<br />
             * File type and storing backup on the file system */<br />
            bkpDBFull.Devices.AddDevice(@&#8221;D:\AdventureWorksFull.bak&#8221;, DeviceType.File);<br />
            bkpDBFull.BackupSetName = &#8220;Adventureworks database Backup&#8221;;<br />
            bkpDBFull.BackupSetDescription = &#8220;Adventureworks database &#8211; Full Backup&#8221;;<br />
            /* You can specify the expiration date for your backup data<br />
             * after that date backup data would not be relevant */<br />
            bkpDBFull.ExpirationDate = DateTime.Today.AddDays(10);<br />
            /* You can specify Initialize = false (default) to create a new<br />
             * backup set which will be appended as last backup set on the media. You can<br />
             * specify Initialize = true to make the backup as first set on the mediuam and<br />
             * to overwrite any other existing backup sets if the all the backup sets have<br />
             * expired and specified backup set name matches with the name on the medium */<br />
            bkpDBFull.Initialize = false;<br />
            /* Wiring up events for progress monitoring */<br />
            bkpDBFull.PercentComplete += CompletionStatusInPercent;<br />
            bkpDBFull.Complete += Backup_Completed;<br />
            /* SqlBackup method starts to take back up<br />
             * You cab also use SqlBackupAsync method to perform backup<br />
             * operation asynchronously */<br />
            bkpDBFull.SqlBackup(myServer);<br />
        }<br />
        private static void BackupDatabaseDifferential(Server myServer, Database myDatabase)<br />
        {<br />
            Backup bkpDBDifferential = new Backup();<br />
            /* Specify whether you want to back up database or files or log */<br />
            bkpDBDifferential.Action = BackupActionType.Database;<br />
            /* Specify the name of the database to back up */<br />
            bkpDBDifferential.Database = myDatabase.Name;<br />
            /* You can take backup on several media type (disk or tape), here I am using<br />
             * File type and storing backup on the file system */<br />
            bkpDBDifferential.Devices.AddDevice(@&#8221;D:\AdventureWorksDifferential.bak&#8221;, DeviceType.File);<br />
            bkpDBDifferential.BackupSetName = &#8220;Adventureworks database Backup&#8221;;<br />
            bkpDBDifferential.BackupSetDescription = &#8220;Adventureworks database &#8211; Differential Backup&#8221;;<br />
            /* You can specify the expiration date for your backup data<br />
             * after that date backup data would not be relevant */<br />
            bkpDBDifferential.ExpirationDate = DateTime.Today.AddDays(10);<br />
            /* You can specify Initialize = false (default) to create a new<br />
             * backup set which will be appended as last backup set on the media. You can<br />
             * specify Initialize = true to make the backup as first set on the mediuam and<br />
             * to overwrite any other existing backup sets if the all the backup sets have<br />
             * expired and specified backup set name matches with the name on the medium */<br />
            bkpDBDifferential.Initialize = false;<br />
            /* You can specify Incremental = false (default) to perform full backup<br />
             * or Incremental = true to perform differential backup since most recent<br />
             * full backup */<br />
            bkpDBDifferential.Incremental = true;<br />
            /* Wiring up events for progress monitoring */<br />
            bkpDBDifferential.PercentComplete += CompletionStatusInPercent;<br />
            bkpDBDifferential.Complete += Backup_Completed;<br />
            /* SqlBackup method starts to take back up<br />
             * You cab also use SqlBackupAsync method to perform backup<br />
             * operation asynchronously */<br />
            bkpDBDifferential.SqlBackup(myServer);<br />
        }<br />
        private static void BackupDatabaseLog(Server myServer, Database myDatabase)<br />
        {<br />
            Backup bkpDBLog = new Backup();<br />
            /* Specify whether you want to back up database or files or log */<br />
            bkpDBLog.Action = BackupActionType.Log;<br />
            /* Specify the name of the database to back up */<br />
            bkpDBLog.Database = myDatabase.Name;<br />
            /* You can take backup on several media type (disk or tape), here I am using<br />
             * File type and storing backup on the file system */<br />
            bkpDBLog.Devices.AddDevice(@&#8221;D:\AdventureWorksLog.bak&#8221;, DeviceType.File);<br />
            bkpDBLog.BackupSetName = &#8220;Adventureworks database Backup&#8221;;<br />
            bkpDBLog.BackupSetDescription = &#8220;Adventureworks database &#8211; Log Backup&#8221;;<br />
            /* You can specify the expiration date for your backup data<br />
             * after that date backup data would not be relevant */<br />
            bkpDBLog.ExpirationDate = DateTime.Today.AddDays(10);<br />
            /* You can specify Initialize = false (default) to create a new<br />
             * backup set which will be appended as last backup set on the media. You can<br />
             * specify Initialize = true to make the backup as first set on the mediuam and<br />
             * to overwrite any other existing backup sets if the all the backup sets have<br />
             * expired and specified backup set name matches with the name on the medium */<br />
            bkpDBLog.Initialize = false;<br />
            /* Wiring up events for progress monitoring */<br />
            bkpDBLog.PercentComplete += CompletionStatusInPercent;<br />
            bkpDBLog.Complete += Backup_Completed;<br />
            /* SqlBackup method starts to take back up<br />
             * You cab also use SqlBackupAsync method to perform backup<br />
             * operation asynchronously */<br />
            bkpDBLog.SqlBackup(myServer);<br />
        }<br />
        private static void BackupDatabaseFullWithCompression(Server myServer, Database myDatabase)<br />
        {<br />
            Backup bkpDBFullWithCompression = new Backup();<br />
            /* Specify whether you want to back up database or files or log */<br />
            bkpDBFullWithCompression.Action = BackupActionType.Database;<br />
            /* Specify the name of the database to back up */<br />
            bkpDBFullWithCompression.Database = myDatabase.Name;<br />
            /* You can use back up compression technique of SQL Server 2008,<br />
             * specify CompressionOption property to On for compressed backup */<br />
            bkpDBFullWithCompression.CompressionOption = BackupCompressionOptions.On;<br />
            bkpDBFullWithCompression.Devices.AddDevice(@&#8221;D:\AdventureWorksFullWithCompression.bak&#8221;, DeviceType.File);<br />
            bkpDBFullWithCompression.BackupSetName = &#8220;Adventureworks database Backup &#8211; Compressed&#8221;;<br />
            bkpDBFullWithCompression.BackupSetDescription = &#8220;Adventureworks database &#8211; Full Backup with Compressin &#8211; only in SQL Server 2008&#8243;;<br />
            bkpDBFullWithCompression.SqlBackup(myServer);<br />
        }<br />
        private static void CompletionStatusInPercent(object sender, PercentCompleteEventArgs args)<br />
        {<br />
            Console.Clear();<br />
            Console.WriteLine(&#8220;Percent completed: {0}%.&#8221;, args.Percent);<br />
        }<br />
        private static void Backup_Completed(object sender, ServerMessageEventArgs args)<br />
        {<br />
            Console.WriteLine(&#8220;Hurray&#8230;Backup completed.&#8221; );<br />
            Console.WriteLine(args.Error.Message);<br />
        }<br />
        private static void Restore_Completed(object sender, ServerMessageEventArgs args)<br />
        {<br />
            Console.WriteLine(&#8220;Hurray&#8230;Restore completed.&#8221;);<br />
            Console.WriteLine(args.Error.Message);<br />
        }<br />
        private static void RestoreDatabase(Server myServer, Database myDatabase)<br />
        {<br />
            Restore restoreDB = new Restore();<br />
            restoreDB.Database = myDatabase.Name;<br />
            /* Specify whether you want to restore database or files or log etc */<br />
            restoreDB.Action = RestoreActionType.Database;<br />
            restoreDB.Devices.AddDevice(@&#8221;D:\AdventureWorksFull.bak&#8221;, DeviceType.File);<br />
            /* You can specify ReplaceDatabase = false (default) to not create a new image<br />
             * of the database, the specified database must exist on SQL Server instance.<br />
             * If you can specify ReplaceDatabase = true to create new database image<br />
             * regardless of the existence of specified database with same name */<br />
            restoreDB.ReplaceDatabase = true;</p>
<p>            /* If you have differential or log restore to be followed, you would need<br />
             * to specify NoRecovery = true, this will ensure no recovery is done after the<br />
             * restore and subsequent restores are allowed. It means it will database<br />
             * in the Restoring state. */<br />
            restoreDB.NoRecovery = true;<br />
            /* Wiring up events for progress monitoring */<br />
            restoreDB.PercentComplete += CompletionStatusInPercent;<br />
            restoreDB.Complete += Restore_Completed;<br />
            /* SqlRestore method starts to restore database<br />
             * You cab also use SqlRestoreAsync method to perform restore<br />
             * operation asynchronously */<br />
            restoreDB.SqlRestore(myServer);<br />
        }<br />
        private static void RestoreDatabaseLog(Server myServer, Database myDatabase)<br />
        {<br />
            Restore restoreDBLog = new Restore();<br />
            restoreDBLog.Database = myDatabase.Name;<br />
            restoreDBLog.Action = RestoreActionType.Log;<br />
            restoreDBLog.Devices.AddDevice(@&#8221;D:\AdventureWorksLog.bak&#8221;, DeviceType.File);<br />
            /* You can specify NoRecovery = false (default) so that transactions are<br />
             * rolled forward and recovered. */<br />
            restoreDBLog.NoRecovery = false;<br />
            /* Wiring up events for progress monitoring */<br />
            restoreDBLog.PercentComplete += CompletionStatusInPercent;<br />
            restoreDBLog.Complete += Restore_Completed;<br />
            /* SqlRestore method starts to restore database<br />
             * You cab also use SqlRestoreAsync method to perform restore<br />
             * operation asynchronously */<br />
            restoreDBLog.SqlRestore(myServer);<br />
        }<br />
        private static void RestoreDatabaseWithDifferentNameAndLocation(Server myServer, Database myDatabase)<br />
        {<br />
            Restore restoreDB = new Restore();<br />
            restoreDB.Database = myDatabase.Name + &#8220;New&#8221;;<br />
            /* Specify whether you want to restore database or files or log etc */<br />
            restoreDB.Action = RestoreActionType.Database;<br />
            restoreDB.Devices.AddDevice(@&#8221;D:\AdventureWorksFull.bak&#8221;, DeviceType.File);<br />
            /* You can specify ReplaceDatabase = false (default) to not create a new image<br />
             * of the database, the specified database must exist on SQL Server instance.<br />
             * You can specify ReplaceDatabase = true to create new database image<br />
             * regardless of the existence of specified database with same name */<br />
            restoreDB.ReplaceDatabase = true;<br />
            /* If you have differential or log restore to be followed, you would need<br />
             * to specify NoRecovery = true, this will ensure no recovery is done after the<br />
             * restore and subsequent restores are allowed. It means it will database<br />
             * in the Restoring state. */<br />
            restoreDB.NoRecovery = false;<br />
            /* RelocateFiles collection allows you to specify the logical file names and<br />
             * physical file names (new locations) if you want to restore to a different location.*/<br />
            restoreDB.RelocateFiles.Add(new RelocateFile(&#8220;AdventureWorks_Data&#8221;, @&#8221;D:\AdventureWorksNew_Data.mdf&#8221;));<br />
            restoreDB.RelocateFiles.Add(new RelocateFile(&#8220;AdventureWorks_Log&#8221;, @&#8221;D:\AdventureWorksNew_Log.ldf&#8221;));<br />
            /* Wiring up events for progress monitoring */<br />
            restoreDB.PercentComplete += CompletionStatusInPercent;<br />
            restoreDB.Complete += Restore_Completed;<br />
            /* SqlRestore method starts to restore database<br />
             * You cab also use SqlRestoreAsync method to perform restore<br />
             * operation asynchronously */<br />
            restoreDB.SqlRestore(myServer);<br />
        }<br />
    }<br />
}</p>
<p><strong><em>Notes:</em></strong></p>
<ul>
<li>Location of assemblies in SQL Server 2005 is the <span style="text-decoration:underline;">C:\Program Files\Microsoft SQL Server\90\SDK\Assemblies</span> folder.</li>
<li>Location of assemblies in SQL Server 2008 is the <span style="text-decoration:underline;">C:\Program Files\Microsoft SQL Server\100\SDK\Assemblies</span> folder.</li>
<li>In SQL Server 2005, the <strong>Backup</strong> and <strong>Restore</strong> classes are available in the <strong>Microsoft.SqlServer.Management.Smo</strong> namespace and in the <strong>Microsoft.SqlServer.Smo</strong> (microsoft.sqlserver.smo.dll) assembly.</li>
<li>In SQL Server 2008, the <strong>Backup</strong> and <strong>Restore</strong> classes are available in the <strong>Microsoft.SqlServer.Management.Smo</strong> namespace and in the <strong>Microsoft.SqlServer.SmoExtended</strong> (microsoft.sqlserver.smoextended.dll) assembly.</li>
<li>If you are restoring a transaction log, you can specify a particular point in time with <strong>ToPointInTime</strong> property of the <strong>Restore</strong> class.</li>
<li>The <strong>Restore</strong> class methods (<strong>SqlVerify</strong>, <strong>SqlVerifyAsync</strong> and <strong>SqlVerifyLatest</strong>) to verify and validate (backup set is complete and the entire backup is readable) the backup media before restoration.</li>
<li>The SQL Server service account must have access to the folders where backup or restore operations are executed.</li>
<li>You need to have sufficient permissions to perform backup and restore operations. For example, for backup you need to be either in sysadmin/db_owner/db_backupoperator role or must have BACKUP DATABASE or BACKUP LOG permission on the database.</li>
<li>If you try to connect SQL Server 2008 from SMO 2005, you will get an exception &#8220;SQL Server &#60;10.0&#62; version is not supported&#8221;.</li>
</ul>
<p><strong><span style="text-decoration:underline;">Next Steps</span></strong></p>
<ul>
<li>Review the following tips:
<ul>
<li><a href="http://www.mssqltips.com/tip.asp?tip=1826">Getting started with SQL Server Management Objects (SMO)</a></li>
<li><a href="http://www.mssqltips.com/tip.asp?tip=1833" target="_blank">SQL Script Generation Programmatically with SMO</a></li>
<li><a href="http://www.mssqltips.com/tip.asp?tip=1513">Exploring Database Backup Compression in SQL Server 2008</a></li>
</ul>
</li>
<li>Review <a href="http://msdn.microsoft.com/en-us/library/microsoft.sqlserver.management.smo.backup.aspx">Backup</a> and <a href="http://msdn.microsoft.com/en-us/library/microsoft.sqlserver.management.smo.restore.aspx">Restore</a> classes on MSDN.</li>
<li>Review the MSSQLTips <a href="http://www.mssqltips.com/category.asp?catid=8" target="_blank">Backup and Recovery category</a> with 40+ tips.</li>
</ul>
<p><span style="text-decoration:underline;"><strong>Readers Who Read This Tip Also Read</strong></span></p>
<ul>
<li><a href="http://www.mssqltips.com/tip.asp?tip=1860">How to identify when a database was restored, the source of the backup and the date of the backup</a></li>
<li><a href="http://www.mssqltips.com/tip.asp?tip=1854">How to Backup and Restore a SQL Server FILESTREAM Enabled Database</a></li>
<li><a href="http://www.mssqltips.com/tip.asp?tip=1809">Restore a SQL Server Database to a New Database to Minimize Downtime</a></li>
<li><a href="http://www.mssqltips.com/tip.asp?tip=1779">Mirrored Database Backup Feature in SQL Server 2005 and SQL Server 2008</a></li>
<li><a href="http://www.mssqltips.com/tip.asp?tip=1772">Copy Only Backup for SQL Server 2005 and SQL Server 2008</a></li>
<li><a href="http://www.mssqltips.com/category.asp?catid=8">More&#8230;</a></li>
</ul>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[Checking SQL Server Agent jobs using Windows PowerShell ]]></title>
<link>http://esersahin.wordpress.com/2009/10/29/checking-sql-server-agent-jobs-using-windows-powershell/</link>
<pubDate>Thu, 29 Oct 2009 12:39:39 +0000</pubDate>
<dc:creator>esersahin</dc:creator>
<guid>http://esersahin.wordpress.com/2009/10/29/checking-sql-server-agent-jobs-using-windows-powershell/</guid>
<description><![CDATA[http://www.mssqltips.com/tip.asp?tip=1798 Problem Checking for SQL Server Agent jobs and their statu]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p><a href="http://www.mssqltips.com/tip.asp?tip=1798">http://www.mssqltips.com/tip.asp?tip=1798</a></p>
<p><span style="text-decoration:underline;"><strong>Problem<br />
</strong></span>Checking for SQL Server Agent jobs and their status is part of your daily task as a DBA. How do we use Windows PowerShell to check for SQL Server Agent jobs?</p>
<p><span style="text-decoration:underline;"><strong>Solution</strong></span><br />
Similar to the task described in the tip <a href="http://www.mssqltips.com/tip.asp?tip=1784">Check the Last SQL Server Backup Date using Windows PowerShell</a>, it would require reading the tables in the <strong>msdb</strong> database and joining them appropriately to find out which jobs failed. Two tables in particular are of interest to us to check for job execution information like job name, execution status, run date, run time, etc. &#8211; the <strong>sysjobs</strong> and <strong>sysjobhistory</strong> tables. 
<p>&#160;</p>
<p>The <a href="http://www.mssqltips.com/tip.asp?tip=1054" target="_blank">script below</a> displays a list of jobs on your SQL Server instance with there status.
<p>&#160;</p>
<table border="1" cellspacing="0" cellpadding="4" width="500">
<tbody>
<tr>
<td><strong><span style="font-family:Arial;font-size:x-small;">USE msdb <br />
GO <br />
SELECT <br />
   j.[name] AS [JobName], <br />
   run_status = CASE h.run_status <br />
   WHEN 0 THEN &#8217;Failed&#8217;<br />
   WHEN 1 THEN &#8217;Succeeded&#8217;<br />
   WHEN 2 THEN &#8217;Retry&#8217;<br />
   WHEN 3 THEN &#8217;Canceled&#8217;<br />
   WHEN 4 THEN &#8217;In progress&#8217;<br />
   END,<br />
   h.run_date AS LastRunDate,  <br />
   h.run_time AS LastRunTime<br />
FROM sysjobhistory h <br />
   INNER JOIN sysjobs j ON h.job_id = j.job_id <br />
       WHERE j.enabled = 1  <br />
       AND h.instance_id IN <br />
       (SELECT MAX(h.instance_id) <br />
           FROM sysjobhistory h GROUP BY (h.job_id))<br />
GO </span></strong>
<p>&#160;</p>
</td>
</tr>
</tbody>
</table>
<p><img src="http://www.mssqltips.com/tipImages2/1798_1.jpg" alt="" width="553" height="309" />
<p>&#160;</p>
<p>Notice that the <strong>run_date </strong>and <strong>run_time</strong> columns of the <strong>sysjobhistory</strong> table are of type <strong>int</strong> and would be a bit challenging to convert the columns to their appropriate data types.  Server Management Objects (SMO) exposes these properties when using Windows PowerShell. The <a href="http://msdn.microsoft.com/en-us/library/microsoft.sqlserver.management.smo.server.jobserver.aspx" target="_blank">JobServer</a> property of the <a href="http://msdn.microsoft.com/en-us/library/microsoft.sqlserver.management.smo.server.aspx">Server</a> object represents the SQL Server Agent associated with an instance of SQL Server. This includes the SQL Server jobs, operators and alerts.When translating the T-SQL query above to Windows PowerShell, we would be interested in the <strong>Name</strong>, <strong>LastRunDate</strong> and <strong>LastRunOutcome</strong> properties of the <strong><a href="http://msdn.microsoft.com/en-us/library/microsoft.sqlserver.management.smo.agent.jobserver.jobs.aspx">Jobs</a></strong> object. What&#8217;s really good to note is that the <strong>LastRunDate</strong> property is in a <strong>datetime</strong> format that no longer requires conversion to the appropriate data type, similar to what we get from the <strong>sysjobhistory </strong>table in <strong>the msdb database</strong>.  I keep trying to highlight this for every tip I&#8217;ve written that uses PowerShell with SMO.  The only aspect of the code that we have changed from the scripts in the previous tips is the last line, i.e. adding new properties for the new objects we are working with. This highlights the power and simplicity of Windows PowerShell from the script.</p>
<table border="1" cellspacing="0" cellpadding="4" width="600">
<tbody>
<tr>
<td><span style="font-family:Arial;font-size:x-small;"><strong>[System.Reflection.Assembly]::LoadWithPartialName(&#8216;Microsoft.SqlServer.SMO&#8217;) &#124; out-null<br />
$rvs = New-Object (&#8216;Microsoft.SqlServer.Management.Smo.Server&#8217;) &#8220;LOCALHOST\SQL2000&#8243; </strong></span>
<p>&#160;</p>
<p><span style="font-family:Arial;font-size:x-small;"><strong>#Create an instance of the Jobs object collection from the JobServer property<br />
#And pipes that to the filter Where-Object cmdlet to retrieve only those jobs that are enabled but failed<br />
$srv.JobServer.Jobs &#124; Where-Object {$_.IsEnabled -eq $TRUE} &#124; Select Name,LastRunOutcome, LastRunDate<br />
 </strong></span>
<p>&#160;</p>
</td>
</tr>
</tbody>
</table>
<p><img src="http://www.mssqltips.com/tipImages2/1798_2.jpg" alt="" width="635" height="189" />
<p>&#160;</p>
<p>Notice that the <strong>LastRunDate</strong> property is in the correct data type. The <strong>LastRunOutcome</strong> property is returned as they are without the need for further translations as in the T-SQL script above. Let&#8217;s call to the Excel object as we did in the previous tips to format the results. Again, the script above is more than enough for what we need.</p>
<table border="1" cellspacing="0" cellpadding="4" width="600">
<tbody>
<tr>
<td><span style="font-family:Arial;font-size:x-small;">#Create a new Excel object using COM<br />
<strong>$Excel = New-Object -ComObject Excel.Application<br />
$Excel.visible = $True</strong></span>
<p>&#160;</p>
<p><span style="font-family:Arial;font-size:x-small;"><strong>$Excel = $Excel.Workbooks.Add()<br />
$Sheet = $Excel.Worksheets.Item(1)</p>
<p>#Counter variable for rows</strong><br />
<strong>$intRow = 1</strong></span>
<p>&#160;</p>
<p><span style="font-family:Arial;font-size:x-small;">#Read thru the contents of the SQL_Servers.txt file<br />
<strong>foreach ($instance in get-content &#8220;D:\SQL_Servers.txt&#8221;)</strong><br />
<strong>{</strong></span>
<p>&#160;</p>
<p><span style="font-family:Arial;font-size:x-small;"><strong>     #Create column headers</strong><br />
<strong>     $Sheet.Cells.Item($intRow,1) = &#8220;INSTANCE NAME:&#8221;</strong><br />
<strong>     $Sheet.Cells.Item($intRow,2) = $instance</strong><br />
<strong>     $Sheet.Cells.Item($intRow,1).Font.Bold = $True</strong><br />
<strong>     $Sheet.Cells.Item($intRow,2).Font.Bold = $True</strong></span>
<p>&#160;</p>
<p><span style="font-family:Arial;font-size:x-small;"><strong>     $intRow++</strong></span>
<p>&#160;</p>
<p><span style="font-family:Arial;font-size:x-small;"><strong>      $Sheet.Cells.Item($intRow,1) = &#8220;JOB NAME&#8221;</strong><br />
<strong>      $Sheet.Cells.Item($intRow,2) = &#8220;LAST RUN OUTCOME&#8221;</strong><br />
<strong>      $Sheet.Cells.Item($intRow,3) = &#8220;LAST RUN DATE&#8221;</strong><br />
</span>
<p>&#160;</p>
<p><span style="font-family:Arial;font-size:x-small;"><strong>     #Format the column headers</strong><br />
<strong>     for ($col = 1; $col –le 3; $col++)</strong><br />
<strong>     {</strong><br />
<strong>          $Sheet.Cells.Item($intRow,$col).Font.Bold = $True</strong><br />
<strong>          $Sheet.Cells.Item($intRow,$col).Interior.ColorIndex = 48</strong><br />
<strong>          $Sheet.Cells.Item($intRow,$col).Font.ColorIndex = 34</strong><br />
<strong>     }</strong><br />
</span>
<p>&#160;</p>
<p><span style="font-family:Arial;font-size:x-small;"><strong>     $intRow++</strong><br />
<strong>      #######################################################</strong><br />
<strong>     #This script gets SQL Server Agent job status information using PowerShell</strong><br />
</span>
<p>&#160;</p>
<p><span style="font-family:Arial;font-size:x-small;"><strong>     [System.Reflection.Assembly]::LoadWithPartialName(&#8216;Microsoft.SqlServer.SMO&#8217;) &#124; out-null</strong></span>
<p>&#160;</p>
<p><span style="font-family:Arial;font-size:x-small;"><strong>     # Create an SMO connection to the instance</strong><br />
<strong>     $srv = New-Object (&#8216;Microsoft.SqlServer.Management.Smo.Server&#8217;) $instance</strong></span>
<p>&#160;</p>
<p><span style="font-family:Arial;font-size:x-small;"><strong>     $jobs=$srv.JobServer.Jobs</strong></span>
<p>&#160;</p>
<p><span style="font-family:Arial;font-size:x-small;"><strong>     #Formatting using Excel</strong> </span>
<p>&#160;</p>
<p><strong><span style="font-family:Arial;"><span style="font-size:x-small;"><br />
</span><span style="font-size:x-small;">ForEach ($job in $jobs) <br />
{</p>
<p>       #<em> Formatting for the failed jobs </em><br />
       if ($job.LastRunOutcome -eq 0)<br />
       {<br />
           $fgColor = 3<br />
       }<br />
       else<br />
       {<br />
           $fgColor = 0<br />
       }<br />
    </span></span>
<p>&#160;</p>
<p><span style="font-family:Arial;font-size:x-small;">       $Sheet.Cells.Item($intRow, 1) =  $job.Name<br />
       $Sheet.Cells.Item($intRow, 2) = $job.LastRunOutcome.ToString()<br />
       $Sheet.Cells.item($intRow, 2).Interior.ColorIndex = $fgColor<br />
       $Sheet.Cells.Item($intRow, 3) =  $job.LastRunDate</p>
<p>   <br />
           <br />
       $intRow ++<br />
   <br />
}<br />
   $intRow ++</p>
<p>}</span>
<p>&#160;</p>
<p><span style="font-family:Arial;font-size:x-small;">$Sheet.UsedRange.EntireColumn.AutoFit()<br />
cls<br />
</span>
<p>&#160;</p>
<p></strong></td>
</tr>
</tbody>
</table>
<p><img src="http://www.mssqltips.com/tipImages2/1798_3.jpg" alt="" width="650" height="467" /> 
<p>&#160;</p>
<p><span style="text-decoration:underline;"><strong>Next Steps </strong></span>
<p>&#160;</p>
<ul>
<li>Try converting your T-SQL DBA scripts to Windows PowerShell</li>
<li>Read more on the <a href="http://msdn.microsoft.com/en-us/library/cc194731(SQL.90).aspx">SMO Class Library</a> to translate SQL Server objects that we are already familiar with to SMO objects</li>
<li>Check out some recent PowerShell scripts:
<ul>
<li><a href="http://www.mssqltips.com/tip.asp?tip=1784">Check the Last SQL Server Backup Date using Windows PowerShell</a></li>
<li><a href="http://www.mssqltips.com/tip.asp?tip=1759">Retrieve List of Databases and their Properties using PowerShell</a></li>
<li><a href="http://www.mssqltips.com/tip.asp?tip=1745">Using PowerShell with SQL Server Management Objects (SMO)</a></li>
<li><a href="http://www.mssqltips.com/tip.asp?tip=1680">Introduction to Windows PowerShell for the SQL Server DBA Part 1</a></li>
<li><a href="http://www.mssqltips.com/tip.asp?tip=1703">Introduction to Windows PowerShell for the SQL Server DBA Part 2</a></li>
</ul>
</li>
</ul>
<p><span style="text-decoration:underline;"><strong>Readers Who Read This Tip Also Read</strong></span></p>
<ul>
<li><a href="http://www.mssqltips.com/tip.asp?tip=1862">Backup SQL Server Databases with a Windows PowerShell Script</a></li>
<li><a href="http://www.mssqltips.com/tip.asp?tip=1842">Generating SQL Scripts using Windows PowerShell</a></li>
<li><a href="http://www.mssqltips.com/tip.asp?tip=1784">Check the Last SQL Server Backup Date using Windows PowerShell</a></li>
<li><a href="http://www.mssqltips.com/tip.asp?tip=1759">Retrieve a List of SQL Server Databases and their Properties using PowerShell</a></li>
<li><a href="http://www.mssqltips.com/tip.asp?tip=1745">Using PowerShell with SQL Server Management Objects (SMO)</a></li>
<li><a href="http://www.mssqltips.com/category.asp?catid=81">More&#8230;</a></li>
</ul>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[Backup SQL Server Databases with a Windows PowerShell Script]]></title>
<link>http://esersahin.wordpress.com/2009/10/29/backup-sql-server-databases-with-a-windows-powershell-script/</link>
<pubDate>Thu, 29 Oct 2009 12:38:08 +0000</pubDate>
<dc:creator>esersahin</dc:creator>
<guid>http://esersahin.wordpress.com/2009/10/29/backup-sql-server-databases-with-a-windows-powershell-script/</guid>
<description><![CDATA[http://www.mssqltips.com/tip.asp?tip=1862&amp;home Problem In a previous tip on Backup and Restore S]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p><a href="http://www.mssqltips.com/tip.asp?tip=1862&#38;home">http://www.mssqltips.com/tip.asp?tip=1862&#38;home</a></p>
<p><span style="text-decoration:underline;"><strong>Problem<br />
</strong></span>In a previous tip on <a href="http://www.mssqltips.com/tip.asp?tip=1849">Backup and Restore SQL Server databases programmatically with SMO</a>, you&#8217;ve seen how you can use Windows PowerShell to backup and restore SQL Server databases. In this tip, I will cover how to use Windows PowerShell to generate <a href="http://www.mssqltips.com/category.asp?catid=8">SQL Server backups</a>.
<p>&#160;</p>
<p><span style="text-decoration:underline;"><strong>Solution</strong></span><br />
<a href="http://www.mssqltips.com/category.asp?catid=8">Generating and maintaining backups</a> are the most important tasks that any DBA has to fulfill. And, as mentioned in the previous <a href="http://www.mssqltips.com/tip.asp?tip=1849">tip</a>, SMO can be used to <a href="http://www.mssqltips.com/category.asp?catid=8">backup and restore a database</a>. There are different ways to backup a database, depending on company policies on <a href="http://www.mssqltips.com/category.asp?catid=4">disaster recovery</a>. We will be introducing a new SMO namespace that will allow us to create the <a href="http://msdn.microsoft.com/en-us/library/microsoft.sqlserver.management.smo.backup.aspx">Backup</a> object. This is an added line in our previous <a href="http://www.mssqltips.com/category.asp?catid=81">PowerShell scripts</a> to create a new instance of the Backup object.
<p>&#160;</p>
<table border="1" cellpadding="3" width="600">
<tbody>
<tr>
<td><span style="font-family:Courier New;font-size:x-small;">$dbBackup = new-object (&#8220;Microsoft.SqlServer.Management.Smo.Backup&#8221;)</span>
<p>&#160;</p>
</td>
</tr>
</tbody>
</table>
<p>The first property of the Backup object that we need to assign is the name of the database that we need to do a backup on. This is defined by the <a href="http://msdn.microsoft.com/en-us/library/microsoft.sqlserver.management.smo.backuprestorebase.database.aspx">Database</a> property of the Backup object. The code snippet below defines a Database property for the Backup object to perform a backup on the Northwind database.
<p>&#160;</p>
<table border="1" cellpadding="3" width="600">
<tbody>
<tr>
<td><span style="font-family:Courier New;font-size:x-small;">$dbBackup.Database = &#8220;Northwind&#8221; </span>
<p>&#160;</p>
</td>
</tr>
</tbody>
</table>
<p>Whenever you generate or create backups, SMO considers this as a <a href="http://msdn.microsoft.com/en-us/library/microsoft.sqlserver.management.smo.backuprestorebase.devices.aspx">Device</a>. This requires us to add the Backup file to the Devices collection of the Backup object, specifying the <a href="http://msdn.microsoft.com/en-us/library/microsoft.sqlserver.management.smo.devicetype.aspx">DeviceType</a> as File. The first parameter in the <a href="http://msdn.microsoft.com/en-us/library/microsoft.sqlserver.management.smo.backupdevicelist.adddevice.aspx">AddDevice</a> method of the Devices collection is the file name of the backup file with the full path as stored in the file system whereas the second parameter is the DeviceType. While SQL Server supports the use of devices, I normally recommend using the file system to easily identify the backup sets based on the file name using the proper naming convention (one thing you would not want to be worried about during disaster recovery is scrambling to find the valid backup sets).
<p>&#160;</p>
<table border="1" cellpadding="3" width="600">
<tbody>
<tr>
<td><span style="font-family:Courier New;font-size:x-small;">$dbBackup.Devices.AddDevice(&#8220;yourDBbackupFile.bak&#8221;, &#8220;File&#8221;)</span>
<p>&#160;</p>
</td>
</tr>
</tbody>
</table>
<p>The next important property of the Backup object that we are interested in is the <a href="http://msdn.microsoft.com/en-us/library/microsoft.sqlserver.management.smo.backup.action.aspx">Action</a> property. The Action property sets the type of backup to be performed &#8211; Database, Log or File. The default value of the Action property is set to Database. This property is of importance based on the definition of our service level agreement as you don&#8217;t just generate backups without understanding the defined SLAs for a specific database or application. For our example, we will define a FULL database backup
<p>&#160;</p>
<table border="1" cellpadding="3" width="600">
<tbody>
<tr>
<td><span style="font-family:Courier New;font-size:x-small;">$dbBackup.Action = &#8220;Database&#8221;</span>
<p>&#160;</p>
</td>
</tr>
</tbody>
</table>
<p>Once we have defined the properties of our Backup object, it&#8217;s just a matter of calling the <a href="http://msdn.microsoft.com/en-us/library/microsoft.sqlserver.management.smo.backup.sqlbackup.aspx">SqlBackup</a> method of the Backup object. The SqlBackup method performs the backup operation as defined by the properties you have set in the Backup object. It accepts a parameter of type <a href="http://msdn.microsoft.com/en-us/library/microsoft.sqlserver.management.smo.server.aspx">Server</a> which represents the SQL Server instance that you have defined as the source of the backup operation.
<p>&#160;</p>
<table border="1" cellpadding="3" width="600">
<tbody>
<tr>
<td><span style="font-family:Courier New;font-size:x-small;">$dbBackup.SqlBackup($s)</span>
<p>&#160;</p>
</td>
</tr>
</tbody>
</table>
<p>Combining the code snippets above, here is a working Windows PowerShell script to perform a FULL database backup against the Northwind database, storing the backup file in your file system.
<p>&#160;</p>
<table border="1" cellpadding="3" width="800">
<tbody>
<tr>
<td><span style="font-family:Courier New;font-size:x-small;">[System.Reflection.Assembly]::LoadWithPartialName(&#8216;Microsoft.SqlServer.SMO&#8217;) &#124; out-null<br />
$s = New-Object (&#8216;Microsoft.SqlServer.Management.Smo.Server&#8217;) &#8220;LOCALHOST\SQL2005_1&#8243; </span>
<p>&#160;</p>
<p><span style="font-family:Courier New;font-size:x-small;">#Create a Backup object instance with the Microsoft.SqlServer.Management.Smo.Backup namespace<br />
$dbBackup = new-object (&#8220;Microsoft.SqlServer.Management.Smo.Backup&#8221;) </span>
<p>&#160;</p>
<p><span style="font-family:Courier New;font-size:x-small;">#Set the Database property to Northwind<br />
$dbBackup.Database = &#8220;Northwind&#8221; </span>
<p>&#160;</p>
<p><span style="font-family:Courier New;font-size:x-small;">#Add the backup file to the Devices collection and specify File as the backup type<br />
$dbBackup.Devices.AddDevice(&#8220;D:\PSScripts\backups\NWind_FULL.bak&#8221;, &#8220;File&#8221;)</span>
<p>&#160;</p>
<p><span style="font-family:Courier New;font-size:x-small;">#Specify the Action property to generate a FULL backup<br />
$dbBackup.Action=&#8221;Database&#8221;</span>
<p>&#160;</p>
<p><span style="font-family:Courier New;font-size:x-small;">#Call the SqlBackup method to generate the backup<br />
$dbBackup.SqlBackup($s)</span>
<p>&#160;</p>
</td>
</tr>
</tbody>
</table>
<p>Now, since you won&#8217;t be performing backups of just a single database, it would be better if we loop the entire script in a <strong>For-Each</strong> cmdlet iterating thru the <strong>Databases</strong> collection of the <strong>Server</strong> object.
<p>&#160;</p>
<table border="1" cellpadding="3" width="800">
<tbody>
<tr>
<td><span style="font-family:Courier New;font-size:x-small;">[System.Reflection.Assembly]::LoadWithPartialName(&#8220;Microsoft.SqlServer.SMO&#8221;) &#124; out-null<br />
$s = new-object (&#8220;Microsoft.SqlServer.Management.Smo.Server&#8221;) $instance</span>
<p>&#160;</p>
<p><span style="font-family:Courier New;font-size:x-small;">$bkdir = &#8220;D:\PSScripts\backups&#8221; #We define the folder path as a variable<br />
$dbs = $s.Databases<br />
foreach ($db in $dbs)<br />
{<br />
     if($db.Name -ne &#8220;tempdb&#8221;) #We don&#8217;t want to backup the tempdb database<br />
     {<br />
     $dbname = $db.Name<br />
     $dt = get-date -format yyyyMMddHHmm #We use this to create a file name based on the timestamp<br />
     $dbBackup = new-object (&#8220;Microsoft.SqlServer.Management.Smo.Backup&#8221;)<br />
     $dbBackup.Action = &#8220;Database&#8221;<br />
     $dbBackup.Database = $dbname<br />
     $dbBackup.Devices.AddDevice($bkdir + &#8220;\&#8221; + $dbname + &#8220;_db_&#8221; + $dt + &#8220;.bak&#8221;, &#8220;File&#8221;)<br />
     $dbBackup.SqlBackup($s)<br />
     }<br />
}</span>
<p>&#160;</p>
</td>
</tr>
</tbody>
</table>
<p>While my only condition for generating backups is to exclude the <strong>tempdb</strong> database, you can include other conditions such as querying the database property if it is used for database mirroring (<a href="http://msdn.microsoft.com/en-us/library/microsoft.sqlserver.management.smo.database.ismirroringenabled.aspx">IsMirroringEnabled</a> property) or specifying database names if you are sure enough that you won&#8217;t be needing backups for them. While not really necessary, you also might want to include other Backup object properties such as <a href="http://msdn.microsoft.com/en-us/library/microsoft.sqlserver.management.smo.backup.backupsetdescription.aspx">BackupSetName</a>, <a href="http://msdn.microsoft.com/en-us/library/microsoft.sqlserver.management.smo.backup.backupsetdescription.aspx">BackupSetDescription</a>, and <a href="http://msdn.microsoft.com/en-us/library/microsoft.sqlserver.management.smo.backup.mediadescription.aspx">MediaDescription</a> as they can be of help in case you wanted to find out the contents of your backup sets.
<p>&#160;</p>
<p><strong>NOTE</strong>: If you have SQL Server 2008 Client Tools installed on your workstation where you intend to run this PowerShell script, it is important that you add a reference to the <strong>Microsoft.SqlServer.SmoExtended </strong>namespace. The Backup object and a few other objects were moved from the <strong>Microsoft.SqlServer.Smo</strong> to the <strong>Microsoft.SqlServer.SmoExtended</strong>. In the example I provided, I have SQL Server 2005 and SQL Server 2008 running on my machine, thus, requiring that I add a reference to the <strong>Microsoft.SqlServer.SmoExtended</strong> namespace. SQL Server MVP <a href="https://mvp.support.microsoft.com/profile/Allen.White">Allen White</a> has blogged about <a href="http://sqlblog.com/blogs/allen_white/archive/2008/12/07/loading-smo-assemblies-into-powershell.aspx">Loading SMO Assemblies in PowerShell</a> and explains using a custom script to load appropriate SMO assemblies depending on the SQL Server version.</p>
<table border="1" cellpadding="3" width="800">
<tbody>
<tr>
<td><span style="font-family:Courier New;font-size:x-small;">[System.Reflection.Assembly]::LoadWithPartialName(&#8220;Microsoft.SqlServer.SMO&#8221;)&#124; out-null<br />
[System.Reflection.Assembly]::LoadWithPartialName(&#8220;Microsoft.SqlServer.SmoExtended&#8221;)&#124; out-null</span>
<p>&#160;</p>
</td>
</tr>
</tbody>
</table>
<h4><em><strong>Generating Differential and Log Backups</strong></em></h4>
<p>Depending on your service level agreement, you would also need to define either Differential or Log backups to complement your Full backups. This can be done by changing the Action property of the Backup object to either Log for Log backups or setting the <a href="http://msdn.microsoft.com/en-us/library/microsoft.sqlserver.management.smo.backup.incremental.aspx">Incremental</a> property of the Backup object to a value of 1. Below is a code snippet for generating Log backups, simply by changing the Action property.
<p>&#160;</p>
<table border="1" cellpadding="3" width="600">
<tbody>
<tr>
<td><span style="font-family:Courier New;font-size:x-small;">$dbBackup.Action = &#8220;Log&#8221;</span>
<p>&#160;</p>
</td>
</tr>
</tbody>
</table>
<p>Note that you can only do Log backups on databases that are not configured to use the SIMPLE recovery model. This means that your condition for generating Log backups would include a check on the <a href="http://msdn.microsoft.com/en-us/library/microsoft.sqlserver.management.smo.database.recoverymodel.aspx">RecoveryModel</a> property
<p>&#160;</p>
<table border="1" cellpadding="3" width="800">
<tbody>
<tr>
<td><strong>    </strong><span style="font-family:Courier New;font-size:x-small;"> if($db.RecoveryModel -ne 3) #Don&#8217;t issue Log backups for DBs with RecoveryModel=3 or SIMPLE<br />
     {<br />
     $dbname = $db.Name<br />
     $dt = get-date -format yyyyMMddHHmm #Create a file name based on the timestamp<br />
     $dbBackup = new-object (&#8220;Microsoft.SqlServer.Management.Smo.Backup&#8221;)<br />
     $dbBackup.Action = &#8220;Log&#8221;<br />
     $dbBackup.Database = $dbname<br />
     $dbBackup.Devices.AddDevice($bkdir + &#8220;\&#8221; + $dbname + &#8220;_log_&#8221; + $dt + &#8220;.trn&#8221;, &#8220;File&#8221;)<br />
     $dbBackup.SqlBackup($s)<br />
     } </span>
<p>&#160;</p>
</td>
</tr>
</tbody>
</table>
<p>For Differential backups, you would need to replace the Action property with the Incremental property and set the value to 1
<p>&#160;</p>
<table border="1" cellpadding="3" width="800">
<tbody>
<tr>
<td><strong>  </strong><span style="font-family:Courier New;font-size:x-small;">   if($db.Name -ne &#8220;tempdb&#8221;)<br />
     {<br />
     $dbname = $db.Name<br />
     $dt = get-date -format yyyyMMddHHmm #Create a file name based on the timestamp<br />
     $dbBackup = new-object (&#8220;Microsoft.SqlServer.Management.Smo.Backup&#8221;)<br />
     $dbBackup.Incremental = 1<br />
     $dbBackup.Database = $dbname<br />
     $dbBackup.Devices.AddDevice($bkdir + &#8220;\&#8221; + $dbname + &#8220;_diff_&#8221; + $dt + &#8220;.bak&#8221;, &#8220;File&#8221;)<br />
     $dbBackup.SqlBackup($s)<br />
     } </span>
<p>&#160;</p>
</td>
</tr>
</tbody>
</table>
<p>Your backup strategies, depending on your service level agreement, will definitely include a combination of either Full and Differential and/or Log backups.
<p>&#160;</p>
<p><span style="text-decoration:underline;"><strong>Next Steps</strong></span>
<p>&#160;</p>
<ul>
<li>Read more on the <a href="http://msdn.microsoft.com/en-us/library/microsoft.sqlserver.management.smo.backup.aspx">Backup</a> class in SMO</li>
<li>Review the tip <a href="http://www.mssqltips.com/tip.asp?tip=1849">Backup and Restore SQL Server databases programmatically with SMO</a></li>
<li>Test how you can use <a href="http://www.mssqltips.com/category.asp?catid=81">Windows PowerShell</a> to generate your <a href="http://www.mssqltips.com/category.asp?catid=8">SQL Server backups</a>.</li>
</ul>
<p><span style="text-decoration:underline;"><strong>Readers Who Read This Tip Also Read</strong></span></p>
<ul>
<li><a href="http://www.mssqltips.com/tip.asp?tip=1842">Generating SQL Scripts using Windows PowerShell</a></li>
<li><a href="http://www.mssqltips.com/tip.asp?tip=1798">Checking SQL Server Agent jobs using Windows PowerShell </a></li>
<li><a href="http://www.mssqltips.com/tip.asp?tip=1784">Check the Last SQL Server Backup Date using Windows PowerShell</a></li>
<li><a href="http://www.mssqltips.com/tip.asp?tip=1759">Retrieve a List of SQL Server Databases and their Properties using PowerShell</a></li>
<li><a href="http://www.mssqltips.com/tip.asp?tip=1745">Using PowerShell with SQL Server Management Objects (SMO)</a></li>
<li><a href="http://www.mssqltips.com/category.asp?catid=81">More&#8230;</a></li>
</ul>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[How to schedule a database backup operation by using SQL Server Management Studio in SQL Server 2005]]></title>
<link>http://nightbugs.wordpress.com/2009/08/06/how-to-schedule-a-database-backup-operation-by-using-sql-server-management-studio-in-sql-server-2005/</link>
<pubDate>Thu, 06 Aug 2009 10:13:50 +0000</pubDate>
<dc:creator>sborkar</dc:creator>
<guid>http://nightbugs.wordpress.com/2009/08/06/how-to-schedule-a-database-backup-operation-by-using-sql-server-management-studio-in-sql-server-2005/</guid>
<description><![CDATA[http://support.microsoft.com/kb/930615]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p>http://support.microsoft.com/kb/930615</p>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[Automated SQL Server Backup: Poor Man's Edition]]></title>
<link>http://dbalink.wordpress.com/2009/04/25/automated-sql-server-back-poor-mans-edition/</link>
<pubDate>Sat, 25 Apr 2009 23:02:48 +0000</pubDate>
<dc:creator>MarlonRibunal</dc:creator>
<guid>http://dbalink.wordpress.com/2009/04/25/automated-sql-server-back-poor-mans-edition/</guid>
<description><![CDATA[Small companies that cannot afford high-end appliances and software are resorting to custom solution]]></description>
<content:encoded><![CDATA[Small companies that cannot afford high-end appliances and software are resorting to custom solution]]></content:encoded>
</item>
<item>
<title><![CDATA[SQL Server 2005 Interview Questions]]></title>
<link>http://sampleinterviewquestions.wordpress.com/2008/11/16/sql-server-2005-interview-questions/</link>
<pubDate>Sun, 16 Nov 2008 16:46:12 +0000</pubDate>
<dc:creator>sk</dc:creator>
<guid>http://sampleinterviewquestions.wordpress.com/2008/11/16/sql-server-2005-interview-questions/</guid>
<description><![CDATA[• If I want to see what fields a table is made of, and what the sizes of the fields are, what option]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p><strong>• If I want to see what fields a table is made of, and what the sizes  of the<br />
fields are, what option do I have to look for?<br />
</strong>Sp_Columns  ‘TableName’</p>
<p><strong>• What is a query?</strong><br />
A request for information from a  database. There are three general methods for posing queries:<br />
# Choosing  parameters from a menu: In this method, the database system presents a list of  parameters from which you can choose. This is perhaps the easiest way to pose a  query because the menus guide you, but it is also the least flexible.<br />
# Query  by example (QBE): In this method, the system presents a blank record and lets  you specify the fields and values that define the query.<br />
# Query language:  Many database systems require you to make requests for information in the form  of a stylized query that must be written in a special query language. This is  the most complex method because it forces you to learn a specialized language,  but it is also the most powerful.</p>
<p><strong>• What is the purpose of the model database?</strong><br />
It works as  Template Database for the Create Database Syntax</p>
<p><strong>• What is the purpose of the master database?</strong><br />
Master  database keeps the information about sql server configuration, databases users  etc</p>
<p><strong>• What is the purpose of the tempdb database?</strong><br />
Tempdb  database keeps the information about the temporary objects (#TableName,  #Procedure). Also the sorting, DBCC operations are performed in the TempDB</p>
<p><strong>• What is the purpose of the USE command?</strong><br />
Use command is  used for to select the database. For i.e Use Database Name</p>
<p><strong>• If you delete a table in the database, will the data in the table  be deleted too?</strong><br />
Yes</p>
<p><strong>• What is the Parse Query button used for? How does this help  you?</strong><br />
Parse query button is used to check the SQL Query Syntax</p>
<p><strong>• Tables are created in a ____________________ in SQL Server  2005.</strong><br />
resouce database(System Tables)</p>
<p><strong>• What is usually the first word in a SQL  query?</strong><br />
SELECT</p>
<p><strong>• Does a SQL Server 2005 SELECT statement require a  FROM?</strong><br />
NO</p>
<p><strong>• Can a SELECT statement in SQL Server 2005 be used to make an  assignment? Explain with examples.</strong><br />
Yes. Select @MyDate =  GetDate()</p>
<p><strong>• What is the ORDER BY used for?</strong><br />
Order By clause is used  for sorting records in Ascending or Descending order</p>
<p><strong>• Does ORDER BY actually change the order of the data in the tables  or does it just<br />
change the output?</strong><br />
Order By clause change only  the output of the data</p>
<p><strong>• What is the default order of an ORDER BY  clause?</strong><br />
Ascending Order</p>
<p><strong>• What kind of comparison operators can be used in a WHERE  clause?</strong></p>
<table border="1" width="680">
<tbody>
<tr>
<th>Operator</th>
<th>Meaning</th>
</tr>
<tr>
<td><a id="ctl00_rs1_mainContentContainer_ctl01" href="http://msdn.microsoft.com/en-us/library/ms175118.aspx">= (Equals)</a></td>
<td>Equal to</td>
</tr>
<tr>
<td><a id="ctl00_rs1_mainContentContainer_ctl02" href="http://msdn.microsoft.com/en-us/library/ms178590.aspx">&#62; (Greater  Than)</a></td>
<td>Greater than</td>
</tr>
<tr>
<td><a id="ctl00_rs1_mainContentContainer_ctl03" href="http://msdn.microsoft.com/en-us/library/ms179873.aspx">&#60; (Less  Than)</a></td>
<td>Less than</td>
</tr>
<tr>
<td><a id="ctl00_rs1_mainContentContainer_ctl04" href="http://msdn.microsoft.com/en-us/library/ms181567.aspx">&#62;= (Greater Than  or Equal To)</a></td>
<td>Greater than or equal to</td>
</tr>
<tr>
<td><a id="ctl00_rs1_mainContentContainer_ctl05" href="http://msdn.microsoft.com/en-us/library/ms174978.aspx">&#60;= (Less Than or  Equal To)</a></td>
<td>Less than or equal to</td>
</tr>
<tr>
<td><a id="ctl00_rs1_mainContentContainer_ctl06" href="http://msdn.microsoft.com/en-us/library/ms176020.aspx">&#60;&#62; (Not Equal  To)</a></td>
<td>Not equal to</td>
</tr>
<tr>
<td><a id="ctl00_rs1_mainContentContainer_ctl07" href="http://msdn.microsoft.com/en-us/library/ms190296.aspx">!= (Not Equal  To)</a></td>
<td>Not equal to (not SQL-92 standard)</td>
</tr>
<tr>
<td><a id="ctl00_rs1_mainContentContainer_ctl08" href="http://msdn.microsoft.com/en-us/library/ms189808.aspx">!&#60; (Not Less  Than)</a></td>
<td>Not less than (not SQL-92 standard)</td>
</tr>
<tr>
<td><a id="ctl00_rs1_mainContentContainer_ctl09" href="http://msdn.microsoft.com/en-us/library/ms184364.aspx">!&#62; (Not Greater  Than)</a></td>
<td>Not greater than (not SQL-92 standard)</td>
</tr>
</tbody>
</table>
<p><strong>• What are four major operators that can be used to combine  conditions on a WHERE<br />
clause? </strong></p>
<p>OR, AND, IN and BETWEEN</p>
<p><strong>• What are the logical operators?</strong></p>
<table border="1" width="676">
<tbody>
<tr>
<th>Operator</th>
<th>Meaning</th>
</tr>
<tr>
<td><a id="ctl00_rs1_mainContentContainer_ctl01" href="http://msdn.microsoft.com/en-us/library/ms178543.aspx">ALL</a></td>
<td>TRUE if all of a set of comparisons are TRUE.</td>
</tr>
<tr>
<td><a id="ctl00_rs1_mainContentContainer_ctl02" href="http://msdn.microsoft.com/en-us/library/ms188372.aspx">AND</a></td>
<td>TRUE if both Boolean expressions are TRUE.</td>
</tr>
<tr>
<td><a id="ctl00_rs1_mainContentContainer_ctl03" href="http://msdn.microsoft.com/en-us/library/ms189526.aspx">ANY</a></td>
<td>TRUE if any one of a set of comparisons are TRUE.</td>
</tr>
<tr>
<td><a id="ctl00_rs1_mainContentContainer_ctl04" href="http://msdn.microsoft.com/en-us/library/ms187922.aspx">BETWEEN</a></td>
<td>TRUE if the operand is within a range.</td>
</tr>
<tr>
<td><a id="ctl00_rs1_mainContentContainer_ctl05" href="http://msdn.microsoft.com/en-us/library/ms188336.aspx">EXISTS</a></td>
<td>TRUE if a subquery contains any rows.</td>
</tr>
<tr>
<td><a id="ctl00_rs1_mainContentContainer_ctl06" href="http://msdn.microsoft.com/en-us/library/ms177682.aspx">IN</a></td>
<td>TRUE if the operand is equal to one of a list of expressions.</td>
</tr>
<tr>
<td><a id="ctl00_rs1_mainContentContainer_ctl07" href="http://msdn.microsoft.com/en-us/library/ms179859.aspx">LIKE</a></td>
<td>TRUE if the operand matches a pattern.</td>
</tr>
<tr>
<td><a id="ctl00_rs1_mainContentContainer_ctl08" href="http://msdn.microsoft.com/en-us/library/ms189455.aspx">NOT</a></td>
<td>Reverses the value of any other Boolean operator.</td>
</tr>
<tr>
<td><a id="ctl00_rs1_mainContentContainer_ctl09" href="http://msdn.microsoft.com/en-us/library/ms188361.aspx">OR</a></td>
<td>TRUE if either Boolean expression is TRUE.</td>
</tr>
<tr>
<td><a id="ctl00_rs1_mainContentContainer_ctl10" href="http://msdn.microsoft.com/en-us/library/ms175064.aspx">SOME</a></td>
<td>TRUE if some of a set of comparisons are TRUE.</td>
</tr>
</tbody>
</table>
<p><strong>•In a WHERE clause, do you need to enclose a text column in quotes?  Do you need to enclose a numeric column in quotes?</strong><br />
Enclose Text in  Quotes (Yes)<br />
Enclose Number in Quotes (NO)</p>
<p><strong>• Is a null value equal to anything? Can a space in a column be  considered a null value? Why or why not?</strong><br />
No NULL value means  nothing. We can’t consider space as NULL value.</p>
<p><strong>• Will COUNT(column) include columns with null values in its  count?</strong><br />
Yes, it will include the null column in count</p>
<p><strong>• What are column aliases? Why would you want to use column aliases?  How can you embed blanks in column aliases?</strong><br />
You can create aliases  for column names to make it easier to work with column names, calculations, and  summary values. For example, you can create a column alias to:<br />
* Create a  column name, such as “Total Amount,” for an expression such as (quantity *  unit_price) or for an aggregate function.<br />
* Create a shortened form of a  column name, such as “d_id” for “discounts.stor_id.”<br />
After you have defined a  column alias, you can use the alias in a Select query to specify query  output</p>
<p><strong>• What are table aliases?</strong><br />
Aliases can make it easier to  work with table names. Using aliases is helpful when:<br />
* You want to make the  statement in the SQL Pane shorter and easier to read.<br />
* You refer to the  table name often in your query — such as in qualifying column names — and want  to be sure you stay within a specific character-length limit for your query.  (Some databases impose a maximum</p>
<p>length for queries.)<br />
* You are working with multiple instances of the same  table (such as in a self-join) and need a way to refer to one instance or the  other.</p>
<p><strong>• What are table qualifiers? When should table qualifiers be  used?</strong><br />
[@table_qualifier =] qualifier<br />
Is the name of the table or  view qualifier. qualifier is sysname, with a default of NULL. Various DBMS  products support three-part naming for tables (qualifier.owner.name). In SQL  Server, this column represents the database name. In some products, it  represents the server name of the table’s database environment.</p>
<p><strong>• Are semicolons required at the end of SQL statements in SQL Server  2005?</strong><br />
No it is not required<br />
<strong><br />
• Do comments need to go  in a special place in SQL Server 2005?</strong><br />
No its not  necessary<br />
<strong><br />
• When would you use the ROWCOUNT function versus using  the WHERE clause?</strong><br />
Returns the number of rows affected by the last  statement. If the number of rows is more than 2 billion, use  ROWCOUNT_BIG.<br />
Transact-SQL statements can set the value in @@ROWCOUNT in the  following ways:<br />
* Set @@ROWCOUNT to the number of rows affected or read. Rows  may or may not be sent to the client.<br />
* Preserve @@ROWCOUNT from the previous  statement execution.<br />
* Reset @@ROWCOUNT to 0 but do not return the value to  the client.<br />
Statements that make a simple assignment always set the  @@ROWCOUNT value to 1.<br />
<strong><br />
• Is SQL case-sensitive? Is SQL Server  2005 case-sensitive?</strong><br />
No both are not case-sensitive. Case  sensitivity depends on the collation you choose.<br />
If you installed SQL Server  with the default collation options, you might find that the following queries  return the same results:</p>
<p>CREATE TABLE mytable<br />
(<br />
mycolumn VARCHAR(10)<br />
)<br />
GO</p>
<p>SET NOCOUNT ON</p>
<p>INSERT mytable VALUES(’Case’)<br />
GO</p>
<p>SELECT mycolumn FROM mytable WHERE mycolumn=’Case’<br />
SELECT mycolumn FROM  mytable WHERE mycolumn=’caSE’<br />
SELECT mycolumn FROM mytable WHERE  mycolumn=’case’</p>
<p>You can alter your query by forcing collation at the column level:</p>
<p>SELECT myColumn FROM myTable<br />
WHERE myColumn COLLATE Latin1_General_CS_AS =  ‘caSE’</p>
<p>SELECT myColumn FROM myTable<br />
WHERE myColumn COLLATE Latin1_General_CS_AS =  ‘case’</p>
<p>SELECT myColumn FROM myTable<br />
WHERE myColumn COLLATE Latin1_General_CS_AS =  ‘Case’</p>
<p>– if myColumn has an index, you will likely benefit by adding<br />
– AND  myColumn = ‘case’<br />
<strong><br />
• What is a synonym? Why would you want to  create a synonym?</strong><br />
SYNONYM is a single-part name that can replace a  two, three or four-part name in many SQL statements. Using SYNONYMS in RDBMS  cuts down on typing.<br />
SYNONYMs can be created for the following objects:</p>
<p>* Table<br />
* View<br />
* Assembly (CLR) Stored Procedure<br />
* Assembly (CLR)  Table-valued Function<br />
* Assembly (CLR) Scalar Function<br />
* Assembly  Aggregate (CLR) Aggregate Functions<br />
* Replication-filter-procedure<br />
*  Extended Stored Procedure<br />
* SQL Scalar Function<br />
* SQL Table-valued  Function<br />
* SQL Inline-table-valued Function<br />
* SQL Stored Procedure</p>
<p><strong>Syntax</strong><br />
CREATE SYNONYM [ schema_name_1. ] synonym_name FOR  &#60; object &#62;</p>
<p>&#60; object &#62; :: =<br />
{<br />
[ server_name.[ database_name ] . [  schema_name_2 ].&#124; database_name . [ schema_name_2 ].&#124; schema_name_2. ]  object_name<br />
}</p>
<p><strong>• Can a synonym name of a table be used instead of a table name in a  SELECT statement?</strong><br />
Yes</p>
<p><strong>• Can a synonym of a table be used when you are trying to alter the  definition of a table?</strong><br />
Not Sure will try</p>
<p><strong>• Can you type more than one query in the query editor screen at the  same time?</strong><br />
Yes we can.</p>
<p><strong>• While you are inserting values into a table with the INSERT INTO ..  VALUES option, does the order of the columns in the INSERT statement have to be  the same as the order of the columns in the table?</strong><br />
Not Necessary</p>
<p><strong>• While you are inserting values into a table with the INSERT INTO ..  SELECT option, does the order of the columns in the INSERT statement have to be  the same as the order of the columns in the table?</strong><br />
Yes if you are  not specifying the column names in the insert clause, you need to maintain the  column order in SELECT statement</p>
<p><strong>• When would you use an INSERT INTO .. SELECT option versus an INSERT  INTO .. VALUES option? Give an example of each.</strong><br />
INSERT INTO ..  SELECT is used insert data in to table from diffrent tables or condition based  insert<br />
INSERT INTO .. VALUES you have to specify the insert values</p>
<p><strong>• What does the UPDATE command do?</strong><br />
Update command will  modify the existing record<br />
<strong><br />
• Can you change the data type of a  column in a table after the table has been created? If so,which command would  you use?</strong><br />
Yes we can. Alter Table Modify Column</p>
<p><strong>• Will SQL Server 2005 allow you to reduce the size of a  column?</strong><br />
Yes it allows</p>
<p><strong>• What integer data types are available in SQL Server  2005?</strong></p>
<p>Exact-number data types that use integer data.</p>
<table border="1" width="734">
<tbody>
<tr>
<th>Data type</th>
<th>Range</th>
<th>Storage</th>
</tr>
<tr>
<td><strong>bigint </strong></td>
<td>-2^63 (-9,223,372,036,854,775,808) to 2^63-1  (9,223,372,036,854,775,807)</td>
<td>8 Bytes</td>
</tr>
<tr>
<td><strong>int </strong></td>
<td>-2^31 (-2,147,483,648) to 2^31-1 (2,147,483,647)</td>
<td>4 Bytes</td>
</tr>
<tr>
<td><strong>smallint </strong></td>
<td>-2^15 (-32,768) to 2^15-1 (32,767)</td>
<td>2 Bytes</td>
</tr>
<tr>
<td><strong>tinyint </strong></td>
<td>0 to 255</td>
<td>1 Byte</td>
</tr>
</tbody>
</table>
<p><strong><br />
• What is the default value of an integer data type in SQL Server  2005?</strong><br />
NULL<br />
<strong></strong><br />
<strong>• What is the difference  between a CHAR and a VARCHAR datatype?</strong></p>
<p><strong>CHAR</strong> and <strong>VARCHAR</strong> data types are both  non-Unicode character data types with a maximum length of 8,000 characters. The  main difference between these 2 data types is that a <strong>CHAR</strong> data  type is fixed-length while a <strong>VARCHAR</strong> is variable-length. If the  number of characters entered in a <strong>CHAR</strong> data type column is less  than the declared column length, spaces are appended to it to fill up the whole  length.</p>
<p>Another difference is in the storage size wherein the storage size for  <strong>CHAR</strong> is <em>n</em> bytes while for <strong>VARCHAR</strong> is  the actual length in bytes of the data entered (and not <em>n</em> bytes).</p>
<p>You should use <strong>CHAR</strong> data type when the data values in a  column are expected to be consistently close to the same size. On the other  hand, you should use <strong>VARCHAR</strong> when the data values in a column  are expected to vary considerably in size.</p>
<p><strong>• Does Server SQL treat CHAR as a variable-length or fixed-length  column?</strong><br />
SQL Server treats CHAR as fixed length column</p>
<p><strong>• If you are going to have too many nulls in a column, what would be  the best data type to use?</strong><br />
Variable length columns only use a very  small amount of space to store a NULL so VARCHAR datatype is the good option for  null values<br />
<strong><br />
• When columns are added to existing tables, what do  they initially contain?</strong><br />
The column initially contains the NULL  values<br />
<strong><br />
• What command would you use to add a column to a table in  SQL Server?</strong><br />
ALTER TABLE tablename ADD column_name DATATYPE</p>
<p><strong>• Does an index slow down updates on indexed  columns?</strong><br />
Yes<br />
<strong><br />
• What is a  constraint?</strong><br />
Constraints in Microsoft SQL Server 2000/2005 allow us  to define the ways in which we can automatically enforce the integrity of a  database. Constraints define rules regarding permissible values allowed in  columns and are the standard mechanism for enforcing integrity. Using  constraints is preferred to using triggers, stored procedures, rules, and  defaults, as a method of implementing data integrity rules. The query optimizer  also uses constraint definitions to build high-performance query execution  plans.</p>
<p><strong>• How many indexes does SQL Server 2005 allow you to have on a  table?</strong><br />
250 indices per table</p>
<p><strong>• What command would you use to create an index?</strong><br />
CREAT  INDEX INDEXNAME ON TABLE(COLUMN NAME)</p>
<p><strong>• What is the default ordering that will be created by an index  (ascending or descending)?</strong><br />
Clustered indexes can be created in SQL  Server databases. In such cases the logical order of the index key values will  be the same as the physical order of rows in the table.<br />
By default it is  ascending order, we can also specify the index order while index  creation.<br />
CREATE [ UNIQUE ] [ CLUSTERED &#124; NONCLUSTERED ] INDEX  index_name<br />
ON { table &#124; view } ( column [ ASC &#124; DESC ] [ ,...n ] )</p>
<p><strong>• How do you delete an index?</strong><br />
DROP INDEX  authors.au_id_ind</p>
<p><strong>• What does the NOT NULL constraint do?</strong><br />
Constrain will  not allow NULL values in the column</p>
<p><strong>• What command must you use to include the NOT NULL constraint after  a table has already been created?</strong><br />
DEFAULT, WITH CHECK or WITH  NOCHECK</p>
<p><strong>• When a PRIMARY KEY constraint is included in a table, what other  constraints does this imply?</strong><br />
Unique + NOT NULL<br />
<strong><br />
• What  is a concatenated primary key?</strong><br />
Each table has one and only one  primary key, which can consist of one or many columns. A concatenated primary  key comprises two or more columns. In a single table, you might find several  columns, or groups of columns, that might serve as a primary key and are called  candidate keys. A table can have more than one candidate key, but only one  candidate key can become the primary key for that table</p>
<p><strong>• How are the UNIQUE and PRIMARY KEY constraints  different?</strong><br />
A UNIQUE constraint is similar to PRIMARY key, but you  can have more than one UNIQUE constraint per table.</p>
<p>When you declare a UNIQUE constraint, SQL Server creates a UNIQUE index to  speed up the process of searching for duplicates. In this case the index  defaults to NONCLUSTERED index, because you can have only one CLUSTERED index  per table.</p>
<p>* The number of UNIQUE constraints per table is limited by the number of  indexes on the table i.e 249 NONCLUSTERED index and one possible CLUSTERED  index.</p>
<p>Contrary to PRIMARY key UNIQUE constraints can accept NULL but just once. If  the constraint is defined in a combination of fields, then every field can  accept NULL and can have some values on them, as long as the combination values  is unique.<br />
<strong><br />
• What is a referential integrity constraint? What two  keys does the referential integrity constraint usually  include?</strong><br />
Referential integrity in a relational database is  consistency between coupled tables. Referential integrity is usually enforced by  the combination of a primary key or candidate key (alternate key) and a foreign  key. For referential integrity to hold, any field in a table that is declared a  foreign key can contain only values from a parent table’s primary key or a  candidate key. For instance, deleting a record that contains a value referred to  by a foreign key in another table would break referential integrity. The  relational database management system (RDBMS) enforces referential integrity,  normally either by deleting the foreign key rows as well to maintain integrity,  or by returning an error and not performing the delete. Which method is used  would be determined by the referential integrity constraint, as defined in the  data dictionary.<br />
<strong><br />
• What is a foreign key?</strong><br />
FOREIGN KEY  constraints identify the relationships between tables.<br />
A foreign key in one  table points to a candidate key in another table. Foreign keys prevent actions  that would leave rows with foreign key values when there are no candidate keys  with that value. In the following sample, the order_part table establishes a  foreign key referencing the part_sample table defined earlier. Usually,  order_part would also have a foreign key against an order table, but this is a  simple example.</p>
<p>CREATE TABLE order_part<br />
(order_nmbr int,<br />
part_nmbr int<br />
FOREIGN KEY  REFERENCES part_sample(part_nmbr)<br />
ON DELETE NO ACTION,<br />
qty_ordered  int)<br />
GO</p>
<p>You cannot insert a row with a foreign key value (except NULL) if there is no  candidate key with that value. The ON DELETE clause controls what actions are  taken if you attempt to delete a row to which existing foreign keys point. The  ON DELETE clause has two options:</p>
<p>NO ACTION specifies that the deletion fails with an error.</p>
<p>CASCADE specifies that all the rows with foreign keys pointing to the deleted  row are also deleted.<br />
The ON UPDATE clause defines the actions that are taken  if you attempt to update a candidate key value to which existing foreign keys  point. It also supports the NO ACTION and CASCADE options.</p>
<p><strong><br />
• What does the ON DELETE CASCADE option do?</strong><br />
ON  DELETE CASCADE<br />
Specifies that if an attempt is made to delete a row with a  key referenced by foreign keys in existing rows in other tables, all rows  containing those foreign keys are also deleted. If cascading referential actions  have also been defined on the target tables, the specified cascading actions are  also taken for the rows deleted from those tables.</p>
<p>ON UPDATE CASCADE<br />
Specifies that if an attempt is made to update a key  value in a row, where the key value is referenced by foreign keys in existing  rows in other tables, all of the foreign key values are also updated to the new  value specified for the key. If cascading referential actions have also been  defined on the target tables, the specified cascading actions are also taken for  the key values updated in those tables.</p>
<p><strong><br />
• What does the ON UPDATE NO ACTION do?</strong><br />
ON DELETE NO  ACTION<br />
Specifies that if an attempt is made to delete a row with a key  referenced by foreign keys in existing rows in other tables, an error is raised  and the DELETE is rolled back.</p>
<p>ON UPDATE NO ACTION<br />
Specifies that if an attempt is made to update a key  value in a row whose key is referenced by foreign keys in existing rows in other  tables, an error is raised and the UPDATE is rolled back.</p>
<p><strong>• Can you use the ON DELETE and ON UPDATE in the same  constraint?</strong><br />
Yes we can.<br />
CREATE TABLE part_sample<br />
(part_nmbr  int PRIMARY KEY,<br />
part_name char(30),<br />
part_weight  decimal(6,2),<br />
part_color char(15) )</p>
<p>CREATE TABLE order_part<br />
(order_nmbr int,<br />
part_nmbr int<br />
FOREIGN KEY  REFERENCES part_sample(part_nmbr)<br />
ON DELETE NO ACTION ON UPDATE NO  ACTION,<br />
qty_ordered int)<br />
GO</p>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[HyperBac White Paper by Dell]]></title>
<link>http://databasechronicles.wordpress.com/2008/04/14/hyperbac-white-paper-by-dell/</link>
<pubDate>Mon, 14 Apr 2008 09:00:05 +0000</pubDate>
<dc:creator>jeffreyaven</dc:creator>
<guid>http://databasechronicles.wordpress.com/2008/04/14/hyperbac-white-paper-by-dell/</guid>
<description><![CDATA[Senior Systems Engineers from Dell have recently concluded extensive testing and profiling of the Hy]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p><span>Senior Systems Engineers from Dell have recently concluded extensive testing and profiling of the HyperBac for SQL Server and HyperBac for Oracle (Windows and Linux) products at their Vendor Performance Laboratories in Austin, TX.  Dell has released a white paper entitled:<br />
</span><br />
<a href="http://www.dell.com/downloads/global/solutions/Dell_hyperbac_white_paper.pdf">HyperBac Delivers High-Performance Database Backup for SQL Server and Oracle on Dell-EMC Infrastructure</a></p>
<p><span>This paper details the results of the tests conducted including VLDB testing on SQL Server.  The white paper can be downloaded directly from the dell.com web site using the link above, there is also a summary of this paper in the following link</p>
<p><a href="http://hyperbac.blogspot.com/2008/04/dell-performance-review-of-hyperbac.html">Summary of Dell White Paper on HyperBac for SQL Server and Oracle</a><br />
</span></p>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[SQL Server Backup Compression Shootout]]></title>
<link>http://databasechronicles.wordpress.com/2008/04/07/sql-server-backup-compression-shootout/</link>
<pubDate>Mon, 07 Apr 2008 16:03:00 +0000</pubDate>
<dc:creator>jeffreyaven</dc:creator>
<guid>http://databasechronicles.wordpress.com/2008/04/07/sql-server-backup-compression-shootout/</guid>
<description><![CDATA[HyperBac for SQL Server recently featured in the April edition of SQL Server Magazine in an article ]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p align="justify">HyperBac for SQL Server recently featured in the April edition of SQL Server Magazine in an article titled &#8216;SQL Server Backup Compression Shootout&#8217;. The article tested three well known SQL Server backup products including HyperBac against one another with HyperBac coming out in the lead with a 4 out of 5 star rating.</p>
<p align="justify">The summary of HyperBac from the article is below:</p>
<p align="justify"><strong>HyperBac for SQL Server</strong><br />
<strong>Pros:</strong> Excellent integration with SQL Server; no updating of SQL Server Agent jobs or T-SQL scripts; simple installation; ZIP functionality; compression of bcp, DTS, and SQL Server Integration Services (SSIS) files to disk; fastest restore of products compared Cons: No GUI-based backup tools<br />
<strong>Rating:</strong> 4 stars<br />
<strong>Price:</strong> $699 per server<br />
<strong>Recommendation:</strong> HyperBac for SQL Server matches the way many DBAs like to work and integrates with SQL Server seamlessly out of the box. Coupled with innovative features such as backing up to a .zip file and the ability to compress bcp, DTS, and SSIS streams to and from files, HyperBac for SQL Server is a clear winner.<br />
<strong>Contact:</strong> HyperBac Technologies • <a href="http://www.hyperbac.com/" target="_blank">www.hyperbac.com</a></p>
<p>The full article is available at <a href="http://www.sqlmag.com/Article/ArticleID/98180/sql_server_98180.html">http://www.sqlmag.com/Article/ArticleID/98180/sql_server_98180.html</a></p>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[History of backup compression for SQL Server Part I]]></title>
<link>http://databasechronicles.wordpress.com/2008/02/19/history-of-backup-compression-for-sql-server-part-i/</link>
<pubDate>Tue, 19 Feb 2008 03:44:52 +0000</pubDate>
<dc:creator>jeffreyaven</dc:creator>
<guid>http://databasechronicles.wordpress.com/2008/02/19/history-of-backup-compression-for-sql-server-part-i/</guid>
<description><![CDATA[A chronology of the SQL Server compressed backup software market from 2001-2007 from a co-founder of]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p><em>A chronology of the SQL Server compressed backup software market from 2001-2007 from a co-founder of LiteSpeed.</em></p>
<p>In 2001, a small group of developer/DBAs from Melbourne, Australia discovered a significant shortcoming in SQL Server when it came to backing up VLDB databases.  It took far too long and consumed an unacceptable amount of disk and tape, in addition the IO workload placed on a SQL Server when moving hundreds of GB (or even TB on rare occasions at that juncture in time).  There were no viable alternatives available at the time to relieve these issues.  The developers began working on a project which would be called SQL LiteSpeed, later to be re-named LiteSpeed for SQL Server.</p>
<p>The SQL LiteSpeed architecture involved an out of process executable which requested data from SQL Server using the Virtual Device Interface (VDI), an API typically used by the likes of Veritas, Legato, ArcServe, etc to write data to tape (or disk staging areas).  The exe was accessed in process from SQL Server by using Extended Stored Procedures (xp_backup_database, xp_restore_database, etc).  SQL LiteSpeed was suitable priced and licensed for the SQL Server market at the time and was effectively positioned and marketed to the community, subsequently the product rapidly gained momentum, acceptability and market share.</p>
<p>In early 2004, Insight Venture Partners (a New York based technology investment company) acquired a majority stake in DBAssociatesIT (the founding company for SQL LiteSpeed).  Insight appointed the outgoing VP of Sales for Embarcadero as the new CEO.  The newly formed entity was named “Imceda”.  Over the course of 2004-2005, sales and marketing efforts for the LiteSpeed product intensified substantially.</p>
<p>During the period of 2004-2005, the SQL Server compressed backup market was seen by other vendors to be very lucrative as well and subsequently spawned various other products including Idera’s SQL Safe (released in Q3-2004) and Red Gates SQL Backup (initially called Yohz Mini SQL Backup prior to its acquisition by Red Gate).  All of these products essentially mirrored the initial SQL LiteSpeed architecture (invoking the backup from TSQL using extended stored procedures either directly or indirectly).  Efforts from all vendors were focused mainly on graphical enhancements to their respective management console interfaces for differentiation. </p>
<p>At this stage, the <a target="_blank" href="http://weblog.infoworld.com/dbunderground/archives/2006/04/backup_war_goes.html">SQL Server backup wars</a> were raging, with the end users often finding themselves precariously placed in the middle of the battlefield between the various combatants.</p>
<p>In Q2-2005, Imceda was acquired by Quest Software for $60M, and sales and marketing efforts were taken to another level altogether.  By this time only one of the original founders of SQL LiteSpeed remained with Quest.  The other two co-founders, which included the developer who wad written the entire SQL LiteSpeed engine code, had departed Imceda between Feb and Sep 2004. </p>
<p>After their respective departures from Imceda in 2004 &#8211; long before the QSFT acquisition, the two co-founders of SQL LiteSpeed got together to explore an alternative way to achieve the LiteSpeed value with a unique, extensible architecture, which would subsequently extend features and benefits beyond that of what any other technologies on the market were capable of delivering.  The new technology was called HyperBac.</p>
<p>After serving out their individual non-compete agreements, which originated with the Insight transaction and were commuted to Quest after their acquisition of Imceda, the co-founders of SQL LiteSpeed released HyperBac.</p>
<p>HyperBac took a completely different approach to achieving SQL Server backup compression, using filter driver technology (using standard, supported Microsoft platform APIs as provided to many other file system driver development companies) to seamlessly compress SQL Server backup data streams as they are written from SQL Server to disk.</p>
<p>HyperBac was the first technology to introduce this new architecture, which was a marked departure from the numerous extended stored procedure based products available on the market to date.  HyperBac allowed DBA’s to use native TSQL to perform backups with integrated high performance compression and encryption.  Moreover, HyperBac’s architecture extended backup compression to other DBMS’s besides SQL Server, something not achieved by any other third party software vendor at the time.  In addition the co-founders implemented several other innovations including the capability of performing backups directly to a ZIP/RAR compatible storage format, as opposed to a proprietary storage format creating an indefinite dependence on a third party software vendor to extract or restore companies data.</p>
<p>In Q3-2007, Microsoft announced that it was to release their own implementation of integrated backup compression in SQL Server 2008.  This feature would be available in the Enterprise Edition of SQL Server 2008.  Which takes us to today, Part II to follow…</p>
<p>More information on HyperBac for SQL Server is available at <a href="http://www.hyperbac.com/sqlserver/">http://www.hyperbac.com/sqlserver/</a></p>
<p>More information on compression in Microsoft SQL Server 2008 is available at <a href="http://www.microsoft.com/sql/2008/default.mspx">http://www.microsoft.com/sql/2008/default.mspx</a></p>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[SQL Server 2005 Backup]]></title>
<link>http://dbalink.wordpress.com/2008/01/22/sql-server-2005-backup/</link>
<pubDate>Tue, 22 Jan 2008 05:09:53 +0000</pubDate>
<dc:creator>MarlonRibunal</dc:creator>
<guid>http://dbalink.wordpress.com/2008/01/22/sql-server-2005-backup/</guid>
<description><![CDATA[Most of the people, if not all, who work around the SQL Server know how to backup their databases by]]></description>
<content:encoded><![CDATA[Most of the people, if not all, who work around the SQL Server know how to backup their databases by]]></content:encoded>
</item>
<item>
<title><![CDATA[Simple SQL Backup]]></title>
<link>http://csharpdeveloper.wordpress.com/2008/01/22/simple-sql-backup/</link>
<pubDate>Tue, 22 Jan 2008 02:21:13 +0000</pubDate>
<dc:creator>robkraft</dc:creator>
<guid>http://csharpdeveloper.wordpress.com/2008/01/22/simple-sql-backup/</guid>
<description><![CDATA[This quick post is not about C#, though my program was written in C# Express Edition.  The program a]]></description>
<content:encoded><![CDATA[This quick post is not about C#, though my program was written in C# Express Edition.  The program a]]></content:encoded>
</item>

</channel>
</rss>
