Saturday, August 28, 2010

Rolling back TRUNCATE statements in SQL Server


There are two main statements used for deleting data from a table in SQL SERVER:

  • TRUNCATE
  • DELETE

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.

In this post we will concentrate in one aspect of these commands usage – the ability to rollback each operation.

DELETE statements delete rows one at a time, logging each row in the transaction log and maintaining the log sequence number (LSN) information.
Even though it will consumes more database resources, it comes in handy as these transactions can be rolled back if necessary by using the log files, when the recovery model of the database is set to full.

But what happens when you issue the TRUNCATE command?

The TRUNCATE statement is much faster statement than the DELETE command.
It deletes all records in a table by deallocating the data pages used to store the table'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.
As a result of the above it is commonly believed that records removed by the TRUNCATE statement cannot be restored – rolled back.

It is true in most cases, however DELETE and TRUNCATE can both be rolled back when they are executed inside a 'BEGIN TRANSACTION' block and the current session has not yet ended.
In other words, when the TRUNCATE statement has not been committed yet, it can be rolled back

The following code demonstrates a scenario when a TRUNCATE can be rolled back for that particular session.

view source print?
01--Creating a testTable for the demonstration
02CREATE TABLE TESTTABLE (ID INT)
03 
04 --Inserting rows into the testTable.
05 INSERT INTO TESTTABLE
06 SELECT TOP 1000 OBJECT_ID FROM SYS.OBJECTS
07BEGIN TRAN
08   --Truncating the table
09   TRUNCATE TABLE TESTTABLE
10   --No rows will return
11   SELECT * FROM TESTTABLE
12ROLLBACK
13 
14--The original rows from testTable will return
15SELECT * FROM TESTTABLE
16 
17 --Dropping the testTable.
18DROP TABLE TESTTABLE

To summarize,
DELETE can always be rolled back-

  • When the recovery model of the database is set to SIMPLE, the statement can be rolled back – when the statement is executed inside a 'BEGIN TRANSACTION' block.
  • When the recovery model of the database is set to FULL, the statement can also be recovered from the log files.

TRUNCATE can or cannot be rolled back, depends if it is executed from within a 'BEGIN TRANSACTION' block.



Friday, August 20, 2010

Five tips for becoming a successful IT manager


Before I made the decision to become a freelance writer, I served as a CIO for one organization and as an IT manager for several other organizations. During that time, I learned quite a bit about what it takes to be a successful manager. Some of the criteria are obvious, such as completing projects on time and on budget. More often than not, though, being a good manager has more to do with how you interact with your staff than with how smoothly various projects go. In this article, I want to share with you some of the things I learned about being a good IT manager.

1: Listen to your staff

By far the best advice I can possibly give you is to listen to your staff and to take their recommendations seriously. You don't necessarily have to follow every recommendation, but at least hear your employees out. They are the ones who do most of the day-to-day work, so they may have insight into aspects of the organization's operations that you might not pick up on yourself.

Not only can your staff give you valuable guidance, but taking the time to listen to them helps build morale. Listening to your employees shows that you respect them and that you value their input.

2: Be accommodating

Another thing I realized during my tenure as an IT manager is that it's important to be accommodating to your staff whenever possible. In every organization I have ever worked for, IT jobs have involved a lot of stress and some really long hours. Because everyone worked such long hours, I had to accept the fact that sometimes my employees would need to leave for a little while during the workday. For example, someone might need to go to the bank before it closed or pick up their kids. As an IT manager, I always tried to accommodate these types of requests so long as they didn't interfere with IT operations.

3: Maintain your technical knowledge

Often, IT managers (and especially CIOs) spend more time in meetings than they do configuring servers or troubleshooting problems. As a result, it's easy to let your technical skills become outdated. But there are at least three good reasons why you should maintain your technical skills, even if you don't use them on a regular basis.

