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
 General SQL Server Forums
 Database Design and Application Architecture
 Indexes on related tables...

Author  Topic 

iulianionescu
Starting Member

14 Posts

Posted - 2007-06-17 : 19:13:46
Hi,

I have 2 tables with this design: one has ArticleID as primary key and multiple other fields and one has GroupID as primary key and multiple other fields. Each article can belong in multiple groups so I created a new table called articleGroups with only 2 fields: ArticleID and GroupID to show the groups associated with each article. There is a relation between this table and each of the main 2 tables. My question is, in the articleGroup table, does it make any sense to create an Index on ArticleID, GroupID or both? Since the group is needed for each article the Groups will always be queried everytime the article is queried. So, I am not sure if an index is needed?

Thank you,


Regards,

Iulian

rmiao
Master Smack Fu Yak Hacker

7266 Posts

Posted - 2007-06-17 : 20:12:58
How big the third table will be?
Go to Top of Page

iulianionescu
Starting Member

14 Posts

Posted - 2007-06-18 : 11:15:30
Well, there are about 20 groups. So, let's say, for 500 articles, with an average of 3 groups per article, we are looking at no more than 1500 records. Let's say 2000...

Thank you,

Iulian

Regards,

Iulian
Go to Top of Page

rmiao
Master Smack Fu Yak Hacker

7266 Posts

Posted - 2007-06-18 : 15:54:12
I'll put indexes on the table.
Go to Top of Page

facestheband
Starting Member

6 Posts

Posted - 2007-07-05 : 00:33:07
I would actually do two things here.

1.) Create an Identity field seperate from the other two.
2.) Create an indexed based on the other two fields together.

Dewayne
Go to Top of Page

pootle_flump

1064 Posts

Posted - 2007-07-05 : 05:45:50
I would skip the identity if there are no attributes to the table and it does not participate in any further relationships.
ArticleID and GroupID should be a composite primary key in any case. SQL Server enforces this as a unique non-null index so your only choices are should it be clustered (yes) and which column do you want for the first column in the key?
Go to Top of Page
   

- Advertisement -