<?xml version="1.0" encoding="UTF-8"?>
<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/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>dbsnaps &#187; Administration</title>
	<atom:link href="http://www.dbsnaps.com/category/sql-server/administration-sql-server/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.dbsnaps.com</link>
	<description>database video tutorials</description>
	<lastBuildDate>Sun, 13 Nov 2011 13:50:36 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.1</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Rolling back TRUNCATE statements in SQL Server</title>
		<link>http://www.dbsnaps.com/sql-server/tips-tricks-sql-server/rolling-back-truncate-statements-in-sql-server/</link>
		<comments>http://www.dbsnaps.com/sql-server/tips-tricks-sql-server/rolling-back-truncate-statements-in-sql-server/#comments</comments>
		<pubDate>Wed, 28 Jul 2010 09:49:58 +0000</pubDate>
		<dc:creator>Roni Vered</dc:creator>
				<category><![CDATA[Administration]]></category>
		<category><![CDATA[Main-Administration]]></category>
		<category><![CDATA[SQL Server - Latest Articles]]></category>
		<category><![CDATA[Tips & Tricks]]></category>
		<category><![CDATA[BEGIN TRAN]]></category>
		<category><![CDATA[DELETE]]></category>
		<category><![CDATA[Rollback]]></category>
		<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[TRUNCATE]]></category>

		<guid isPermaLink="false">http://www.dbsnaps.com/?p=374</guid>
		<description><![CDATA[There are two main ways to delete all records from a table - DELETE and TRUNCATE commands, but if we do, can we rollback the operation?]]></description>
			<content:encoded><![CDATA[<p>There are two main statements used for deleting data from a table in SQL SERVER:</p>
<ul>
<li>TRUNCATE</li>
<li>DELETE</li>
</ul>
<p>The two commands achieve the same result; however, each of the commands acts a little bit different. Each of the two commands have advantages, limitations, and consequences, which have to be considered when deciding which method to use.</p>
<p>In this post we will concentrate in <em>one</em> aspect of these commands usage – <em>the ability to rollback each operation</em>.</p>
<p>DELETE statements delete rows one at a time, logging each row in the transaction log and maintaining the log sequence number (LSN) information.<br />
Even though it will consumes more database resources, it comes in handy as these transactions can be <strong>rolled back</strong> if necessary by using the log files, when the recovery model of the database is set to full.</p>
<p>But what happens when you issue the <em>TRUNCATE </em>command?</p>
<p>The TRUNCATE statement is much faster statement than the DELETE command.<br />
It deletes all records in a table by deallocating the data pages used to store the table&#8217;s data. This operation has a limited logging in the transaction log (only the page deallocations are recorded in the transaction log). In addition fewer locks are acquired with this statement in compare to the DELETE statement.<br />
As a result of the above it is commonly believed that records removed by the TRUNCATE statement cannot be restored – rolled back.</p>
<p>It is true in most cases, however <strong>DELETE and TRUNCATE can both be rolled back</strong> when they are executed inside a ‘BEGIN <em>TRANSACTION’</em> block and the current session has not yet ended.<br />
In other words, when the TRUNCATE statement has not been committed yet, it can be rolled back</p>
<p>The following code demonstrates a scenario when a TRUNCATE can be rolled back for that particular session.</p>
<pre class="brush: sql;">
--Creating a testTable for the demonstration
CREATE TABLE TESTTABLE (ID INT)

--Inserting rows into the testTable.
INSERT INTO TESTTABLE
SELECT TOP 1000 OBJECT_ID FROM SYS.OBJECTS
BEGIN TRAN
   --Truncating the table
   TRUNCATE TABLE TESTTABLE
   --No rows will return
   SELECT * FROM TESTTABLE
ROLLBACK

--The original rows from testTable will return
SELECT * FROM TESTTABLE

--Dropping the testTable.
DROP TABLE TESTTABLE
</pre>
<p><strong>To summarize,<br />
</strong>DELETE can always be rolled back-</p>
<ul>
<li><span style="font-size: 13.3333px">When the recovery model of the database is set to SIMPLE, the statement can be rolled back &#8211; when the statement is executed inside a ‘BEGIN TRANSACTION’ block.</span></li>
<li><span style="font-size: 13.3333px">When the recovery model of the database is set to FULL, the statement can also be recovered from the log files.</span></li>
</ul>
<p><span style="font-size: 13.3333px">TRUNCATE can or cannot be rolled back, depends if it is executed from within a ‘BEGIN TRANSACTION’ block.</span></p>
]]></content:encoded>
			<wfw:commentRss>http://www.dbsnaps.com/sql-server/tips-tricks-sql-server/rolling-back-truncate-statements-in-sql-server/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>SQL Server &#8211; How to determine instance uptime</title>
		<link>http://www.dbsnaps.com/sql-server/334/</link>
		<comments>http://www.dbsnaps.com/sql-server/334/#comments</comments>
		<pubDate>Fri, 09 Jul 2010 09:29:40 +0000</pubDate>
		<dc:creator>Alon Spiegel</dc:creator>
				<category><![CDATA[Administration]]></category>
		<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[SQL Server - Latest Articles]]></category>
		<category><![CDATA[Tips & Tricks]]></category>
		<category><![CDATA[crdate]]></category>
		<category><![CDATA[Instance Uptime]]></category>
		<category><![CDATA[sysdatabase]]></category>
		<category><![CDATA[tempdb]]></category>

		<guid isPermaLink="false">http://www.dbsnaps.com/?p=334</guid>
		<description><![CDATA[In this article we will demonstrate how to retrieve the startup time of SQL Server]]></description>
			<content:encoded><![CDATA[<p>Unfortunately, SQL Server does not provide an easy and simple query that answers this question. What we could do is use the fact that tempdb database is being created every time we start SQL Server and query the create time of this reincarnating temporary database. The table/columns we are interested is sysdatabase.crdate  The following statement demonstrates it. Just copy it and run it in SSMS.</p>
<p>(I have written it for SQL 2005 but I guess it runs both on 2000 and 2008 versions)</p>
<pre class="brush: sql;">

declare @startupDate datetime
,		@days bigint
,		@hours bigint
,		@minutes bigint
,		@seconds bigint

select	@startupDate = CrDate
,		@seconds = DateDiff(second, CrDate, getdate())
,		@days = @seconds/60/60/24
,		@seconds = @seconds - (@days*60*60*24)
,		@hours = @seconds/60/60
,		@seconds = @seconds - (@hours*60*60)
,		@minutes = @seconds/60
,		@seconds = @seconds - (@minutes*60)

from	sysdatabases (nolock)
where	[name] = 'TempDb'

select	@startupDate startup_time
,		cast(@days as varchar) + ' days ' +
		case when @hours &lt; 10 then '0' else '' end + cast(@hours as varchar) + ':' +
		case when @minutes &lt; 10 then '0' else '' end + cast(@minutes as varchar) + ':' +
		case when @seconds &lt; 10 then '0' else '' end + cast(@seconds as varchar)
		as online_duration
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.dbsnaps.com/sql-server/334/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>SQL Server 2005 Backup &amp; Restore tutorial</title>
		<link>http://www.dbsnaps.com/videos/sql-server-2005-backup-restore/</link>
		<comments>http://www.dbsnaps.com/videos/sql-server-2005-backup-restore/#comments</comments>
		<pubDate>Sat, 06 Feb 2010 19:04:16 +0000</pubDate>
		<dc:creator>Oded Raz</dc:creator>
				<category><![CDATA[Administration]]></category>
		<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[Videos]]></category>
		<category><![CDATA[Backup & Restore]]></category>
		<category><![CDATA[SQL Server 2005]]></category>
		<category><![CDATA[Tutorial]]></category>
		<category><![CDATA[Video]]></category>

		<guid isPermaLink="false">http://dbsnaps.oracletutorialvideos.com/?p=96</guid>
		<description><![CDATA[Microsoft SQL Server enables you to back up and restore your databases. The SQL Server backup and restore component provides an important safeguard for protecting critical data stored in SQL Server databases.]]></description>
			<content:encoded><![CDATA[<p>Microsoft SQL Server enables you to back up and restore your databases.  The SQL Server backup and restore component provides an important  safeguard for protecting critical data stored in SQL Server databases. A  well-planned backup and restore strategy helps protect databases  against data loss caused by a variety of failures. Test your strategy by  restoring a set of backups and then recovering your database to prepare  you to respond effectively to a disaster.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.dbsnaps.com/videos/sql-server-2005-backup-restore/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

