patternsqlMinor
Can a column be referenced from multiple table as a foreign key
Viewed 0 times
canreferencedcolumnforeignmultiplefromtablekey
Problem
Suppose I have a table named
But I have other tables that have a similarities with that table
like
Can the
Service.But I have other tables that have a similarities with that table
like
RoomService, ConsultatonService, etc.Can the
Id of RoomService and ConsultationService keep a foreign key reference to Service table's ServiceId column but being identifiable by the Type column in the Service table?Solution
Yes, you can do it. Your
If you intend to avoid 1:1 relationships, you'll have to create, for example, an
In addition, the
services table will store all the common attributes between your sub-classes.If you intend to avoid 1:1 relationships, you'll have to create, for example, an
ServiceId column and do the relationship with it, using Id as PK of RoomService. By the way, there is no problems with 1:1 relationships, specially in your case, where you are creating specialized sub-classes.In addition, the
type column will be used by your application to determine which subclass the object is. Also no problem on that.Context
StackExchange Database Administrators Q#205171, answer score: 4
Revisions (0)
No revisions yet.