<?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</title><link>http://sqlblog.com/blogs/michael_zilberstein/default.aspx</link><description /><dc:language>en</dc:language><generator>CommunityServer 2.1 SP2 (Build: 61129.1)</generator><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>0</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>How do we know that Microsoft conducts performance tests?</title><link>http://sqlblog.com/blogs/michael_zilberstein/archive/2008/03/24/5757.aspx</link><pubDate>Mon, 24 Mar 2008 07:31:00 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:5757</guid><dc:creator>Michael Zilberstein</dc:creator><slash:comments>0</slash:comments><comments>http://sqlblog.com/blogs/michael_zilberstein/comments/5757.aspx</comments><wfw:commentRss>http://sqlblog.com/blogs/michael_zilberstein/commentrss.aspx?PostID=5757</wfw:commentRss><description>Funny comment in undocumented system stored procedure - and undocumented syntax of DBCC SHOW_STATISTICS. ...(&lt;a href="http://sqlblog.com/blogs/michael_zilberstein/archive/2008/03/24/5757.aspx"&gt;read more&lt;/a&gt;)&lt;img src="http://sqlblog.com/aggbug.aspx?PostID=5757" width="1" height="1"&gt;</description></item><item><title>How to find real database creation date</title><link>http://sqlblog.com/blogs/michael_zilberstein/archive/2008/03/18/5629.aspx</link><pubDate>Tue, 18 Mar 2008 05:56:30 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:5629</guid><dc:creator>Michael Zilberstein</dc:creator><slash:comments>4</slash:comments><comments>http://sqlblog.com/blogs/michael_zilberstein/comments/5629.aspx</comments><wfw:commentRss>http://sqlblog.com/blogs/michael_zilberstein/commentrss.aspx?PostID=5629</wfw:commentRss><description>Restoring database from backup or moving it to another server resets all the creation_date fields (in sys.databases , msdb..backupset etc'). So is there any way to find out the original creation date? Looks like there is one. It is stored in the boot...(&lt;a href="http://sqlblog.com/blogs/michael_zilberstein/archive/2008/03/18/5629.aspx"&gt;read more&lt;/a&gt;)&lt;img src="http://sqlblog.com/aggbug.aspx?PostID=5629" width="1" height="1"&gt;</description><category domain="http://sqlblog.com/blogs/michael_zilberstein/archive/tags/Internals/default.aspx">Internals</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>6</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;BR&gt;&lt;div class = "shareblock"&gt;&lt;span class = "shareblockTitle"&gt;Share this post:&lt;/span&gt;&lt;span class = "shareblockLink"&gt; &lt;a href = "mailto:?subject=Have your database ever been backed up?&amp;amp;body=Seen on SQLblog.com: %0A%0A%09Have your database ever been backed up?%0A%0Ahttp://sqlblog.com/blogs/michael_zilberstein/archive/2008/03/01/Have-your-database-ever-been-backed-up_3F00_.aspx" target="_blank" title = "Email Have your database ever been backed up?"&gt;email it!&lt;/a&gt; |  &lt;a href = "http://del.icio.us/post?url=http://sqlblog.com/blogs/michael_zilberstein/archive/2008/03/01/Have-your-database-ever-been-backed-up_3F00_.aspx&amp;amp;title=Have+your+database+ever+been+backed+up%3f" target="_blank" title = "Submit Have your database ever been backed up? to del.icio.us"&gt;bookmark it!&lt;/a&gt; |  &lt;a href = "http://www.digg.com/submit?url=http://sqlblog.com/blogs/michael_zilberstein/archive/2008/03/01/Have-your-database-ever-been-backed-up_3F00_.aspx&amp;amp;phase=2" target="_blank" title = "Submit Have your database ever been backed up? to digg.com"&gt;digg it!&lt;/a&gt; |  &lt;a href = "http://reddit.com/submit?url=http://sqlblog.com/blogs/michael_zilberstein/archive/2008/03/01/Have-your-database-ever-been-backed-up_3F00_.aspx&amp;amp;title=Have+your+database+ever+been+backed+up%3f" target="_blank" title = "Submit Have your database ever been backed up? to reddit.com"&gt;reddit!&lt;/a&gt; |  &lt;a href = "http://www.dotnetkicks.com/submit/?url=http://sqlblog.com/blogs/michael_zilberstein/archive/2008/03/01/Have-your-database-ever-been-backed-up_3F00_.aspx&amp;amp;title=Have+your+database+ever+been+backed+up%3f" target="_blank" title = "Submit Have your database ever been backed up? to DotNetKicks"&gt;kick it!&lt;/a&gt; |  &lt;a href = "https://favorites.live.com/quickadd.aspx?marklet=1&amp;amp;mkt=en-us&amp;amp;url=http://sqlblog.com/blogs/michael_zilberstein/archive/2008/03/01/Have-your-database-ever-been-backed-up_3F00_.aspx&amp;amp;title=Have+your+database+ever+been+backed+up%3f&amp;amp;;top=1" target="_blank" title = "Add Have your database ever been backed up? to Live Bookmarks"&gt;live it!&lt;/a&gt;&lt;/span&gt;&lt;/div&gt;&lt;img src="http://info.sqlblog.com/a.aspx?ZoneID=0&amp;BannerID=12&amp;AdvertiserID=1&amp;CampaignID=12&amp;Task=Get&amp;Mode=TEXT&amp;SiteID=1&amp;RandomNumber=463323" width="1" height="1" border="0"&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;BR&gt;&lt;div class = "shareblock"&gt;&lt;span class = "shareblockTitle"&gt;Share this post:&lt;/span&gt;&lt;span class = "shareblockLink"&gt; &lt;a href = "mailto:?subject=1001st way to find SQL Server service start time&amp;amp;body=Seen on SQLblog.com: %0A%0A%091001st way to find SQL Server service start time%0A%0Ahttp://sqlblog.com/blogs/michael_zilberstein/archive/2008/03/01/1001st-way-to-find-sql-server-service-start-time.aspx" target="_blank" title = "Email 1001st way to find SQL Server service start time"&gt;email it!&lt;/a&gt; |  &lt;a href = "http://del.icio.us/post?url=http://sqlblog.com/blogs/michael_zilberstein/archive/2008/03/01/1001st-way-to-find-sql-server-service-start-time.aspx&amp;amp;title=1001st+way+to+find+SQL+Server+service+start+time" target="_blank" title = "Submit 1001st way to find SQL Server service start time to del.icio.us"&gt;bookmark it!&lt;/a&gt; |  &lt;a href = "http://www.digg.com/submit?url=http://sqlblog.com/blogs/michael_zilberstein/archive/2008/03/01/1001st-way-to-find-sql-server-service-start-time.aspx&amp;amp;phase=2" target="_blank" title = "Submit 1001st way to find SQL Server service start time to digg.com"&gt;digg it!&lt;/a&gt; |  &lt;a href = "http://reddit.com/submit?url=http://sqlblog.com/blogs/michael_zilberstein/archive/2008/03/01/1001st-way-to-find-sql-server-service-start-time.aspx&amp;amp;title=1001st+way+to+find+SQL+Server+service+start+time" target="_blank" title = "Submit 1001st way to find SQL Server service start time to reddit.com"&gt;reddit!&lt;/a&gt; |  &lt;a href = "http://www.dotnetkicks.com/submit/?url=http://sqlblog.com/blogs/michael_zilberstein/archive/2008/03/01/1001st-way-to-find-sql-server-service-start-time.aspx&amp;amp;title=1001st+way+to+find+SQL+Server+service+start+time" target="_blank" title = "Submit 1001st way to find SQL Server service start time to DotNetKicks"&gt;kick it!&lt;/a&gt; |  &lt;a href = "https://favorites.live.com/quickadd.aspx?marklet=1&amp;amp;mkt=en-us&amp;amp;url=http://sqlblog.com/blogs/michael_zilberstein/archive/2008/03/01/1001st-way-to-find-sql-server-service-start-time.aspx&amp;amp;title=1001st+way+to+find+SQL+Server+service+start+time&amp;amp;;top=1" target="_blank" title = "Add 1001st way to find SQL Server service start time to Live Bookmarks"&gt;live it!&lt;/a&gt;&lt;/span&gt;&lt;/div&gt;&lt;img src="http://info.sqlblog.com/a.aspx?ZoneID=0&amp;BannerID=12&amp;AdvertiserID=1&amp;CampaignID=12&amp;Task=Get&amp;Mode=TEXT&amp;SiteID=1&amp;RandomNumber=463323" width="1" height="1" border="0"&gt;&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>