April 30th, 2009 by Supriya Agnihotri Jagani §
Why It Is Nice to Have Clean URL’s
There could be two very strong reasons for you to rewrite your URLs. One of them is related to Search Engine Optimization. It seems that search engines are much more at ease with URLs that don’t contain long query strings.
A URL like http://www.example.com/4/basic.html can be indexed much easier, whereas its dynamic form, http://www.example.com/cgi-bin/gen.pl?id=4&view=basic, can actually confuse the search engines and cause them to miss possibly important information contained in the URL, and thus preventing you from getting the expected ranking.
With clean URLs, the search engines can distinguish folder names and can establish real links to keywords. Query string parameters seem to be an impediment in a search engine’s attempt to perform the indexing. Many of the SEO professionals agree that dynamic (a.k.a. dirty) URLs are not very appealing to web spiders, while static URLs have greater visibility in their “eyes”.
The other strong reason for URL rewriting would be the increase in usability for web users, and in maintainability for webmasters. Clean URLs are much easier to remember. A regular web surfer will find hard to remember a URL full of parameters, not to mention that they would be discouraged by the idea of typing, one character at a time, the entire URL. And they could also mistype it, and not get to where they wanted.
This is less prone to happen with clean URLs. They can help you create a more intuitive Web site altogether, making it easier for your visitors to anticipate where they could find the information they need.
Webmasters will find themselves that maintaining static URLs is a much easier task than with dynamic ones. Static URLs are more abstract, and thus more difficult to hack. The dynamic URLs are more transparent, allowing possible hackers to see the technology used to build them and thus facilitating attacks.
Also, given the length of dynamic URLs, it is possible for webmasters to make mistakes too during maintenance sessions, usually resulting in broken links. Not to mention that, when static URLs are used, should it be necessary to migrate a site from one programming language to another (e.g. from Perl to Java), the links to the site’s pages will still remain valid.
Dashes vs. Underscores
This is an issue where people have different opinions. The Web sites that still use underscores for their URLs are becoming scarcer and scarcer; Dashes seem to hold the upper hand these days.
Among the reasons for using dashes rather than underscores, we can distinguish some usability-related ones, such as the elimination of the confusion created between a space and an underscore when the URL is viewed as a link, or when printing such a URL.
Other than this, the chances that a combination of keywords contained in your Web site is included in the SERPs increase exponentially when using dashes.
To exemplify: a URL that contains “seo_techniques” will be shown by the search engine only if the user searches for seo_techniques (but this kind of search is rarely performed); whereas searches for “seo”, “techniques”, or “seo techniques” give your “seo-techniques” containing URL a better chance of being displayed on the SERPs. So, it is safe to say that this humble graphic sign can help you more than you can imagine, by greatly improving your visibility on the Web.
How to Rewrite an URL
The principle of URL rewriting is actually setting a “system” on the host server that will allow it (i.e. the server) to know how to interpret the new URL format. What actually happens when one decides to rewrite the URLs of a certain Web site is masking the dynamic URLs with static ones. This means that the URLs that previously contained query strings with elements such as “?”, “+”, “&”, “$”, “=”, or “%” will contain the more search engine friendly “/” (slash) element and present themselves in a simplified form.
Rewriting Tools
To help you with cleaning your URLs, there are rewriting tools and engines, some free of charge, other fee based. have a look at one such tool, that I found : Free Online URL Rewriting.
April 26th, 2009 by pinaldave §
Of late, I penned down an article – SQL SERVER – Interesting Observation of ON Clause on LEFT JOIN – How ON Clause Effects Resultset in LEFT JOIN – which received a very intriguing comment from one of my regular blog readers Craig. According to him this phenomenon happens due to Logical Query Processing. His comment instigated a question in my mind. I have put forth this question to all my readers at the end of the article. Let me first give you an introduction to Logical Query Processing Phase.
What actually sets SQL Server apart from other programming languages is the way SQL Server processes its code. Generally, most programming languages process statement from top to bottom. By contrast, SQL Server processes them in a unique order which is known as Logical Query Processing Phase. These phases generate a series of virtual tables with each virtual table feeding into the next phase (virtual tables not viewable). These phases and their orders are given as follows:
1. FROM
2. ON
3. OUTER
4. WHERE
5. GROUP BY
6. CUBE | ROLLUP
7. HAVING
8. SELECT
9. DISTINCT
10 ORDER BY
11. TOP
As OUTER join is applied subsequent to ON clause, all rows eliminated by the ON clause will still be included by the OUTER join as described in the article SQL SERVER – Interesting Observation of ON Clause on LEFT JOIN – How ON Clause Effects Resultset in LEFT JOIN.
However, I am perplexed about the last two, ORDER BY and TOP. According to some people TOP comes first in logical query processing phase while others suggest that ORDER BY comes first. Now, here I’ve laid down my questions for you all to think about:
1) What is the correct answer for order query processing phase – ORDER BY or TOP?
2) How can we create an example to verify query processing phase for ORDER BY and TOP?
I will soon publish the answers I receive to the above questions on this blog, with due credit given to my readers.
Reference : Pinal Dave (http://blog.SQLAuthority.com),
April 21st, 2009 by vishal.parmar §
We have lot of clients in Middle East and thus we have to develop almost all the projects in English and Arabic.
Developing in Arabic can be quite challanging sometimes not just because it is a different language but it is also read and written from right to left. So it is a very vast subject but right now let us focus on few things.
Following are couple of issues you may come across working with Arabic but there are also simple solutions to them as explained below.
(1) Sending email in Arabic
Sometimes we find that Arabic mail is displayed properly in gmail,yahoo etc but they dont look ok in Outlook, Zimbra.
Instead of Arabic junk data like following comes in email:
áã íÊã ÝÊÍ ãáÝ ÇáÞÇáÈáã íÊã ÝÊÍ ãáÝ ÇáÞÇáÈ
áã íÊã ÝÊÍ ãáÝ ÇáÞÇáÈáã íÊã ÝÊÍ ãáÝ ÇáÞÇáÈ
Solution to this problem is very simple
You just need to set mail header charset as UTF-8 intead of iso-8859-1.
PHP example:
$headers = ‘MIME-Version: 1.0′ . “\r\n”;
$headers .= ‘Content-type: text/html; charset=UTF-8‘ . “\r\n”;
(2) To display HTML page in Arabic Language
<html xmlns=”http://www.w3.org/1999/xhtml“>
<head>
<meta http-equiv=”content-type” content=”text/html; charset=UTF-8“>
I hope this may help you someday when you are stuck.
Would you like to share some of your tips about working with Arabic language here? please write them in comments.
Thanks.
April 16th, 2009 by pinaldave §
Of late, I penned down an article – SQL SERVER – Interesting Observation of ON Clause on LEFT JOIN – How ON Clause Effects Resultset in LEFT JOIN – which received a very intriguing comment from one of my regular blog readers Craig. According to him this phenomenon happens due to Logical Query Processing. His comment instigated a question in my mind. I have put forth this question to all my readers at the end of the article. Let me first give you an introduction to Logical Query Processing Phase.
What actually sets SQL Server apart from other programming languages is the way SQL Server processes its code. Generally, most programming languages process statement from top to bottom. By contrast, SQL Server processes them in a unique order which is known as Logical Query Processing Phase. These phases generate a series of virtual tables with each virtual table feeding into the next phase (virtual tables not viewable). These phases and their orders are given as follows:
1. FROM
2. ON
3. OUTER
4. WHERE
5. GROUP BY
6. CUBE | ROLLUP
7. HAVING
8. SELECT
9. DISTINCT
10 ORDER BY
11. TOP
As OUTER join is applied subsequent to ON clause, all rows eliminated by the ON clause will still be included by the OUTER join as described in the article SQL SERVER – Interesting Observation of ON Clause on LEFT JOIN – How ON Clause Effects Resultset in LEFT JOIN.
However, I am perplexed about the last two, ORDER BY and TOP. According to some people TOP comes first in logical query processing phase while others suggest that ORDER BY comes first. Now, here I’ve laid down my questions for you all to think about:
1) What is the correct answer for order query processing phase – ORDER BY or TOP?
2) How can we create an example to verify query processing phase for ORDER BY and TOP?
I will soon publish the answers I receive to the above questions on this blog, with due credit given to my readers.
Reference : Pinal Dave (http://blog.SQLAuthority.com)
April 16th, 2009 by pinaldave §
SQL Server 2008 Service Pack 1 (SP1) is now available. You can use these packages to upgrade any SQL Server 2008 edition.
Build of SP1 is SP1 is build 10.00.2531.00.
Reference : Pinal Dave (http://blog.sqlauthority.com)
April 9th, 2009 by divyang.shah §
Some time its necessary to take backup of the database but generally this kind of script is not available easily on the internet.
Fortunately I found one script for that and much credit goes to Oliver Mueller (oliver@teqneers.de) for writing the script.
This Script will take all the database backup from the specified domain.
It will give output in .tar formate as a single file and in that file you will get all the database backup as .sql files.
####################################################
## MySQL Backup Script
####################################################
## For more documentation and new versions, please visit:
## http://www.dagondesign.com/articles/automatic-mysql-backup-script/
## ——————————————————————-
## Created by Dagon Design (www.dagondesign.com).
## Much credit goes to Oliver Mueller (oliver@teqneers.de)
## for contributing additional features, fixes, and testing.
####################################################
####################################################
## Usage Instructions
####################################################
## This script requires two files to run:
## backup_dbs.php – Main script file
## backup_dbs_config.php – Configuration file
## Be sure they are in the same directory.
## ——————————————————————-
## Do not edit the variables in the main file. Use the configuration
## file to change your settings. The settings are explained there.
## ——————————————————————-
## A few methods to run this script:
## – php /PATH/backup_dbs.php
## – BROWSER: http://domain/PATH/backup_dbs.php
## – ApacheBench: ab “http://domain/PATH/backup_dbs.php”
## – lynx http://domain/PATH/backup_dbs.php
## – wget http://domain/PATH/backup_dbs.php
## – crontab: 0 3 * * * root php /PATH/backup_dbs.php
####################################################
####################################################
Main part of backup_dbs.php
####################################################
############# Start #############
error_reporting( E_ALL );
// Initialize default settings
$MYSQL_PATH = ‘/usr/bin’;
$MYSQL_HOST = ‘localhost’;
$MYSQL_USER = ‘root’;
$MYSQL_PASSWD = ‘password’;
$BACKUP_DEST = ‘/db_backups’;
$BACKUP_TEMP = ‘/tmp/backup_temp’;
// Load configuration file
$current_path = dirname(__FILE__);
if( file_exists( $current_path.’/backup_dbs_config.php’ ) ) {
require( $current_path.’/backup_dbs_config.php’ );
} else {
echo ‘No configuration file [backup_dbs_config.php] found. Please check your installation.’;
exit;
}
################################
# main
################################
// set header to text/plain in order to see result correctly in a browser
header( ‘Content-Type: text/plain; charset=”UTF-8″‘ );
header( ‘Content-disposition: inline’ );
// set execution time limit
if( ini_get( ‘max_execution_time’ ) < $MAX_EXECUTION_TIME ) {
set_time_limit( $MAX_EXECUTION_TIME );
}
// initialize error control
$error = false;
// guess and set host operating system
if( strtoupper(substr(PHP_OS, 0, 3)) !== ‘WIN’ ) {
$os = ‘unix’;
$backup_mime = ‘application/x-tar’;
$BACKUP_NAME .= ‘.tar’;
} else {
$os = ‘windows’;
$backup_mime = ‘application/zip’;
$BACKUP_NAME .= ‘.zip’;
}
// create directories if they do not exist
if( !is_dir( $BACKUP_DEST ) ) {
$success = mkdir( $BACKUP_DEST );
error( !$success, ‘Backup directory could not be created in ‘ . $BACKUP_DEST, true );
}
if( !is_dir( $BACKUP_TEMP ) ) {
$success = mkdir( $BACKUP_TEMP );
error( !$success, ‘Backup temp directory could not be created in ‘ . $BACKUP_TEMP, true );
}
// prepare standard log file
$log_path = $BACKUP_DEST . ‘/’ . $LOG_FILE;
($f_log = fopen($log_path, ‘w’)) || error( true, ‘Cannot create log file: ‘ . $log_path, true );
// prepare error log file
$err_path = $BACKUP_DEST . ‘/’ . $ERR_FILE;
($f_err = fopen($err_path, ‘w’)) || error( true, ‘Cannot create error log file: ‘ . $err_path, true );
// Start logging
writeLog( “Executing MySQL Backup Script v1.4″ );
writeLog( “Processing Databases..” );
################################
# DB dumps
################################
$excludes = array();
if( trim($EXCLUDE_DB) != ” ) {
$excludes = array_map( ‘trim’, explode( ‘,’, $EXCLUDE_DB ) );
}
// Loop through databases
$db_conn = @mysql_connect( $MYSQL_HOST, $MYSQL_USER, $MYSQL_PASSWD ) or error( true, mysql_error(), true );
$db_result = mysql_list_dbs($db_conn);
$db_auth = ” –host=\”$MYSQL_HOST\” –user=\”$MYSQL_USER\” –password=\”$MYSQL_PASSWD\”";
while ($db_row = mysql_fetch_object($db_result)) {
$db = $db_row->Database;
if( in_array( $db, $excludes ) ) {
// excluded DB, go to next one
continue;
}
// dump db
unset( $output );
exec( “$MYSQL_PATH/mysqldump $db_auth –opt $db 2>&1 >$BACKUP_TEMP/$db.sql”, $output, $res);
if( $res > 0 ) {
error( true, “DUMP FAILED\n”.implode( “\n”, $output) );
} else {
writeLog( “Dumped DB: ” . $db );
if( $OPTIMIZE ) {
unset( $output );
exec( “$MYSQL_PATH/mysqlcheck $db_auth –optimize $db 2>&1″, $output, $res);
if( $res > 0 ) {
error( true, “OPTIMIZATION FAILED\n”.implode( “\n”, $output) );
} else {
writeLog( “Optimized DB: ” . $db );
}
} // if
} // if
// compress db
unset( $output );
if( $os == ‘unix’ ) {
exec( “$USE_NICE $COMPRESSOR $BACKUP_TEMP/$db.sql 2>&1″ , $output, $res );
} else {
exec( “zip -mj $BACKUP_TEMP/$db.sql.zip $BACKUP_TEMP/$db.sql 2>&1″ , $output, $res );
}
if( $res > 0 ) {
error( true, “COMPRESSION FAILED\n”.implode( “\n”, $output) );
} else {
writeLog( “Compressed DB: ” . $db );
}
if( $FLUSH ) {
unset( $output );
exec(“$MYSQL_PATH/mysqladmin $db_auth flush-tables 2>&1″, $output, $res );
if( $res > 0 ) {
error( true, “Flushing tables failed\n”.implode( “\n”, $output) );
} else {
writeLog( “Flushed Tables” );
}
} // if
} // while
mysql_free_result($db_result);
mysql_close($db_conn);
############ End #############
Create a cron job and be tension free about backing up your database.
Download the full script from here.
April 8th, 2009 by abhishek §
Thank you for your patience so far in getting results of the Coding War Games. But before announcing the result I would again thank all of the participants. They really did it and they have the stemina and determination to prove their point in 24 hours.
Total 6 teams participated in this event having 4 members each and all of them coded for 24 hours non stop. Obviously the output after 24 hours was not perfect but good enough to measure the skills of each of them. I am sure all of them learnt a lot out of this event and will do much better next time.
Now let me tell you how did we evaluate each teams work:
1) We put the demos of each team on demo server.
2) Our QA team extensively tested the applications for one week on various criteria
- stability
- user friendliness of the application
- speed of the application
- best design/creativity
3) They came out with the final report.
As per the report 2 teams were having close fight.
One team was of Chirag’s and the other was of Amit’s. Both the teams were from Deewar (.NET department). Team members are as follow.
a) Chirag
Nishant
Hitesh
Urvish
They have produced following in 24 hours.
b) Amit
Dhruval
Virat
Dhaval
and they have produced following in 24 hours

