<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://sqlblog.com/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Michael Zilberstein : Misc</title><link>http://sqlblog.com/blogs/michael_zilberstein/archive/tags/Misc/default.aspx</link><description>Tags: Misc</description><dc:language>en</dc:language><generator>CommunityServer 2.1 SP2 (Build: 61129.1)</generator><item><title>NHibernate wonders</title><link>http://sqlblog.com/blogs/michael_zilberstein/archive/2009/02/17/11934.aspx</link><pubDate>Mon, 16 Feb 2009 21:06:11 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:11934</guid><dc:creator>Michael Zilberstein</dc:creator><slash:comments>7</slash:comments><comments>http://sqlblog.com/blogs/michael_zilberstein/comments/11934.aspx</comments><wfw:commentRss>http://sqlblog.com/blogs/michael_zilberstein/commentrss.aspx?PostID=11934</wfw:commentRss><description>&lt;p&gt;This ORM piece of tool just can't stop to surprise. A week ago I've found out that although NHibernate can execute stored procedure, it doesn't support output parameters - when procedure returns one, it causes failure. Today I've found another pearl. Imagine following scenario: 2 entities with many-to-many relationship between them. For example, projects and employees - project contains many employees, employee can participate in several projects. So we have ProjectsEmployees table that maps employees to projects. Done with a foreword, now the scenario itself. Project X contains 9 employees already mapped to it in the ProjectsEmployees table. We want to add another employee to the project. Just a simple INSERT operation, right? NHibernate doesn't look for easy ways. It performs the following operations:&lt;/p&gt;  &lt;p&gt;1. DELETE FROM ProjectsEmployees WHERE ProjectID = X&lt;/p&gt;  &lt;p&gt;2-11. INSERT INTO ProjectsEmployees VALUES()...&lt;/p&gt;  &lt;p&gt;Instead of single INSERT we have 11 operations here. Besides unnecessary pressure on IO system and possible locks, we have much more serious consistency issue - if HR department queries table after DELETE operation but before all the INSERTs have been completed, it would receive project status that never occurred in real life - 3 employees for example. But that's the way NHibernate works - &amp;quot;just in case&amp;quot; overwrites the entire projects object.&lt;/p&gt;  &lt;p&gt;Ah, and how did I find out? Noticed that after mapping new employee to project trigger on delete fires. WEB team developers (those actually programming with NHibernate) keep log of commands NHibernate executes in development environment. There I have seen it plain and simple.&lt;/p&gt;&lt;img src="http://sqlblog.com/aggbug.aspx?PostID=11934" width="1" height="1"&gt;</description><category domain="http://sqlblog.com/blogs/michael_zilberstein/archive/tags/Misc/default.aspx">Misc</category><category domain="http://sqlblog.com/blogs/michael_zilberstein/archive/tags/ORM/default.aspx">ORM</category></item><item><title>Restoring master database</title><link>http://sqlblog.com/blogs/michael_zilberstein/archive/2008/12/30/10816.aspx</link><pubDate>Tue, 30 Dec 2008 17:03:44 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:10816</guid><dc:creator>Michael Zilberstein</dc:creator><slash:comments>13</slash:comments><comments>http://sqlblog.com/blogs/michael_zilberstein/comments/10816.aspx</comments><wfw:commentRss>http://sqlblog.com/blogs/michael_zilberstein/commentrss.aspx?PostID=10816</wfw:commentRss><description>Disclaimer: I'm not an infrastructure DBA.Probably everything below is just bullshit. Recently our talented IT guys destroyed disk on a virtual machine. They chose the disk carefully - it was the one with master database. How do you restore master db...(&lt;a href="http://sqlblog.com/blogs/michael_zilberstein/archive/2008/12/30/10816.aspx"&gt;read more&lt;/a&gt;)&lt;img src="http://sqlblog.com/aggbug.aspx?PostID=10816" width="1" height="1"&gt;</description><category domain="http://sqlblog.com/blogs/michael_zilberstein/archive/tags/Misc/default.aspx">Misc</category><category domain="http://sqlblog.com/blogs/michael_zilberstein/archive/tags/Internals/default.aspx">Internals</category></item><item><title>Name resolution in SQL Server</title><link>http://sqlblog.com/blogs/michael_zilberstein/archive/2008/08/28/Name-resolution-in-SQL-Server.aspx</link><pubDate>Thu, 28 Aug 2008 10:57:00 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:8628</guid><dc:creator>Michael Zilberstein</dc:creator><slash:comments>0</slash:comments><comments>http://sqlblog.com/blogs/michael_zilberstein/comments/8628.aspx</comments><wfw:commentRss>http://sqlblog.com/blogs/michael_zilberstein/commentrss.aspx?PostID=8628</wfw:commentRss><description>This post is inspired by recent post by Mladen Prajdić. Mladen had found out (as many did before him - hanging around in blogs and communities, I see questions about this issue from time to time) that name resolution works for temporary tables differs...(&lt;a href="http://sqlblog.com/blogs/michael_zilberstein/archive/2008/08/28/Name-resolution-in-SQL-Server.aspx"&gt;read more&lt;/a&gt;)&lt;img src="http://sqlblog.com/aggbug.aspx?PostID=8628" width="1" height="1"&gt;</description><category domain="http://sqlblog.com/blogs/michael_zilberstein/archive/tags/Misc/default.aspx">Misc</category></item><item><title>Partitioning by GUID</title><link>http://sqlblog.com/blogs/michael_zilberstein/archive/2008/06/11/7237.aspx</link><pubDate>Wed, 11 Jun 2008 00:40:14 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:7237</guid><dc:creator>Michael Zilberstein</dc:creator><slash:comments>8</slash:comments><comments>http://sqlblog.com/blogs/michael_zilberstein/comments/7237.aspx</comments><wfw:commentRss>http://sqlblog.com/blogs/michael_zilberstein/commentrss.aspx?PostID=7237</wfw:commentRss><description>Recently I had to use GUID (Global Unique Identifier) as primary key in order to ensure cross-server uniqueness. In many cases surrogate key (some sort of concatenation between server id and intra-server identity) would give a better performance but in...(&lt;a href="http://sqlblog.com/blogs/michael_zilberstein/archive/2008/06/11/7237.aspx"&gt;read more&lt;/a&gt;)&lt;img src="http://sqlblog.com/aggbug.aspx?PostID=7237" width="1" height="1"&gt;</description><category domain="http://sqlblog.com/blogs/michael_zilberstein/archive/tags/Misc/default.aspx">Misc</category><category domain="http://sqlblog.com/blogs/michael_zilberstein/archive/tags/Scripts/default.aspx">Scripts</category></item><item><title>Scalability features I would like to have in SQL Server</title><link>http://sqlblog.com/blogs/michael_zilberstein/archive/2008/04/23/6361.aspx</link><pubDate>Wed, 23 Apr 2008 16:03:26 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:6361</guid><dc:creator>Michael Zilberstein</dc:creator><slash:comments>6</slash:comments><comments>http://sqlblog.com/blogs/michael_zilberstein/comments/6361.aspx</comments><wfw:commentRss>http://sqlblog.com/blogs/michael_zilberstein/commentrss.aspx?PostID=6361</wfw:commentRss><description>1. Active-Active cluster. Like RAC in Oracle. Maximum that commodity server can provide by now is 4 quad-core CPU machine. If application requires more, we can split the database (which is not always possible; and even when it is - such a solution often...(&lt;a href="http://sqlblog.com/blogs/michael_zilberstein/archive/2008/04/23/6361.aspx"&gt;read more&lt;/a&gt;)&lt;img src="http://sqlblog.com/aggbug.aspx?PostID=6361" width="1" height="1"&gt;</description><category domain="http://sqlblog.com/blogs/michael_zilberstein/archive/tags/Misc/default.aspx">Misc</category></item><item><title>Have your database ever been backed up?</title><link>http://sqlblog.com/blogs/michael_zilberstein/archive/2008/03/01/Have-your-database-ever-been-backed-up_3F00_.aspx</link><pubDate>Sat, 01 Mar 2008 14:15:00 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:5378</guid><dc:creator>Michael Zilberstein</dc:creator><slash:comments>5</slash:comments><comments>http://sqlblog.com/blogs/michael_zilberstein/comments/5378.aspx</comments><wfw:commentRss>http://sqlblog.com/blogs/michael_zilberstein/commentrss.aspx?PostID=5378</wfw:commentRss><description>
&lt;p&gt;Recently I've been asked by one of my clients to write a simple script that would find out whether particular database had ever been backed up (full backup). The reason for a requirement was semi-automatic application which would enable end users to manage backup activity including manually backup transaction log - not via Management Studio but via much more friendly UI designed for non-DBAs. As you know, for database running in Full Recovery Mode, transaction log can't be backed up before full backup is done at least for the first time.
OK, I thought. Let's just check whether full backup exists for the database:
&lt;font color="#0033cc"&gt;&lt;/font&gt;&lt;/p&gt;

