Firebird SQL Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsDatabasesFirebird SQL Development

Closed Thread
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old February 7th, 2011, 07:13 AM
shibumathew shibumathew is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2011
Posts: 8 shibumathew User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 50 m 15 sec
Reputation Power: 0
Question How to select records using Index key in Firebird?

MS Compact SQL
----------------
1. Table creation

CREATE TABLE ProductsWIndex(ProductID int IDENTITY(1,1), ProductName nvarchar(50))

2. Create Index

CREATE INDEX index_productID ON ProductsWIndex (ProductID)

3. Select records using Index key

SELECT * FROM ProductsWIndex WITH (INDEX(index_productID)) WHERE ProductID < @ProductID



So please help me....how to select records in faster way using the Index 'index_productID' in Firebird SQL?

Reply With Quote
  #2  
Old February 7th, 2011, 10:58 AM
clivew clivew is offline
Contributing User
Dev Shed Regular (2000 - 2499 posts)
 
Join Date: Jan 2006
Location: Carlsbad, CA
Posts: 2,045 clivew User rank is Major (30000 - 40000 Reputation Level)clivew User rank is Major (30000 - 40000 Reputation Level)clivew User rank is Major (30000 - 40000 Reputation Level)clivew User rank is Major (30000 - 40000 Reputation Level)clivew User rank is Major (30000 - 40000 Reputation Level)clivew User rank is Major (30000 - 40000 Reputation Level)clivew User rank is Major (30000 - 40000 Reputation Level)clivew User rank is Major (30000 - 40000 Reputation Level)clivew User rank is Major (30000 - 40000 Reputation Level)clivew User rank is Major (30000 - 40000 Reputation Level) 
Time spent in forums: 1 Week 6 Days 2 h 37 m
Reputation Power: 382
Code:
SELECT * FROM ProductsWIndex 
WHERE ProductID < :ProductID

Firbird will use the PK without your help.

At the purest level, SQL is a declarative language.
That means you 'declare' what you want and the SQL server implementation decides how to fulfill it.

Last edited by clivew : February 7th, 2011 at 12:48 PM.

Reply With Quote
  #3  
Old February 7th, 2011, 07:42 PM
shibumathew shibumathew is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2011
Posts: 8 shibumathew User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 50 m 15 sec
Reputation Power: 0
Question

Thanks for your reply.

I have one small doubt.

Here while table creation i didn't set ProductID as Primary key.

So while executing SELECT * FROM ProductsWIndex
WHERE ProductID < :ProductID refers index_productID index table??

Please tell me how indexing is working in the above query?

Reply With Quote
  #4  
Old February 7th, 2011, 09:30 PM
clivew clivew is offline
Contributing User
Dev Shed Regular (2000 - 2499 posts)
 
Join Date: Jan 2006
Location: Carlsbad, CA
Posts: 2,045 clivew User rank is Major (30000 - 40000 Reputation Level)clivew User rank is Major (30000 - 40000 Reputation Level)clivew User rank is Major (30000 - 40000 Reputation Level)clivew User rank is Major (30000 - 40000 Reputation Level)clivew User rank is Major (30000 - 40000 Reputation Level)clivew User rank is Major (30000 - 40000 Reputation Level)clivew User rank is Major (30000 - 40000 Reputation Level)clivew User rank is Major (30000 - 40000 Reputation Level)clivew User rank is Major (30000 - 40000 Reputation Level)clivew User rank is Major (30000 - 40000 Reputation Level) 
Time spent in forums: 1 Week 6 Days 2 h 37 m
Reputation Power: 382
As long as the index exists it will be used provided the optimizer thinks it will be beneficial.

All SQL tables should have a PK defined. Either a natural PK or a surrogate one.

Reply With Quote
  #5  
Old February 7th, 2011, 11:48 PM
shibumathew shibumathew is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2011
Posts: 8 shibumathew User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 50 m 15 sec
Reputation Power: 0
Question

Thanks for your reply.

I tried with

SELECT * FROM ProductsWIndex WHERE ProductID < @ProductID PLAN (ProductsWIndex INDEX (index_productID))

Is the correct way of selecting records faster using Index key??

Reply With Quote
  #6  
Old February 8th, 2011, 12:42 PM
clivew clivew is offline
Contributing User
Dev Shed Regular (2000 - 2499 posts)
 
Join Date: Jan 2006
Location: Carlsbad, CA
Posts: 2,045 clivew User rank is Major (30000 - 40000 Reputation Level)clivew User rank is Major (30000 - 40000 Reputation Level)clivew User rank is Major (30000 - 40000 Reputation Level)clivew User rank is Major (30000 - 40000 Reputation Level)clivew User rank is Major (30000 - 40000 Reputation Level)clivew User rank is Major (30000 - 40000 Reputation Level)clivew User rank is Major (30000 - 40000 Reputation Level)clivew User rank is Major (30000 - 40000 Reputation Level)clivew User rank is Major (30000 - 40000 Reputation Level)clivew User rank is Major (30000 - 40000 Reputation Level) 
Time spent in forums: 1 Week 6 Days 2 h 37 m
Reputation Power: 382
I give up.
Perhaps someone more articulate than I can explain better.

Reply With Quote
  #7  
Old February 8th, 2011, 11:13 PM
shibumathew shibumathew is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2011
Posts: 8 shibumathew User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 50 m 15 sec
Reputation Power: 0
Thanks for your reply.

Reply With Quote
Closed Thread

Viewing: Dev Shed ForumsDatabasesFirebird SQL Development > How to select records using Index key in Firebird?

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap