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


How to execute Index?


How to execute Index?

Author
Message
chandrasekaran.ganapathy
chandrasekaran.ganapathy
Old Hand
Old Hand (336 reputation)Old Hand (336 reputation)Old Hand (336 reputation)Old Hand (336 reputation)Old Hand (336 reputation)Old Hand (336 reputation)Old Hand (336 reputation)Old Hand (336 reputation)

Group: General Forum Members
Points: 336 Visits: 92
I have gone through this example for index in one site.

create table employee1(
ID int,
name nvarchar (20),
salary int,
city nvarchar (20),
region nvarchar (20)
)

insert into employee1 values ('1', 'Jason', '40420', 'New York', 'W')
insert into employee1 values ('2', 'Robert','14420', 'Vancouver','N')
insert into employee1 values ('3', 'Celia', '24020', 'Toronto', 'W')
insert into employee1 values ('4', 'Linda', '40620', 'New York', 'N')
insert into employee1 values ('5', 'David', '80026', 'Vancouver','W')
insert into employee1 values ('6', 'James', '70060', 'Toronto', 'N')
insert into employee1 values ('7', 'Alison','90620', 'New York', 'W')
insert into employee1 values ('8', 'Chris', '26020', 'Vancouver','N')
insert into employee1 values ('9', 'Mary', '60020', 'Toronto', 'W')

CREATE UNIQUE CLUSTERED INDEX IX_Employee
ON Employee1
([Id], [Name] DESC)
GO

I have done this.

But I am giving

Select * from IX_Employee.

It is not working.

Here What is the use of creating Index?
Kingston Dhasian
Kingston Dhasian
SSCertifiable
SSCertifiable (6.1K reputation)SSCertifiable (6.1K reputation)SSCertifiable (6.1K reputation)SSCertifiable (6.1K reputation)SSCertifiable (6.1K reputation)SSCertifiable (6.1K reputation)SSCertifiable (6.1K reputation)SSCertifiable (6.1K reputation)

Group: General Forum Members
Points: 6142 Visits: 5288
You can never execute an Index. To get the data you will have to always SELECT * from the table.

And one more thing, is you get some script from somewhere make sure you understand it completely and then try it. You can Google for lot of information on Indexes.


Kingston Dhasian

How to post data/code on a forum to get the best help - Jeff Moden
http://www.sqlservercentral.com/articles/Best+Practices/61537/
GSquared
GSquared
SSC Guru
SSC Guru (59K reputation)SSC Guru (59K reputation)SSC Guru (59K reputation)SSC Guru (59K reputation)SSC Guru (59K reputation)SSC Guru (59K reputation)SSC Guru (59K reputation)SSC Guru (59K reputation)

Group: General Forum Members
Points: 59733 Visits: 9730
You don't select directly from the index. You select from the table.

If the index is appropriate, SQL Server will use it when you do that.

To really "get" indexing, you need to take a look at the subject of "execution plans". RedGate has a good book on that subject, which is free (to download). Here's the link: http://www.red-gate.com/about/book_store/sql_server_execution_plans.htm

The author is a regular on this site, and very, very knowledgeable about SQL Server.

- Gus "GSquared", RSVP, OODA, MAP, NMVP, FAQ, SAT, SQL, DNA, RNA, UOI, IOU, AM, PM, AD, BC, BCE, USA, UN, CF, ROFL, LOL, ETC
Property of The Thread

"Nobody knows the age of the human race, but everyone agrees it's old enough to know better." - Anon
vidya_pande
vidya_pande
SSCommitted
SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)

Group: General Forum Members
Points: 1849 Visits: 242
What a question Hehe



PaulB-TheOneAndOnly
PaulB-TheOneAndOnly
SSChampion
SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)

Group: General Forum Members
Points: 14669 Visits: 4639
chandrasekaran.ganapathy (4/8/2010)Here What is the use of creating Index?


Allow me to answer you with a question... What is the use of having an index in a book? perhaps to allow you to find the page where some information you are looking for is instead of having to read the whole book from page one?

_____________________________________
Pablo (Paul) Berzukov

Author of Understanding Database Administration available at Amazon and other bookstores.