&lt;p&gt;&lt;font color="#0033cc"&gt;IF&lt;/font&gt; &lt;font color="#808080"&gt;EXISTS&lt;/font&gt;( &lt;font color="#0033cc"&gt;SELECT&lt;/font&gt; 1 &lt;font color="#0033cc"&gt;FROM&lt;/font&gt; msdb..backupset &lt;font color="#0033cc"&gt;WHERE&lt;/font&gt; database_name = &lt;font color="#ff0000"&gt;'MyDB'&lt;/font&gt; &lt;font color="#808080"&gt;AND&lt;/font&gt; [type] = &lt;font color="#ff0000"&gt;'D'&lt;/font&gt; )
...&lt;br&gt;&lt;br&gt;&amp;nbsp;Here comes the first catch. Imagine following scenario:
&lt;/p&gt;

&lt;p&gt;1. Create database MyDB.
&lt;/p&gt;

&lt;p&gt;2. Create full backup of 'MyDB'.
&lt;/p&gt;

&lt;p&gt;3. Drop database 'MyDB' (without deleting backup history).&amp;nbsp;
&lt;/p&gt;

&lt;p&gt;4. Create new database with the name 'MyDB' or restore from backup.
&lt;/p&gt;

&lt;p&gt;What do we have now? Query will return true while actually backup we have belongs to another non-existing database. Try to backup transaction log of the new DB - you'll receive error.
&lt;/p&gt;

