I got two 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?
Yes - you can ;-)
Just define all three foreign keys to refer to the id
column in User
.
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)
Alter Table call
ADD FOREIGN KEY (Sourceid) references Source(Id),
FOREIGN KEY (DesId) references Destination(Id)