Subject | 2 Very simple index questions |
---|---|
Author | Vlad Orlovsky |
Post date | 2007-01-25T05:39:17Z |
Hi All,
I have 2 very basic questions about indexes.
1) Do I need to create a separate index for a column in a table that is a foreign key?
Ex:
ROLES table
ROLE_ID INTEGER -- PK
ROLE_NAME VARCHAR(50)
USERS table
USER_ID INTEGER -- PK
ROLE_ID INTEGER -- FK ?????
USER_NAME VARCHAR(50)
....
2) Which SELECT is faster(using above tables):
SELECT * FROM USERS WHERE USER_ID = 1 AND ROLE_ID =10
-- OR
SELECT * FROM USERS WHERE ROLE_ID =10 AND USER_ID = 1
I'm thinking of rewriting some SPs in our code, and it looks like there are 2 flavors of it...
Thanks again in advance,
Vlad
____________________________________________________________________________________
Expecting? Get great news right away with email Auto-Check.
Try the Yahoo! Mail Beta.
http://advision.webevents.yahoo.com/mailbeta/newmail_tools.html
[Non-text portions of this message have been removed]
I have 2 very basic questions about indexes.
1) Do I need to create a separate index for a column in a table that is a foreign key?
Ex:
ROLES table
ROLE_ID INTEGER -- PK
ROLE_NAME VARCHAR(50)
USERS table
USER_ID INTEGER -- PK
ROLE_ID INTEGER -- FK ?????
USER_NAME VARCHAR(50)
....
2) Which SELECT is faster(using above tables):
SELECT * FROM USERS WHERE USER_ID = 1 AND ROLE_ID =10
-- OR
SELECT * FROM USERS WHERE ROLE_ID =10 AND USER_ID = 1
I'm thinking of rewriting some SPs in our code, and it looks like there are 2 flavors of it...
Thanks again in advance,
Vlad
____________________________________________________________________________________
Expecting? Get great news right away with email Auto-Check.
Try the Yahoo! Mail Beta.
http://advision.webevents.yahoo.com/mailbeta/newmail_tools.html
[Non-text portions of this message have been removed]