&lt;p&gt;First try failed - let's give another one. Both &lt;font color="green"&gt;sys.databases&lt;/font&gt; and msdb..backupset contain creation date of the database. In &lt;font color="green"&gt;sys.databases&lt;/font&gt; column name is create_date, in msdb..backupset it is database_creation_date. So let's just compare database_creation_date from the latest full backup row with database's create_date. If they're equal - we have full backup. Otherwise backup belongs to the previous incarnation of our database while full backup of currently existing db had never been taken. Sure, it should also work for the normal scenario - without deleted and restored databases on the way. So first let's check whether our theory works after second step of the scenario described above. But what happened? How comes, our database creation times are different?&amp;nbsp;&lt;/p&gt;

&lt;p&gt;
Here comes second catch. For some strange reason,&amp;nbsp;database_creation_date column in&amp;nbsp;msdb..backupset doesn't contain milliseconds! Minutes, seconds - everything is there but for milliseconds its always 000. While&amp;nbsp;create_date in&amp;nbsp;&lt;font color="green"&gt;sys.databases&lt;/font&gt; contains full date including milliseconds. Don't know who and for what reason cut milliseconds from the backup history table, but that's the way it works now.
&lt;/p&gt;

&lt;p&gt;To make long story short - it was the last barrier. After removing milliseconds part from database creation date in&amp;nbsp;&lt;font color="green"&gt;sys.databases&lt;/font&gt;, everything began to work. Here is the full script that will tell you whether some particular database had ever been backed up (full backup).&lt;/p&gt;