http://demo.digi-corp.com/ORS/Default.aspx
There are lots of bugs and many of the things may not be working but that is understood when you have to code about 1-2 man months work in 24 hours, effectively 6-8 man days.
Both of them had almost similar functionality done and almost similar kind of issues. But one has to be the winner out of them and the winner is DreamUpload!! i.e. Chirag’s team :)
They have done fantastic job in 24 hours and they deserve this trophy.
Once again thank you all the participants for making this event a success. The best thing about the event was the level of energy and committment people showed in those 24 hours.
From the feedback which I have received so far developers are looking forward to such events in future and that gives me hope of coming with something new very soon.
April 6th, 2009 by pinaldave §
Gandhinagar SQL Server User Group launch event was held on March 27, 2009. This successful, well-attended event received very positive and warm community response. This launch event, unexpectedly, saw over 50 database enthusiasts participating. It was really a moment of pleasant surprise when we ran out of chairs. The otherwise spacious room started getting smaller as more and more people joined in, and unquestionably, we felt ecstatic about it! Visit Gandhinagar SQL Server User Group Portal and register yourself now!
We commenced Gandhinagar SQL Server User Group launch event sharp at 6:30 and completed it precisely at 7:30. During these 60 minutes we conducted intense database discussion, and we had our share of some light moments as well. As this was the very first launch event, I had the privilege of being the sole speaker for all the sessions.
The agenda of meeting was as follows:
6:30 PM – 7:00 PM – Introduction to Joins and Real Life Scenario
7:00 PM – 7:10 PM – Tips to Improve SQL Performance
7:10 PM – 7:15 PM – Simple SQL Quiz (3 Question)
7:15 PM – 7:20 PM – Feedback
7:20 PM – 7:30 PM – Award for “Best Participant” and Questions and Answer
I had a great time discussing Join and I promised users that I will definitely be sharing some of my slides and scripts from the meeting with everybody. Click here to download slides and script.
One of the requests I received was to write down a simple and precise definition of Joins. I was quite taken aback to see that Joins are still a subject of interest for developers. I am seriously considering this request. To all those developers wanting to get insight into Joins I promise that I will soon come up with a write-up on Introduction to Joins.
I shared some tips on SQL Server performance improvement and even conducted an interesting and informative quiz round. UG members who gave correct answer to the questions received nice gifts. The best part of the event was giveaway of gifts to the participants near the end when everybody was really involved. The gifts included a vibrant red shirt and few other interesting gifts for the best participants. These Gifts were co-sponsored by Digicorp and me.
Here are a few photographs of UG meeting.