First, you don't want your staff to think of you as an idiot manager who knows nothing. If you don't have a minimal level of IT knowledge, your staff may not respect you. Second, you never know when you may have to fire an employee or when someone will quit or end up in the hospital or something like that. You need to have enough knowledge to pitch in and help complete whatever projects the employee was working on. Even if you don't have sufficient time or technical knowledge to complete the project yourself, you should know enough about it to help those who are going to be working on it, if necessary. Third, vendors will constantly try to sell you things. Unless you have a good bit of technical knowledge, you could easily get taken for a ride by a fast-talking vendor who is pitching an inferior product.

4: Know when to get outside help

No IT employee knows everything. Everyone has his or her strengths and weakness. Sometimes, a project may come along that falls outside of your employees' skill sets. As an IT manager, you must not be afraid to acknowledge that some projects simply can't be handled in house and to outsource such projects when appropriate.

5: Take measures to relax and avoid burn out

IT can be stressful. Being a manager can be stressful. So it's critical for IT managers to regularly take time to do something to relax and de-stress. Otherwise, you will become apathetic toward your job as you get burned out, and you will become irritable toward your staff.


Wednesday, August 11, 2010

Is Google in Trouble ?


Google has changed how we search the web and the company has been constantly innovating search. Apart from search it has come up with (or acquired) very successful products like – Gmail, Chrome Browser, Android, Google Docs, Orkut and many more.

Google's hiring practices consist of bringing in top computer scientists from best schools like Stanford. The culture has been thriving and delivering great products so far.

The only area Google is lacking is 'Social Networks' (and everybody is talking about it right now on the web). Google's attempts to get into mainstream 'social' have been largely unsuccessful with – Orkut, DodgeBall, Buzz, Wave etc. They are a company which keeps innovating and there is already 'Google Me' in the queue which supposedly could be the Facebook killer!

Why Google needs to worry about Facebook?

Facebook is really a cool social network but there are 100s of social networks around the globe. Why Facebook is the one that is so concerning google?

  • Google runs on page-rank. A presumption that internet is a web of HTML links. Their search is built around this. The game is changing. Now, Internet is becoming more of a stream of updates from your friends than a web of pages. Now, It is a web of people!
  • Google is great at technology, no doubts but what matters more is people. Facebook is closer to people than what Google is!
  • There are alternative search engines and they work pretty well, if not great. So, there is no reason why people won't be able to switch their search provider – All they are looking for is information.
  • Facebook is hard to switch as all the friends are there, great apps, likes and interests and much more things that defines identity of a person.
  • Facebook is a 'Social Platform' company and they have no shortcomings that can't be met by partnering with platform developer like Zynga. Google doesn't have this unique capability.
  • The fact that google is doubling salary and letting them lead the teams for the engineers leaving to Facebook is alarming. This makes it evident that Facebook is the future of Internet in Google's view and fear of it results into irrational decisions.
  • Google doesn't have a social context and approach. They are focused on search and the web is changing and so is the search.
  • Partnership of Microsoft Bing with Facebook hurts Google in a big way. They couldn't foresee this opportunity in the past. Now, Bing is grabbing search arising from Facebook and helping Bing grow their traffic. Google has no access to 500+ million users of Facebook as Bing sits right there!
  • The biggest reason why Google needs to worry is time spent by users on Facebook is 3 times the time spent on Google. Following graph demonstrates the same. People giving more time to Facebook and making it more valuable proposition overall!

Google Vs Facebook

  • Facebook is not just a website. They extend beyond it with Facebook Connect and brings 'Social Web' to any 3rd party service. In essence, They are making the whole web more open and social!
  • People are generating a ton of content using Facebook and other social networks like twitter. Google has no or very limited control over this vast content. Thus making Google handicapped.

Why is Google not able to innovate in Social Web?

This is an interesting puzzle and here is how I look at it:

  • Google has not given serious attention to 'Social Web' and they thought Facebook is just another social network and assumed that their growth will stop at certain point. But that has not happened and now they've been a threat to Google itself.
  • Google's products save time and are result oriented. The 'Social Networks' are about 'wasting more time' in a fun way. Google's philosophy of making great and efficient products doesn't go well with Social Products.
  • Google has been focused on search and it is best at it. It is generating a ton of revenues for Google. So, Google was not concerned about making web more social.


Final thoughts

