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.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Index Help

Author  Topic 

jscot
Posting Yak Master

106 Posts

Posted - 2010-06-11 : 16:56:21
One question from all SQL Gurus!
Let say we have EMPLOYEE Table and Fields are
SSN#, EMPID, LNAME, FNAME
SSN# IS PRIMARY KEY
So Clustered index on SSN# right? Because Primary Key generate Clustered Index by default
and my query is
SELECT * FROM EMPLOYEE
WHERE EMPID BETWEEN 1 AND 10

This table carry Million record and we want to avoid table scan, What should we do?

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2010-06-11 : 16:58:43
For that query, yes you should index empid.

I would put the clustered index on empid and then add nonclustered indexes to those columns that are frequently used in where clauses.

Shouldn't empid be the PK? I would think SSN is just an employee attribute.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

jscot
Posting Yak Master

106 Posts

Posted - 2010-06-11 : 17:11:04
Tara this is just a question that i had in my mind. But i have one question "Cluster index sort the data row ASC AND DEC order right?
how about non clustered index? you know about "Natural Index"?

I appreciate your Help!!
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2010-06-11 : 17:21:49
A clustered index physically sorts the data on the disk. A nonclustered index only logically sorts it.

I think you mean natural key. You've got surrogate keys (like identities and other madeup keys) and natural keys (real data that makes it unique).

Sounds like a bunch of homework questions. Isn't this stuff covered in your class materials?

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

jscot
Posting Yak Master

106 Posts

Posted - 2010-06-11 : 17:53:01
Trying to refresh my memory!!! for Interview.
Go to Top of Page
   

- Advertisement -