SQL Server Installation issue


When i am installing Sql server 2005 on Windows XP ,these error come...sqlserver setup failed to compile the Managed Object Format (MOF) file C:\ProgramFiles\MicrosoftSQlserver\90\Shared\sqlmgmproviderxpsp2up.mof.To proceed see Troubleshooting an Installation of SQlserver 2005 or How to:View Sql server 2005 SetUp Log Files "in Sqlserver 2005 Setp Help documentation.


1. We need to install the pre-requisite which will take care of providing a correct baseline to install sql server in your machine.

2. May be due to corruption in WMI in your Windows Server. Try reinstalling WMI. There's information on how to do this at: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/wmisdk/wmi/reinstalling_wmi.asp

Venkatesan Prabu .J

Group by clause in SQL Server


I want to fetch the count of people available in the city. How can we achieve it?

Solution: In this case, you need to use group by clause.

create table venkattable(id int,city varchar(100))
insert into venkattable values(1,'Chennai')
insert into venkattable values(2,'Chennai')
insert into venkattable values(3,'Chennai')
insert into venkattable values(4,'Bombay')

select count(*) as [Count],city from venkattable group by city


Count City


1 Bombay

3 Chennai



Venkatesan Prabu .J


Create windows authentication user in SQL Server

Creating/Configuring Windows authetication in SQL Server:

I got a peculiar query in one of the SQL forum and I wish to write a detailed article on this. In SQL Server, there are 3 types of authentication to enter into your database.

1. Windows authentication. (Will take the in built windows account as an authentication)
2. SQL Server authenticaiton (We need to specify the username and password to enter into the server)
3. Mixed mode authentication (Combination of windows and SQL authentication)

Goto Server Explorer -> Security -> Login ->New Login

Click on the Search button and a window will popup to search for the available users in the machine. In the below screenshot, my machine name is venkat and santhi is an administrator in my machine. I am trying to create windows authentication for this user.

Select the "Server Roles", am trying to make this use as sysadmin.

Select the database to which the user needs proper access.

On clicking "OK" the user is created.

Venkatesan Prabu .J

Display Open Transaction in SQL Server

Fetch open transactions in SQL Server:

We will face an usual problem in transactional queries, Open a transaction and forgot to commit or rollback. This creates lot of issues like,
1. Your transaction wont get committed or reflected.

2. Sometimes, the table will get locked and other transaction cant use the table results in deadlock.

3. You log file will be flooded and if its full, It will hang the entire database.

To get all the transactions available in the database use the below command,


insert into VenkatSample values(100,'Karthi','Karthi')


The above command will list down the transactions pending for commit or rollback. On restarting the server, those transactions will get rollbacked in turn everything will be flushed.

Below DMV will provide the transactions happened in this particular session,

select * from sys.dm_tran_session_transactions

sys.dm_tran_database_transactions will provide all the transactions stored in the database.

Happy Learning!!!


Venkatesan Prabu .J

Covering Index in SQL Server

Covering Index:

Every SQL Server developers used to think about performance. They expect their queries should be fast and they want to write efficient queries. Here is a small tip to improve the performance of your queries.

First thought to improve Performance is to create or modify or rebuild the indexes. Index are special handy objects for the sql developers to improve the performance. Creating an index on the table will improve the accessibility to the tables. Retrieving the values from the table becomes too easy. There are two types of index,

1. Clustered index(On creating primary key, the index will get created)
2. Non-clustered index.

In addtion to the above indexes, we are having another index called Covering index. It's a straight foward index. Considering a query is using 5 columns frequently, In that case we can create a composite index on the table involving all the 5 columns. This will avoid table scan and this will improve the performance of your table access.
Lets see a small code snippet,

drop table VenkatSample
create table VenkatSample(id int, [name] varchar(100),name1 varchar(100))
insert into VenkatSample values(1,'Venkat','Prabu')
insert into VenkatSample values(2,'suba','Venkat')
insert into VenkatSample values(3,'Arun','Arun')
insert into VenkatSample values(4,'Lakshmi','Lakshmi')
insert into VenkatSample values(5,'Santhi','Santhi')
insert into VenkatSample values(7,'Karthi','Karthi')
insert into VenkatSample values(8,'Lakshmi','Lakshmi')
insert into VenkatSample values(3,'Santhi','Santhi')
insert into VenkatSample values(89,'Karthi','Karthi')

select * from VenkatSample
select name,max(id) from VenkatSample group by id,name

Now, am creating an index on the table to force index scan instead of table scan.

create index VenkatIndex_IX on VenkatSample(id,[name])
select name,max(id) from VenkatSample group by id,name

1. Considering, am having only 2 columns in a table. Placing a covering index on the 2 columns will not have any major effect in your query performance.

2. Over usage or more covering index will have a reverse effect in the query performance. So, we should have a clear picture on the column usage in the queries.

3. In case of adverse effect, go back to your clustered or non clustered index on specific column.

Happy Learning!!!

Thanks and Regards,
Venkatesan Prabu .J

"svchost (876) The database engine stopped" in sql server

SQL Server typical error:
Some times, Our sql server will get stopped frequently. On checking the event viewer, we will get the following error message "svchost (876) The database engine stopped".

If you got such an error message, check the following.
1. Goto run, type service.msc. You will get services console, check the sql server agent and sql server services. If its not running right click the services and start it.

2. Check for anti virus software, you should get exclusion from the antivirus.

3. Check for "Autoclose option" in the database. If you have option, its advisable to uncheck this option.

Happy Learning!!!

Venkatesan Prabu .J

My T-SQL Gallery @code.msdn.microsoft

Created my own T-SQL Gallery in Microsoft site. Do visit the same and share your feedback,