The only thing that can make google go social is 'Google Me'. This is a pretty interesting and serious attempt by Google per some 'sources' on Quora. Let's look forward to it and see what it brings to the table!

What do you guys think about Facebook and Google – who will win in the long-term?

Tuesday, August 10, 2010

Rupee Symbol ( Rs. ) on your Webpage

Rupee Symbol ( Rs. ) on your Webpage

I am sure you know how to use the New Rupee Symbol in your Word documents. (If not just download and install this font and press the key above 'tab' button and you are set).

However, using the Rupee symbol ( Rs. ) to show up on your web page is quite difficult. But there is a great solution available now.

A new startup Webrupee has come out with a API, which makes showing the rupee symbol on your website a breeze.

Here is how you can start showing Rs. symbol on your web pages:

How To Use WebRupee on your website ?

(note: please replace "[" and "]" with "<" and ">" other wise code will not work)

1. Add a stylesheet link in the head section of your webpage:

[link rel="stylesheet" type="text/css" href="http://webrupee.com/font"]

2. Add the following code enclosing your "Rs."

[span class="WebRupee"]Rs.[/span]

OR

Just include the following javascript and it will update all the " Rs. "/" Rs. " for you

[script src="http://webrupee.com/js" type="text/javascript"][/script]

(note: please replace "[" and "]" with "<" and ">" other wise code will not work)

What I really like is, if I use the script , it converts all the previous instances where Rs. is mentioned. Also, you do not have to take extra effort. Another advantage of it is – if someone copies your text, still the text will appear properly !

Go ahead, try out this simple, cross browser compatible method for using the Rupee symbol on your webpage, blog or anywhere on the web.

Monday, August 9, 2010

Features in HTML5

This information is provided as is, please know that HTML5 is a rapidly evolving specification and this refers only to these specific features in current versions of Web browsers (Chrome 1, Firefox 3, IE8, Opera 9.64, Safari 4.0) unless otherwise noted.

More information

For more support information, see the following resources


Chrome Firefox Internet Explorer Opera Safari
contentEditable Yes Yes Yes Yes Yes
Stylable Elements (new) Yes Yes No Yes Yes
getElementsByClassName Yes Yes No Yes Yes
Cross-Document Messaging Yes Yes Yes Yes Yes
Web Forms 2.0 Partial No No Yes Partial
Drag and Drop Yes Yes Yes No Yes
<audio> No 3.5 No No Yes
<video> 3.0 3.5 No Labs release, partial Yes
<canvas> Yes Yes No Yes Yes
Server-sent DOM Events No No No Partial No
Client-side Storage (name/value) 2.x Yes Yes No Yes

Thursday, August 5, 2010

Browser Cache Control



META-tags are used to provide special information to browsers and search engines regarding the handling or content of your pages.

Browser Cache Control

Many of today's browsers cache (or hold onto) pages that have been previously viewed/visited.  This is done to optimize the amount of time it takes to return to the page.  Sometimes a page author wants to prevent their page from being cached because the contained information is time sensitive.


<!--
The "expires" "http-equiv" meta-tag can be used to control
the cacheing of pages with Netscape 3.0 and later browsers.
The 'content="0"' form tells the browser to not cache the
page at all.
-->

<meta http-equiv="expires" content="0">
<meta http-equiv="expires" content="Tue, 14 Mar 2000 12:45:26 GMT">
<!--
The "pragma no-cache" http-equiv meta-tag was introduced
in the HTTP/1.1 specification. Not all browsers or proxy
agents may support these operations. To be safe you may
want to specify both expires and pragma in the file.
-->

<meta http-equiv="pragma" content="no-cache">

<!--
The "Cache-Control" http-equiv meta-tag was introduced in
the HTTP/1.1 specification. The allowed "content" values
include:
* public - may be cached in public shared caches
* private - may only be cached in private (client) cache
* no-cache - may not be cached
* no-store - may be cached but no archived

