Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
kiruthika
Yak Posting Veteran
67 Posts |
Posted - 2008-03-17 : 03:44:36
|
| Hi all,Actually my table is having 44496 rows.I want to create index on my table for improving performance.I want to search the records by using type exampleselect * from messages where type = 1 orselect * from messages where type=2This is the script for creating index on table----------------------------------------------create clustered index myindextest on messages(type)Before creating clustered index:---------------------------------duration :1266After creation:---------------duration : 836I droped the clustered index and create a new non clustered index.The result will becreate index myindextest on messages(type)Before creating Non-clustered index:---------------------------------duration :1326After creation:---------------duration : 733Which index can i create on type column? I totally confused.Can anyone give me a proper suggestion for using indexes?This is the script of my table:-------------------------------if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[messages]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)drop table [dbo].[messages]GOCREATE TABLE [dbo].[messages] ( [id] [varchar] (255) COLLATE SQL_Latin1_General_CP1_CI_AS NULL , [status] [varchar] (255) COLLATE SQL_Latin1_General_CP1_CI_AS NULL , [from_username] [varchar] (255) COLLATE SQL_Latin1_General_CP1_CI_AS NULL , [to_username] [varchar] (255) COLLATE SQL_Latin1_General_CP1_CI_AS NULL , [message] [varchar] (255) COLLATE SQL_Latin1_General_CP1_CI_AS NULL , [pictures] [varchar] (255) COLLATE SQL_Latin1_General_CP1_CI_AS NULL , [sent] [varchar] (255) COLLATE SQL_Latin1_General_CP1_CI_AS NULL , [received] [varchar] (255) COLLATE SQL_Latin1_General_CP1_CI_AS NULL , [type] [int] NULL ) ON [PRIMARY]GOThanks in Advance! kiruthikahttp://www.ictned.eu |
|
|
kiruthika
Yak Posting Veteran
67 Posts |
Posted - 2008-03-17 : 07:05:29
|
| Hi, Please reply me. I'm wating for long time. Thanks in Advance.kiruthikahttp://www.ictned.eu |
 |
|
|
sodeep
Master Smack Fu Yak Hacker
7174 Posts |
Posted - 2008-03-17 : 09:41:08
|
| Put your query in Database Tuning advisor and it will suggest you the best indexes and statistics. |
 |
|
|
LoztInSpace
Aged Yak Warrior
940 Posts |
Posted - 2008-03-17 : 19:13:33
|
| This looks like a conversion from Excel or something, but even so, there are some rules of thumb1) Add primary key - you will want an index on your ID I expect2) Index any foriegn keys3) Index where you have good selectivity for where clauses. I am surprised that indexing type helps but like I said, it all depends on what your selectivity is.4) Careful with clustered indexes - best use with timestamps or ever increasing IDs, otherwise stick with non-clustered.5) Look at query plans not wall-clock timings. Unless you are getting orders of magnitude, there are too many variables to judge performance on elapsed time. Look for low IO costs. |
 |
|
|
|
|
|
|
|