&lt;p&gt;
&lt;font color="blue"&gt;DECLARE&amp;nbsp;&lt;/font&gt;&lt;font color="#434343"&gt;@DBName&amp;nbsp;&lt;/font&gt;&lt;font color="blue"&gt;SYSNAME&lt;/font&gt;&lt;font color="blue"&gt;&lt;br&gt;SET&amp;nbsp;&lt;/font&gt;&lt;font color="#434343"&gt;@DBName&amp;nbsp;&lt;/font&gt;&lt;font color="blue"&gt;=&amp;nbsp;&lt;/font&gt;&lt;font color="#ff0000"&gt;'YourDatabase'&lt;/font&gt;
&lt;font color="blue"&gt;&lt;/font&gt;
&lt;/p&gt;

&lt;font color="blue"&gt;DECLARE&amp;nbsp;&lt;/font&gt;&lt;font color="#434343"&gt;@LatestBackupDate&amp;nbsp;&lt;/font&gt;&lt;font color="blue"&gt;DATETIME&lt;/font&gt;&lt;font color="gray"&gt;,&amp;nbsp;&lt;/font&gt;&lt;font color="#434343"&gt;@BackedUpDBCreationDate&amp;nbsp;&lt;/font&gt;&lt;font color="blue"&gt;DATETIME&lt;br&gt;&lt;/font&gt;&lt;font color="blue"&gt;DECLARE&amp;nbsp;&lt;/font&gt;&lt;font color="#434343"&gt;@DBCreationDateNoMilliseconds&amp;nbsp;&lt;/font&gt;&lt;font color="blue"&gt;DATETIME&lt;br&gt;&lt;br&gt;&lt;/font&gt;&lt;font color="green"&gt;--&amp;nbsp;In&amp;nbsp;msdb..backupset&amp;nbsp;table,&amp;nbsp;database_creation_date&amp;nbsp;column&amp;nbsp;is&amp;nbsp;in&amp;nbsp;datatime&amp;nbsp;format&lt;br&gt;--&amp;nbsp;but&amp;nbsp;without&amp;nbsp;milliseconds,&amp;nbsp;so&amp;nbsp;we&amp;nbsp;remove&amp;nbsp;milliseconds&amp;nbsp;from&amp;nbsp;database&amp;nbsp;creation&amp;nbsp;date.&lt;br&gt;&lt;/font&gt;&lt;font color="blue"&gt;SELECT&amp;nbsp;&lt;/font&gt;&lt;font color="#434343"&gt;@DBCreationDateNoMilliseconds&amp;nbsp;&lt;/font&gt;&lt;font color="blue"&gt;= &lt;/font&gt;&lt;font color="blue"&gt;&lt;font color="black"&gt;	&lt;/font&gt;&lt;/font&gt;&lt;font color="blue"&gt;&lt;br&gt;&lt;font color="magenta"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; DATEADD&lt;/font&gt;&lt;font color="gray"&gt;(&lt;/font&gt;&lt;font color="blue"&gt;millisecond&lt;/font&gt;&lt;font color="gray"&gt;,&amp;nbsp;-&lt;/font&gt;&lt;font color="magenta"&gt;DATEPART&lt;/font&gt;&lt;font color="gray"&gt;(&lt;/font&gt;&lt;font color="blue"&gt;millisecond&lt;/font&gt;&lt;font color="gray"&gt;,&amp;nbsp;&lt;/font&gt;&lt;font color="black"&gt;create_date&lt;/font&gt;&lt;font color="gray"&gt;),&amp;nbsp;&lt;/font&gt;&lt;font color="black"&gt;create_date&lt;/font&gt;&lt;font color="gray"&gt;)&lt;/font&gt;&lt;/font&gt;&lt;br&gt;&lt;font color="blue"&gt;FROM&amp;nbsp;&lt;/font&gt;&lt;font color="green"&gt;sys.databases&lt;/font&gt;&lt;font color="#434343"&gt;&lt;br&gt;&lt;/font&gt;&lt;font color="blue"&gt;WHERE&amp;nbsp;&lt;/font&gt;&lt;font color="black"&gt;[name]&amp;nbsp;&lt;/font&gt;&lt;font color="blue"&gt;=&amp;nbsp;&lt;/font&gt;&lt;font color="#434343"&gt;@DBName&lt;/font&gt; &lt;br&gt;
&lt;font color="#434343"&gt;&lt;/font&gt;&lt;font color="blue"&gt;IF&amp;nbsp;&lt;/font&gt;&lt;font color="#434343"&gt;@DBCreationDateNoMilliseconds&amp;nbsp;&lt;/font&gt;&lt;font color="blue"&gt;IS&amp;nbsp;&lt;/font&gt;&lt;font color="gray"&gt;NULL&lt;br&gt;&amp;nbsp;&amp;nbsp; &lt;/font&gt;&lt;font color="blue"&gt;BEGIN&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; PRINT&amp;nbsp;&lt;/font&gt;&lt;font color="red"&gt;'Database&amp;nbsp;'&amp;nbsp;&lt;/font&gt;&lt;font color="gray"&gt;+&amp;nbsp;&lt;/font&gt;&lt;font color="#434343"&gt;@DBName&amp;nbsp;&lt;/font&gt;&lt;font color="gray"&gt;+&amp;nbsp;&lt;/font&gt;&lt;font color="red"&gt;'&amp;nbsp;doesn'&amp;nbsp;&lt;/font&gt;&lt;font color="gray"&gt;+&amp;nbsp;&lt;/font&gt;&lt;font color="blue"&gt;CHAR&lt;/font&gt;&lt;font color="gray"&gt;(&lt;/font&gt;&lt;font color="black"&gt;39&lt;/font&gt;&lt;font color="gray"&gt;)&amp;nbsp;+&amp;nbsp;&lt;/font&gt;&lt;font color="red"&gt;'t&amp;nbsp;exist&amp;nbsp;on&amp;nbsp;the&amp;nbsp;server'&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/font&gt;&lt;font color="blue"&gt;RETURN&lt;br&gt;&amp;nbsp;&amp;nbsp; END&lt;br&gt;&lt;br&gt;SELECT&lt;br&gt;&amp;nbsp;&amp;nbsp; &lt;/font&gt;&lt;font color="#434343"&gt;@LatestBackupDate&amp;nbsp;&lt;/font&gt;&lt;font color="blue"&gt;=&amp;nbsp;&lt;/font&gt;&lt;font color="black"&gt;backup_finish_date&lt;/font&gt;&lt;font color="gray"&gt;,&lt;br&gt;&amp;nbsp;&amp;nbsp; &lt;/font&gt;&lt;font color="#434343"&gt;@BackedUpDBCreationDate&amp;nbsp;&lt;/font&gt;&lt;font color="blue"&gt;=&amp;nbsp;&lt;/font&gt;&lt;font color="black"&gt;database_creation_date&lt;br&gt;&lt;/font&gt;&lt;font color="blue"&gt;FROM&amp;nbsp;&lt;/font&gt;&lt;font color="black"&gt;msdb..backupset&lt;br&gt;&lt;/font&gt;&lt;font color="blue"&gt;WHERE&amp;nbsp;&lt;br&gt;&amp;nbsp;&amp;nbsp; &lt;/font&gt;&lt;font color="black"&gt;backup_set_id&amp;nbsp;&lt;/font&gt;&lt;font color="blue"&gt;=&amp;nbsp;&lt;/font&gt;&lt;font color="gray"&gt;(&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/font&gt;&lt;font color="blue"&gt;SELECT&lt;/font&gt;&amp;nbsp;&lt;font color="magenta"&gt;MAX&lt;/font&gt;&lt;font color="gray"&gt;(&lt;/font&gt;&lt;font color="black"&gt;backup_set_id&lt;/font&gt;&lt;font color="gray"&gt;)&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/font&gt;&lt;font color="blue"&gt;FROM&amp;nbsp;&lt;/font&gt;&lt;font color="black"&gt;msdb..backupset&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/font&gt;&lt;font color="blue"&gt;WHERE&amp;nbsp;&lt;/font&gt;&lt;font color="black"&gt;database_name&amp;nbsp;&lt;/font&gt;&lt;font color="blue"&gt;=&amp;nbsp;&lt;/font&gt;&lt;font color="#434343"&gt;@DBName&amp;nbsp;&lt;/font&gt;&lt;font color="gray"&gt;AND&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/font&gt;&lt;font color="black"&gt;[type]&amp;nbsp;&lt;/font&gt;&lt;font color="blue"&gt;=&amp;nbsp;&lt;/font&gt;&lt;font color="red"&gt;'D'&amp;nbsp;&lt;/font&gt;&lt;font color="gray"&gt;)&lt;br&gt;&lt;br&gt;&lt;/font&gt;&lt;font color="blue"&gt;IF&amp;nbsp;&lt;/font&gt;&lt;font color="#434343"&gt;@LatestBackupDate&amp;nbsp;&lt;/font&gt;&lt;font color="blue"&gt;IS&amp;nbsp;&lt;/font&gt;&lt;font color="gray"&gt;NULL&lt;br&gt;&amp;nbsp;&amp;nbsp; &lt;/font&gt;&lt;font color="blue"&gt;BEGIN&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; PRINT&amp;nbsp;&lt;/font&gt;&lt;font color="red"&gt;'Full&amp;nbsp;backup&amp;nbsp;had&amp;nbsp;never&amp;nbsp;been&amp;nbsp;taken&amp;nbsp;for&amp;nbsp;database&amp;nbsp;'&amp;nbsp;&lt;/font&gt;&lt;font color="gray"&gt;+&amp;nbsp;&lt;/font&gt;&lt;font color="#434343"&gt;@DBName&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/font&gt;&lt;font color="blue"&gt;RETURN&lt;br&gt;&amp;nbsp;&amp;nbsp; END&lt;br&gt;&lt;br&gt;IF&amp;nbsp;&lt;/font&gt;&lt;font color="#434343"&gt;@BackedUpDBCreationDate&amp;nbsp;&lt;/font&gt;&lt;font color="blue"&gt;=&amp;nbsp;&lt;/font&gt;&lt;font color="#434343"&gt;@DBCreationDateNoMilliseconds&lt;br&gt;&amp;nbsp;&amp;nbsp; &lt;/font&gt;&lt;font color="blue"&gt;PRINT&amp;nbsp;&lt;/font&gt;&lt;font color="red"&gt;'Full&amp;nbsp;backup&amp;nbsp;exists&amp;nbsp;for&amp;nbsp;database&amp;nbsp;'&amp;nbsp;&lt;/font&gt;&lt;font color="gray"&gt;+&amp;nbsp;&lt;/font&gt;&lt;font color="#434343"&gt;@DBName&amp;nbsp;&lt;/font&gt;&lt;font color="gray"&gt;+&amp;nbsp;&lt;/font&gt;&lt;font color="red"&gt;'; &lt;/font&gt;&lt;font color="red"&gt;Transaction&amp;nbsp;log&amp;nbsp;backups&amp;nbsp;can&amp;nbsp;be&amp;nbsp;taken'&lt;br&gt;&lt;/font&gt;&lt;font color="blue"&gt;ELSE&lt;br&gt;&amp;nbsp;&amp;nbsp; PRINT&amp;nbsp;&lt;/font&gt;&lt;font color="red"&gt;'Full&amp;nbsp;backup&amp;nbsp;exists&amp;nbsp;for&amp;nbsp;the&amp;nbsp;current&amp;nbsp;version&amp;nbsp;of&amp;nbsp;'&amp;nbsp;&lt;/font&gt;&lt;font color="gray"&gt;+&amp;nbsp;&lt;/font&gt;&lt;font color="#434343"&gt;@DBName&amp;nbsp;&lt;/font&gt;&lt;font color="gray"&gt;+&amp;nbsp;&lt;/font&gt;&lt;font color="red"&gt;'&amp;nbsp;database&amp;nbsp; &lt;/font&gt;&lt;font color="red"&gt;had&amp;nbsp;never&amp;nbsp;been&amp;nbsp;taken. Existing&amp;nbsp;backup&amp;nbsp;refers&amp;nbsp;to&amp;nbsp;non-existing&amp;nbsp;database &lt;/font&gt;&lt;font color="red"&gt;with&amp;nbsp;the&amp;nbsp;same&amp;nbsp;name'&lt;br&gt;&lt;br&gt;&lt;br&gt;&lt;br&gt;&lt;/font&gt;&lt;img src="http://sqlblog.com/aggbug.aspx?PostID=5378" width="1" height="1"&gt;</description><category domain="http://sqlblog.com/blogs/michael_zilberstein/archive/tags/Misc/default.aspx">Misc</category><category domain="http://sqlblog.com/blogs/michael_zilberstein/archive/tags/Scripts/default.aspx">Scripts</category></item><item><title>1001st way to find SQL Server service start time</title><link>http://sqlblog.com/blogs/michael_zilberstein/archive/2008/03/01/1001st-way-to-find-sql-server-service-start-time.aspx</link><pubDate>Sat, 01 Mar 2008 13:43:00 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:5377</guid><dc:creator>Michael Zilberstein</dc:creator><slash:comments>0</slash:comments><comments>http://sqlblog.com/blogs/michael_zilberstein/comments/5377.aspx</comments><wfw:commentRss>http://sqlblog.com/blogs/michael_zilberstein/commentrss.aspx?PostID=5377</wfw:commentRss><description>There're a lot of ways to discover when SQL Server service had been last restarted. That's not a pure curiosity issue since almost all the DMVs and performance counters reset at service restart. So in order to calculate averages (IOs per minute, Waits per minute) etc, one needs to know the starting point. There're a lot of ways to find it. One is to take a look in Error Log (if log hadn't been deleted by numerious DBCC ERRORLOG commands). Another way is to look at &lt;span&gt;sys.dm_exec_requests&lt;/span&gt; for start_time or in master..sysprocesses for login_time of system processes like LAZY WRITER. Recently I've found one more way: look in &lt;span&gt;sys.databases&lt;/span&gt; for create_date of tempdb database. Since tempdb is re-created from scratch every time SQL Server restarts, it works. BOL reference about create_date column also says:&lt;br&gt;&lt;span style="font-style:italic;"&gt;-- Date the database was created or renamed. For &lt;span style="font-weight:bold;"&gt;tempdb&lt;/span&gt;, this value changes every time the server restarts.&lt;/span&gt;&lt;br&gt;&lt;br&gt;P.S. Results you receive trying different ways can vary - half minute here or there - because service restart doesn't happen in a second. But when you need to measure time since startup, 30 seconds usually won't be serious factor.&lt;img src="http://sqlblog.com/aggbug.aspx?PostID=5377" width="1" height="1"&gt;</description><category domain="http://sqlblog.com/blogs/michael_zilberstein/archive/tags/Misc/default.aspx">Misc</category></item></channel></rss>