I have to create a set of tables in SQL Server.
Those are:
chips
, for identifying a chip to be implanted to an animalsignals
, because every chip generates a signal once every hoursignal receivers
, stations which can receive a signal if a chip is in its radiussignal receivings
, for signals that have been received by a receiver
I have a problem in creating those tables.
This is my code:
CREATE TABLE CHIPS (
ID INT PRIMARY KEY,
...(not related attributes)...
);
CREATE TABLE RECEIVERS (
ID_receiver INT PRIMARY KEY,
...(some other attributes, not related to the problem)...
);
CREATE TABLE SIGNALS (
ID_chip INT FOREIGN KEY REFERENCES CHIPS,
Signal_no INT,
Date DATETIME,
PRIMARY KEY (ID_chip, Signal_no)
);
CREATE TABLE SIGNAL_RECEIVINGS (
ID_receiver INT REFERENCES RECEIVERS ,
Id_chip INT REFERENCES SIGNALS(ID_chip),
Signal_no INT REFERENCES SIGNALS(Signal_no),
PRIMARY KEY (Id_chip, Signal_no, ID_receiver )
);
My problem is that I don't know how to make a proper key for the SIGNAL_RECEIVERS
. I want it to be (Id_chip, Signal_no, ID_receiver)
because only then it would be unique, but SQL prints out an error :
The number of columns in the referencing column list for foreign key 'FK__SIGNAL_R__Si_no__5C187C73' does not match those of the primary key in the referenced table 'SIGNALS'.
Could someone help me out on this one?