My heartfelt thanks go to the sponsor of this event – Digicorp - for their significant contribution to make this event a success. They were extremely prompt in making the last minute arrangements, especially arranging for more chairs for the room which was brimming with participants. Digicorp is a prominent IT service provider and an outsourcing company based in Ahmedabad, India. Its services range from Customized Application Development to Facebook Application Development.
To sum up, I would like to say that there are many advantages of User Group meetings. The prominent advantages are ‘Gaining Knowledge’ and ‘Sharing Knowledge’, which will surely add value to you as a professional or as a knowledge seeker.
Next time, I will be expecting a similar overwhelming response and even more participants to show up in UG meeting.
Reference : Pinal Dave (http://blog.sqlauthority.com)
April 1st, 2009 by pinaldave §
More than a year ago I had written article SQL SERVER – Union vs. Union All – Which is better for performance? I have got many request to update this article. It is not fair to update already written article so I am rewriting it again with additional information.
UNION
The UNION command is used to select related information from two tables, much like the JOIN command. However, when using the UNION command all selected columns need to be of the same data type. With UNION, only distinct values are selected.
UNION ALL
The UNION ALL command is equal to the UNION command, except that UNION ALL selects all values.
The difference between Union and Union all is that Union all will not eliminate duplicate rows, instead it just pulls all rows from all tables fitting your query specifics and combines them into a table.
A UNION statement effectively does a SELECT DISTINCT on the results set. If you know that all the records returned are unique from your union, use UNION ALL instead, it gives faster results.
Run following script in SQL Server Management Studio to see the result between UNION ALL and UNION. Download complete script from here.
/* Declare First Table */
DECLARE @Table1 TABLE (ColDetail VARCHAR(10))
INSERT INTO @Table1
SELECT 'First'
UNION ALL
SELECT 'Second'
UNION ALL
SELECT 'Third'
UNION ALL
SELECT 'Fourth'
UNION ALL
SELECT 'Fifth'
/* Declare Second Table */
DECLARE @Table2 TABLE (ColDetail VARCHAR(10))
INSERT INTO @Table2
SELECT 'First'
UNION ALL
SELECT 'Third'
UNION ALL
SELECT 'Fifth'
/* Check the data using SELECT */
SELECT *
FROM @Table1
SELECT *
FROM @Table2
/* UNION ALL */
SELECT *
FROM @Table1
UNION ALL
SELECT *
FROM @Table2
/* UNION */
SELECT *
FROM @Table1
UNION
SELECT *
FROM @Table2
GO
In our example we have two tables: @Table1 and @Table2.

Now let us run UNION ALL and UNION together and see the resultset as well as Execution Plan compared to complete set of query. You can always turn on actual execution plan using CTRL+M.
We can see from the resultset of UNION ALL that it returns everything from both the table but from UNION it is very clear that only DISTINCT rows from both the table is only retrieved.

Additionally, when comparing the execution plan of UNION ALL and UNION it is also quite clear that UNION ALL is way less expensive than UNION as it does not have DISTINCT SORT operation.

Let me know what do you think about this article. If you have any suggestion for improvement please let me know and I will update articles according to that.
Reference : Pinal Dave (http://blog.SQLAuthority.com)