views:

204

answers:

2

Hey guys,

I got 2 tables in my database: user and call. User exists of 3 fields: id, name, number and call : id, 'source', 'destination', 'referred', date.

I need to monitor calls in my app. The 3 ' ' fields above are actually userid numbers.

now i'm wondering, can i make those 3 field foreign key elements of the id-field in table user?

Thanks in advance...

+1  A: 

Yes - you can ;-)

Just define all three foreign keys to refer to the id column in User.

Stefan Gehrig
no violation of any guidelines/rules?
djerry
No - that's perfectly valid.
Stefan Gehrig
+1  A: 

Something alike should do the work:

ALTER TABLE call 
ADD CONSTRAINT fk_call_source_user FOREIGN KEY (source) 
REFERENCES user (id)

ALTER TABLE call 
ADD CONSTRAINT fk_call_destination_user FOREIGN KEY (destination) 
REFERENCES user (id) 

ALTER TABLE call 
ADD CONSTRAINT fk_call_referred_user FOREIGN KEY (referred) 
REFERENCES user (id)
Hueso Azul