sql - doctor schedulering design SQL server
问题描述
Im trying to run this line of code to create a database to schedule doctor.
EmployeeID int primary key not null,
DPhone int not null,
DFirstName nvarchar (20) not null,
DLastName nvarchar (25) not null,
Specialization nvarchar (100) not null,
Cost int not null);
create table schedule(
DEmployeeID int not null, foreign key (DEmployeeID) references doctor (EmployeeID),
SDay nvarchar (9) not null,
SDate date not null,
STime time not null,
BookingStatus char not null,
primary key (DEmployeeID, SDate, STime),
PMedicalID int, foreign key (PMedicalID) references patient (MedicalID));
create table medRecords (
prescription nvarchar (100),
diagnosis nvarchar (100) not null,
Pdescription text not null,
medRecID int not null primary key,
MedicalID int, foreign key (MedicalID) references patient (MedicalID),
SDate date not null, foreign key (SDate) references schedule (SDate),
EmployeeID int not null, foreign key (EmployeeID) references doctor (EmployeeID))
This is the error
There are no primary or candidate keys in the referenced table 'Schedule' that match the referencing column list in the foreign key 'FK__MedRecord__SDate__3D5E1FD2'.
The Sdate is already a primary key so i don't understand why i get this error.
edit I already have a patiens table created
解决方案
推荐阅读
- python - 带有保持额外价值的条件的python格式选项
- react-native - 如何在本机反应中在浮动按钮上获得阴影
- operating-system - 列出在完全专用的机器上运行程序所必需的四个步骤——一台只运行该程序的计算机
- javascript - JS ES6 IIFE + 符号和原型 - 添加到实例?
- c# - 为什么 MySQL 返回在 C# 代码中始终为 1,但在存储过程中测试时却不是?
- python - 即使使用 __init__.py 文件,导入也不起作用
- python - 如何使用 opencv 操作将 `plt.imsave` 替换为 `cmap` 选项设置为 `gray`?
- java - 如何检查在 BottomNavigationView 中膨胀了哪个菜单文件?
- jquery - 如何通过按钮单击移动滚动?
- ruby - `+': Fracpri 不能被强制转换为 Fixnum (TypeError)