postgresql数据库 多张表之间的多对多关系

CREATE TABLE IF NOT EXISTS public."Visit"
(
  "PatientID" character varying NOT NULL,
  "VisitNumber" character varying NOT NULL,
  "LabTestID" character varying NOT NULL,
  "LabTestName" character varying NOT NULL,
  "VisitDate" date  NOT NULL,
  "NumericalValue" double precision,
  "CategoricalValue" character varying,
  "Flags" character varying,
  
  CONSTRAINT "Visit_pkey" PRIMARY KEY ("PatientID", "VisitNumber", "LabTestID", "VisitDate")
);

------------------------------------------------------------
------------------------------------------------------------
CREATE TABLE IF NOT EXISTS public."Diagnosis"
(
  "PatientID" character varying NOT NULL,
  "VisitNumber" character varying NOT NULL,
  "VisitDate" date NOT NULL,

  "DiseaseID" character varying,
  "DiseaseName" character varying NOT NULL,

  CONSTRAINT "Diagnosis_pkey" PRIMARY KEY ("PatientID", "VisitNumber", "VisitDate")
);

------------------------------------------------------------
------------------------------------------------------------
CREATE TABLE IF NOT EXISTS public."LabTest"
(
  "LabTestID" character varying NOT NULL,
  "LabTestName" character varying NOT NULL,
  "Unit" character varying,
  "NormMin" double precision,
  "NormMax" double precision,
  
  CONSTRAINT "LabTest_pkey" PRIMARY KEY ("LabTestID"),
  CONSTRAINT "LabTest_ukey" UNIQUE ("LabTestName")
);

------------------------------------------------------------
------------------------------------------------------------
CREATE TABLE IF NOT EXISTS public."Disease"
(
  "DiseaseID" character varying NOT NULL,
  
  "DiseaseName" character varying NOT NULL,

  CONSTRAINT "Disease_pkey" PRIMARY KEY ("DiseaseID"),
  CONSTRAINT "Disease_ukey" UNIQUE ("DiseaseName")
);

------------------------------------------------------------
------------------------------------------------------------
ALTER TABLE public."Visit" ADD  CONSTRAINT "Visit_fkey_PatientID" FOREIGN KEY ("PatientID", "VisitNumber", "VisitDate") 
	REFERENCES public."Diagnosis" ("PatientID", "VisitNumber", "VisitDate");

ALTER TABLE public."Visit" ADD  CONSTRAINT "Visit_fkey" FOREIGN KEY ("LabTestID") 
	REFERENCES public."LabTest" ("LabTestID");
	
ALTER TABLE public."Diagnosis" ADD  CONSTRAINT "Diagnosis_fkey" FOREIGN KEY ("DiseaseID") 
	REFERENCES public."Disease" ("DiseaseID");




评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值