SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Non cluster index help (SSMS 2008 R2)


Non cluster index help (SSMS 2008 R2)

Author
Message
chauhanparixit
chauhanparixit
Valued Member
Valued Member (51 reputation)Valued Member (51 reputation)Valued Member (51 reputation)Valued Member (51 reputation)Valued Member (51 reputation)Valued Member (51 reputation)Valued Member (51 reputation)Valued Member (51 reputation)

Group: General Forum Members
Points: 51 Visits: 185
Hi Friends,

I have table

(Table_A (A_id int(PK),
col1 nvarchar,
col2 nvarchar,
col3 nvarchar,
col4 nvarchar,
col5 nvarcar
Col6 nvarchar))

A_id int(PK),--- already have one clusterd index on this column as this is PK


I hav only ONE non clustered index on col1, col2 and col3 and i have below query

SELECT col4, COl5, col6
FROM Table_A a INNER JOIN Some_Table_B b
ON a.a_id = b.b_some_id
WHERE a. col1 = 'Some value' AND a.col2 = 'some Value' and a.col3 = 'SOme value'

**Question 1**

do i need more NON Clustered index on this table so that, this query will perform well(as SELECT statement has more columns which dont have any indexex, ).


**Question 2**

if i put the non clusterd index on the columns which are only considerd for displaying the result set
(example, here col4, COl5, col6 with SELECT only, these columns are not utilised in WHERE or JOIN clause ) WIll this improve performance of the query

**Question 3**

Another question (as as i have mentined earlier NON clustred index is on col1, col2 and col3 )

if my WHERE clause hav only col_1 and col_2 ,
Example
SELECT col4, COl5, col6
FROM Table_A a INNER JOIN Some_Table_B
ON a.a_id = b.b_some_id
WHERE a. col1 = 'Some value' AND a.col2 = 'some Value' --- no column3 ok

will this non cluster index help or do i need to create another index only with these two columns.

Please do the needful.

**Thanks in Advance
Parixitsinh**
GilaMonster
GilaMonster
SSC Guru
SSC Guru (229K reputation)SSC Guru (229K reputation)SSC Guru (229K reputation)SSC Guru (229K reputation)SSC Guru (229K reputation)SSC Guru (229K reputation)SSC Guru (229K reputation)SSC Guru (229K reputation)

Group: General Forum Members
Points: 229806 Visits: 46344
http://www.sqlservercentral.com/articles/Indexing/68439/
http://www.sqlservercentral.com/articles/Indexing/68636/

Gail Shaw
Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

We walk in the dark places no others will enter
We stand on the bridge and no one may pass


Andrew G
Andrew G
SSCarpal Tunnel
SSCarpal Tunnel (4.1K reputation)SSCarpal Tunnel (4.1K reputation)SSCarpal Tunnel (4.1K reputation)SSCarpal Tunnel (4.1K reputation)SSCarpal Tunnel (4.1K reputation)SSCarpal Tunnel (4.1K reputation)SSCarpal Tunnel (4.1K reputation)SSCarpal Tunnel (4.1K reputation)

Group: General Forum Members
Points: 4123 Visits: 2285
You've typed most of the code, why not run it and try it? Turn on "include actual execution plan" and create and drop indexes to test


create table Table_A (A_id int PRIMARY KEY,
col1 nvarchar,
col2 nvarchar,
col3 nvarchar,
col4 nvarchar,
col5 nvarchar,
Col6 nvarchar)

create nonclustered index IX_col1_col2_col3 ON Table_A (col1, col2, col3) INCLUDE (col4,col5,col6)

create nonclustered index IX_col4_col5_col6 ON Table_A (col4, col5, col6)

create table Some_Table_B (b_some_id int PRIMARY KEY, data INT)

SELECT col4, COl5, col6
FROM Table_A a INNER JOIN Some_Table_B b
ON a.a_id = b.b_some_id
WHERE a. col1 = 'Some value' AND a.col2 = 'some Value' --- no column3 ok

drop index IX_col1_col2_col3 ON Table_A

drop index IX_col4_col5_col6 ON Table_A


Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search