Cache-Control modifiers include:
* no-transform - proxy servers are not allowed to transform
the cached data.
* must-revalidate - proxy servers and other caching mechanisms
must revalidate the original file each time the file is
accessed.
* proxy-revalidate - same as must-revalidate, but it only
applies to proxy servers.
* max-age=<seconds> - client/browser is willing to accept
a page that is more recent than the number of seconds
indicated.
* s-maxage=<seconds> - same as max-age but applies to shared
proxy servers and other shared caching mechanisms.

The directive CACHE-CONTROL:NO-CACHE indicates cached
information should not be used and instead requests should
be forwarded to the origin server. This directive has the
same semantics as the PRAGMA:NO-CACHE.

Clients/Browsers SHOULD include both "pragma no-cache" and
"cache-control no-cache" http-equiv meta-tags when used with
a server not known to be HTTP/1.1 compliant.
-->

<meta http-equiv="cache-control" content="no-cache, must-revalidate">

<!--
Be aware that some search engines will remove pages from
their indexes based on the "expires" meta-tag. This
implies that pages that identify a 'content="0"' form may
not be indexed at all.
-->

Ownership

These meta-tags are primarily informational.


<meta name="author" content="Boo Boo Bear">
<meta name="copyright" content="copyright 2000 Bear Consulting Group">
<meta name="date" content="20 Apr 2004">

Refresh

The biggest problem with the "refresh" meta-tag method of page-refresh is that it adds to the visitor's page-history.  This means that for each automatic page refresh/reload your site visitor must select the browser's back button.  This potentially can be a considerable bother to your visitors as well as a confusion.


<head>
<!--
The "refresh" meta-tag's content identifies the number of
seconds to delay before refreshing the current document.
Notice that the URL tag is not specified, indicating that
the current document will be refreshed.
-->

<meta http-equiv="refresh" content="2">
</head>

Redirection

The biggest problem with using the "refresh" meta-tag method of page-redirection is that it adds to the visitor's page-history.  This potentially can be a considerable bother to your visitors as well as a confusion.



<head>
<!--
The "refresh" meta-tag's content identifies the number of
seconds to delay and the location (URL) to load.

When using the refresh meta-tag you should not specify "0"
for the delay time because your site's visitor will have
trouble moving "back" through their browser's history.
-->

<meta http-equiv="refresh" content="5; URL=redirectiontarget.htm">
</head>

Search Engine

There are various ways to provide hints for search engines.  There is no way to guarantee how a search engine indexes your site.  Some search engines use the "robots" meta-tag to provide hints regarding how to traverse a site's pages.  Other search engines use the robots.txt file or a combination of techniques.


<!--
The following meta-tag identifies to search engines
that this file should be indexed. This is the default
so you rarely see this usage.
-->

<meta name="robots" content="all">

<!--
The following meta-tag identifies to search engines
that this page should not be indexed nor should any
contained links be followed to other local pages.
-->

<meta name="robots" content="none">

<!--
The two following meta-tag robots have the same result,
telling the search engines to not index the current page,
but allow search engines to followed any contained links.
-->

<meta name="robots" content="noindex">
<meta name="robots" content="noindex,follow">

<!--
Lastly index the current page but don't follow local links
-->

<meta name="robots" content="index,nofollow">

Some search engines use the "keywords" and "description" meta-tags to help in the indexing of a single page.  Many engines will confirm that the listed keywords actually occur on the page.  If they don't then the page may be rejected as a spam page.


<meta name="keywords" content="meta-tags, metatags, keywords, description">
<meta name="description" content="concise description of what this file is about">

Window Target

Specifies the named window target for the document/page.  This tag is not supported by all browsers, but it can be used to prevent pages from being contained in unwanted frames.


<meta http-equiv="window-target" content="_top">

Content Rating


<meta name="rating" content="general">
<meta name="rating" content="mature">
<meta name="rating" content="restricted">
<meta name="rating" content="14 years">

HTTP-EQUIV versus NAME meta-tags

'HTTP-EQUIV' tags are the equivalent of HTTP protocol headers.  Some web-servers may actually generate HTTP headers from the HTML tags, as suggested by the HTML 3.2 specification.  You should strictly avoid inventing/creating new HTTP-EQUIV tags.  Use the 'NAME' meta-tags instead.