[英]How to create relationship between two non primary key entity in SQL Server
I have few tables where I need to link Patient card ID (PID) of table patient where primary key is patient_id with the PID field of other tables... how can I do that? 我有几个表需要链接主表为Patient_id的表Patient的患者卡ID(PID)与其他表的PID字段...我该怎么做? help!
救命!
You can use Foreign Keys 您可以使用外键
CREATE TABLE T
(
any_primary_key INT PRIMARY KEY,
[other attributes],
patient_id,
FOREIGN KEY (patiend_id) REFERENCES Patients.patient_id
)
Where Patients is a table that has the original patient_id
which has to be declared as unique
. 其中
patient_id
是具有原始patient_id
的表,必须将其声明为unique
。
you can join them like 你可以像这样加入他们
SELECT *
FROM [Patient] p
INNER JOIN [OtherTable] ot
ON p.pid = ot.patient_id;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.