我正在尝试查看主键/外键是否可以在MS SQL server 2012中以以下方式使用。
如果我有两个tables
,一个包含雇主信息,另一个包含招聘人员信息。
如果任何给定雇主最多可以有5个招聘人员帐户,则在我的表中,每次创建新的招聘人员帐户时,都会在“招聘人员”表的匹配列中使用该雇主的主键ID创建新的招聘人员帐户,并且在“招聘人员”表中有一个匹配字段,其中包含存在于“招聘人员”表中的招聘人员帐户的数量。
所以
雇主表=A
EmployerID int Unchecked
UserID int Checked
AccountStatus varchar(50) Checked
CompanyName varchar(150) Checked
JobsPosted int Checked
ResumeViews int Checked
ResumeFavorites int Checked
Recruiters int Checked
招聘人表=B
RecruiterID int Unchecked
EmployerID int Checked
UserID int Checked
AccountStatus varchar(50) Checked
JobsPosted int Checked
ResumeViews int Checked
ResumeFavorites int Checked
对于表B中存在的每个招聘人员,自动递增表A的Recruiters
字段中的值。
主键/外键的使用是否正确?或者我应该使用TSQL来实现这一点?
发布于 2017-03-16 10:23:46
我认为你错过了规范化你的数据库的要点。
让您的雇主数据包含在招聘人员和EmployerRecruiterAccount表中的员工和招聘人员数据中,其中一个雇主可以有5个招聘人员。
因此,您的EmployerRecruiterAccount将使用EmployeeID和RecruiterID作为外键。
https://stackoverflow.com/questions/42824172
复制相似问题