Thanks and Regards,
Venkatesan Prabu .J

SQL Server Interview questions - Part 1

What is the significance of NULL value and why should we avoid permitting null values?
Null means no entry has been made. It implies that the value is either unknown or undefined.We should avoid permitting null values because Column with NULL values can't have PRIMARY KEY constraints. Certain calculations can be inaccurate if NULL columns are involved.

What is SQL whats its uses and its component ?
The Structured Query Language (SQL) is foundation for all relational database systems. Most of the large-scale databases use the SQL to define all user and administrator interactions. It enable us to retrieve the data from based on our exact requirement. We will be given a flexibility to store the data in our own format.

The DML component of SQL comprises four basic statements:
* SELECT to get rows from tables
* UPDATE to update the rows of tables
* DELETE to remove rows from tables
* INSERT to add new rows to tables

What is DTS in SQL Server ?
Data Transformation Services is used to transfer the data from one source to our required destination. Considering am having some data in sql server and I need to transfer the data to Excel destination. Its highly possible with dialogue based tool called Data Transformation services. More customization can be achieved using SSIS. A specialized tool used to do such migration works.

What is the difference between SQL and Pl/Sql ?

Straight forward. SQL is a single statement to finish up our work.Considering, I need some data from a particular table. “Select * from table” will fetch the necessary information. Where as I need to do some row by row processing. In that case, we need to go for Procedural Logic / SQL.

What is the significance of NULL value and why should we avoid permitting null values?
Null means no entry has been made. It implies that the value is either unknown or undefined.We should avoid permitting null values because Column with NULL values can't have PRIMARY KEY constraints. Certain calculations can be inaccurate if NULL columns are involved.

Difference between primary key and Unique key?
Both constraints will share a common property called uniqueness. The data in the column should be unique. The basic difference is,
· Primary key won’t allow null value. Whereas, unique key will accept null value but only one null value.
· On creating primary key, it will automatically format the data inturn creates clustered index on the table. Whereas, this characteristics is not associated with unique key.
· Only one primary key can be created for the table. Any number of Unique key can be created for the table.

Select Statement in SQL Server

Select Statement in SQL Server

String Functions in sql server

String Functions in sql server

SQL Server Interview Question - Part 2

What is normalization?

Normalization is the basic concept used in designing a database. Its nothing but, an advise given to the database to have minimal repetition of data, highly structured, highly secured, easy to retrieve. In high level definition, the Process of organizing data into tables is referred to as normalization.

What is a stored procedure:
Stored procedures are precompiled T-SQL statements combined to perform a single task of several tasks. Its basically like a Macro so when you invoke the Stored procedure, you actually run a set of statements. As, its precompiled statement, execution of Stored procedure is compatatively high when compared to an ordinary T-SQL statement.

What is the difference between UNION ALL Statement and UNION ?
The main difference between UNION ALL statement and UNION is UNION All statement is much faster than UNION,the reason behind this is that because UNION ALL statement does not look for duplicate rows, but on the other hand UNION statement does look for duplicate rows, whether or not they exist.

Example for Stored Procedure?
They are three kinds of stored procedures,1.System stored procedure – Start with sp_2. User defined stored procedure – SP created by the user.3. Extended stored procedure – SP used to invoke a process in the external systems.Example for system stored proceduresp_helpdb - Database and its propertiessp_who2 – Gives details about the current user connected to your system. sp_renamedb – Enable you to rename your database

What is a trigger?

Triggers are precompiled statements similar to Stored Procedure. It will automatically invoke for a particular operation. Triggers are basically used to implement business rules.

What is a view?
If we have several tables in a db and we want to view only specific columns from specific tables we can go for views. It would also suffice the needs of security some times allowing specfic users to see only specific columns based on the permission that we can configure on the view. Views also reduce the effort that is required for writing queries to access specific columns every time.

What is an Index?
When queries are run against a db, an index on that db basically helps in the way the data is sorted to process the query for faster and data retrievals are much faster when we have an index.

What are the types of indexes available with SQL Server?

There are basically two types of indexes that we use with the SQL ServerClustered -

1. It will format the entire table, inturn physically sort the table.

2. Only one clustered index can be created for a table.

3. Data will be located in the leaf level.

4. By default, primary key will create clustered index on the table.

Non-Clustered Index

1. It wont touch the structure of the table.

2. It forms an index table as reference to the exact data.

3. A reference to the data will be located in the leaf level.

4. For a table, we can create 249 non clustered index.

Happy Learning!!!
Venkatesan Prabu .J

SQL Interview question

Extent Vs Page?

Pages are low level unit to store the exact data in sql server. Basically, the data will be stored in the mdf, ldf, ndf files. Inturn, pages are logical units available in sql server.The size of the page is 8KB.

Eight consecutive pages will form an extent 8 * 8KB = 64KB.

Thus I/O level operation will be happening at pages level.The pages will hold a template information at the start of each page (header of the page).

They are,

1. page number,

2. page type,

3. the amount of free space on the page,

4. the allocation unit ID of the object that owns the page.

Extents will be classifed into two types,

1. Uniform extents

2. Mixed extents

Uniform Extents:It occupied or used by a single object. Inturn, a single object will hold the entire 8 pages.Mixed

Extents:Mulitple objects will use the same extent. SQL Server will allow a max of eight objects to use a shared extent.

Property of SQL Server :Initally if an object is created, sql server will allocate the object to the mixed extent and once if the size reaches 8 pages and more... immediately, a new uniform extent will be provided for that particular object.

Herecomes, our fragmentation and reindexing concepts.

Best Joke - Enjoy it

Best Joke - Enjoy it