Disclaimer: Advice is provided to the best of my knowledge but no implicit or explicit warranties are provided. Since the advisor explicitly encourages testing any and all suggestions on a test non-production environment advisor should not held liable or responsible for any actions taken based on the given advice.
chandrasekaran.ganapathy
chandrasekaran.ganapathy
Old Hand
Old Hand (336 reputation)Old Hand (336 reputation)Old Hand (336 reputation)Old Hand (336 reputation)Old Hand (336 reputation)Old Hand (336 reputation)Old Hand (336 reputation)Old Hand (336 reputation)

Group: General Forum Members
Points: 336 Visits: 92
Nice explanation. But I dint get how it is related to the database. Are you meant that if i can pull the data where index no is 3 I can use that index. is it right? But I dint find any index no. assigned to the data. Can you give example with the small sample data.
chandrasekaran.ganapathy
chandrasekaran.ganapathy
Old Hand
Old Hand (336 reputation)Old Hand (336 reputation)Old Hand (336 reputation)Old Hand (336 reputation)Old Hand (336 reputation)Old Hand (336 reputation)Old Hand (336 reputation)Old Hand (336 reputation)

Group: General Forum Members
Points: 336 Visits: 92
Hi Kingston and all,

Got it. I have read some article. So If i make a query like

Select * from employeeId where employeeId between 'xxxxxx' and 'xxxx'
or
Select * from employeeId where employeeId > 'xxxxx'.


These kind of query will be fetched from the database too fast using index.

Please correct me if i am wrong.
Kingston Dhasian
Kingston Dhasian
SSCertifiable
SSCertifiable (6.1K reputation)SSCertifiable (6.1K reputation)SSCertifiable (6.1K reputation)SSCertifiable (6.1K reputation)SSCertifiable (6.1K reputation)SSCertifiable (6.1K reputation)SSCertifiable (6.1K reputation)SSCertifiable (6.1K reputation)

Group: General Forum Members
Points: 6142 Visits: 5288
chandrasekaran.ganapathy (4/8/2010)
Hi Kingston and all,

Got it. I have read some article. So If i make a query like

Select * from employeeId where employeeId between 'xxxxxx' and 'xxxx'
or
Select * from employeeId where employeeId > 'xxxxx'.


These kind of query will be fetched from the database too fast using index.

Please correct me if i am wrong.


Depends. If the optimizer thinks that using the index will be a faster method to fetch the required data it will use your index and fetch the data. But if it decides otherwise, it will not use your index.

And did you download the book from the link provided by GSquared? I don't think you did and if you did you haven't read it. It is a free download and it will have answers to most of your questions.


Kingston Dhasian

How to post data/code on a forum to get the best help - Jeff Moden
http://www.sqlservercentral.com/articles/Best+Practices/61537/
GSquared
GSquared
SSC Guru
SSC Guru (59K reputation)SSC Guru (59K reputation)SSC Guru (59K reputation)SSC Guru (59K reputation)SSC Guru (59K reputation)SSC Guru (59K reputation)SSC Guru (59K reputation)SSC Guru (59K reputation)

Group: General Forum Members
Points: 59733 Visits: 9730
chandrasekaran.ganapathy (4/8/2010)
Nice explanation. But I dint get how it is related to the database. Are you meant that if i can pull the data where index no is 3 I can use that index. is it right? But I dint find any index no. assigned to the data. Can you give example with the small sample data.


I don't understand your question. Not sure what you mean about index numbers.

- Gus "GSquared", RSVP, OODA, MAP, NMVP, FAQ, SAT, SQL, DNA, RNA, UOI, IOU, AM, PM, AD, BC, BCE, USA, UN, CF, ROFL, LOL, ETC
Property of The Thread

"Nobody knows the age of the human race, but everyone agrees it's old enough to know better." - Anon
subramanian22
subramanian22
SSC Rookie
SSC Rookie (27 reputation)SSC Rookie (27 reputation)SSC Rookie (27 reputation)SSC Rookie (27 reputation)SSC Rookie (27 reputation)SSC Rookie (27 reputation)SSC Rookie (27 reputation)SSC Rookie (27 reputation)

Group: General Forum Members
Points: 27 Visits: 3
I got it. Kingston explained well. thanks
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