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
 2 indexes -> 1 field ?

Author  Topic 

Billo
Starting Member

2 Posts

Posted - 2011-01-25 : 05:48:04
Hi guys,

I have a beginner question about how to create 2 indexes referencing to one field on an SQL table.
Basically I have 2 tables for 2 types of group (club and association, which btw cannot be combined in one). In a different table, I refer to those tables with 2 fields: groupID (ClubID or AssociationID)and grouptype ("club" or "association") and in the index, refer conditionally to one table or the other (basically GroupID is the one of a club or an association, depending on the value of grouptype). Is that even possible to do that? My fear is that I have to make some drastic changes on the whole database layout.






live fast, die young...

nigelrivett
Master Smack Fu Yak Hacker

3385 Posts

Posted - 2011-01-25 : 06:33:14
I take it the issue is creating foreign keys?
You can create an intereediate table to hold the possible values and a row type.
The club and association have FKs to this table.
On your referencing table you also have the rowtype and also have FKs to the new table.
It means inserting into the new table before insterting into club or assocuiation - might be better to not to include the FKs between these tables but use some other means.

Another option would be to maintain the integity via the application or triggers.

==========================================
Cursors are useful if you don't know sql.
SSIS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page

Billo
Starting Member

2 Posts

Posted - 2011-01-25 : 11:27:12
thanks for the reply. And what about to create an independant table without any FK but with 2 fields groupID and groupType that will contain all the groups created as a copy from the club and association tables ? would it be efficient ?

live fast, die young...
Go to Top of Page
   

- Advertisement -