Madhivanan's TSQL Blog

In the Query Analyser, set the Result mode to Text (Press CTRL+T) and run the following code
set nocount on
select
space(17-len(replicate(char(94),no)))+ replicate(char(94),no*2-1)
from
(
select top 10 row_number() over (order by name) as no from sysobject......

Often deveopers confuse themselves between Timestamp and Datetime datatypes. But they are entirely different datatypes. Although the name has Time, the Timestamp datatype has nothing to do anything with date or time. Also you cannot explicitely add/update that column. It gets updated whenever data a......

Assume that there is a database named test in the server and you want to take a backup of that database. Run the following code without specifying the path
backup database test to disk=''
You will get the following error messages
Msg 3044, Level 16, State 2, Line 1
Invalid zero-length device......

Suppose there are two tables which have 5 and 4 rows respectively and related by the column id. If you want to join these two tables and get data from table1 you can write old style join like below
create table table1 (id int, names varchar(100))
insert into table1
select 1,'test1' union all
s......

This is just for Fun. The following code is unformatted, unclear and may be confusing. But curious to know the result? Set the result mode of the query window to Text . While you are in Query Window press CONTROL+T and run the following code and see what it returns.
......

As I have informed you earlier in this post, there are some interesting tips I have contributed in November 2011. You may find them interesting if you follow them. The following are some of my tips I posted there
Most Learned Posts of all time
You can drop multiple tables using single DROP stateme......

I had blogged about Different ways to know structure of the tables. One of the methods is to highlight the object name and press Alt+F1. But this will not work if the object name contains multiparts ie database name, owner name etc.
Consider the following object
sys.objects
Applying Alt+F1 wil......

There are many aggregate functions available in SQL Server. One thing that most of the people forget is that Aggregate functions always return atleast a row no matter if there are rows in the table or where clause returns or does not return any resultset
Consider the following example
declare @t......

A computed column in SQL Server is an expression which is based on another column in the same table. Consider the following example
create table test_table
(
id int,
names varchar(100),
cust_id as right('00000'+cast(id as varchar(10)),5)
)
GO
insert into test_table (id, names)
sel......

As you know, Pinal Dave, SQL Server MVP, Blogger,Speaker and Evangelist is the co-author of the part 4 of the series SQL Programming Joes 2 Pros: Programming & Development For Microsoft SQL Server 2008 (SQL Exam Prep Series 70-433 (Volume IV)
He is now,along with Vinod kumar, author of anothe......