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)
 Many to Many relationship

Author  Topic 

jung1975
Aged Yak Warrior

503 Posts

Posted - 2010-05-13 : 15:38:42
what is the best way to improve query performance for m to m relatioship table ?

I have Fact/Diemsnions which has M-2-M relationship

Fact

Patid measures (amt)

1001

1002

1003



DiagnosisBridge

Patid Diagnosis_ID

1001 1

1001 2

1001 3

etc



Diagnosis Table

DiagnosisID DiagnosisCode

1 900.01

2 900.03

3 900.34

4 Etc…



I want to return the query aginst these table as quick as possible ...
what is the best way to optimize m to m relationship table structure .. so it returns the result quickly ?


dtecmeister
Starting Member

5 Posts

Posted - 2010-05-13 : 22:36:33
From your example data it looks like this is a one-to-many relationship followed by a one-to-one relationship. Ignoring that, you would want to add a bridge_id column and primary key followed by an index on Patid, an index on Diagnosis_ID, and a unique index on (Patid,Diagnosis_ID). I hope this helps and good luck.
Go to Top of Page
   

- Advertisement -