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.
| Author |
Topic |
|
basicconfiguration
Constraint Violating Yak Guru
358 Posts |
Posted - 2009-09-04 : 13:41:11
|
| drop table encountergodrop table patientgodrop table appointment gocreate table patient (patientID int primary key identity(1,1), patientName varchar(50), clientID int)create table encounter (encounterID int primary key identity(1,1), EncounterName varchar(50), hospitalID int, PatientID int references patient(PatientID))create table appointment (appointmentID int primary key identity(1,1), HospitalID int, appointmentDate datetime )insert patientselect 'FeeFee', 100 union allselect 'Max', 100 union allselect 'Bones', 100 union allselect 'Fort', 100 insert encounterselect 'Enc - Daniel', 10, 1 union allselect 'Enc - Jose', 10, 2 union allselect 'Enc - Mary', 11, 3 union allselect 'Enc - Luis', 11, 4 insert appointmentselect 12, getdate()-5 union allselect 1, getdate()-3 union allselect 10, getdate()-10select * from patientselect * from encounterselect * from appointment/*select a.hospitalid, a.appointmentDate, a.appointmentidfrom appointment ajoin encounter bon a.hospitalID = b.hospitalIDjoin patient con c.patientid = b.patientid |
|
|
Lamprey
Master Smack Fu Yak Hacker
4614 Posts |
Posted - 2009-09-04 : 13:43:07
|
| I commend you for providing DDL and sample data, but is there a question? |
 |
|
|
basicconfiguration
Constraint Violating Yak Guru
358 Posts |
Posted - 2009-09-04 : 14:03:52
|
| oh sorry. when u look at the execution plan. there is a clustered index scan. I like to know how to get rid of it to improve performance. Thanks |
 |
|
|
robvolk
Most Valuable Yak
15732 Posts |
Posted - 2009-09-04 : 14:23:43
|
| 1. Without a WHERE clause, you'll get a clustered scan since it will need to return all rows. 2. You are also returning all columns from the table. If it had done a seek, it would need to do an additional bookmark lookup. The scan would be more efficient3. Why are you assuming the clustered scan performs poorly? Have you tested query hints that provide better performance? |
 |
|
|
basicconfiguration
Constraint Violating Yak Guru
358 Posts |
Posted - 2009-09-09 : 11:30:50
|
| i read query hints are bad for performance. |
 |
|
|
Pradip
Starting Member
32 Posts |
Posted - 2009-11-17 : 06:50:12
|
| You can add non-clustered index on hospitalid. It will change your hash match to Nested loop.www.silicus.compradipjain |
 |
|
|
russell
Pyro-ma-ni-yak
5072 Posts |
Posted - 2009-11-17 : 08:41:03
|
| with 4 records in the table you should expect a scan |
 |
|
|
|
|
|
|
|