简体   繁体   English

MS SQL Server 2012自动增量和主/外键

[英]MS SQL Server 2012 Auto-Increment & Primary/Foreign Keys

I'm trying to see if the Primary/Foreign keys can be used in the following way in MS SQL server 2012. 我正在尝试查看是否可以以下列方式在MS SQL Server 2012中使用主键/外键。

If I have two tables one with employer information and one with recruiter information. 如果我有两张tables一张带有雇主信息,一张带有招聘者信息。

If any given employer can have up to 5 recruiter accounts, then in my table each time a new recruiter account is created with the employer's PK ID in a matching column on the Recruiters table and have a matching field on the recruiters table that has a count of the # of recruiter accounts that exist in the recruiters table. 如果任何给定的雇主最多可以拥有5个招聘者帐户,则每次在我的表中创建一个新的招聘者帐户,并在Recruiters表的匹配列中使用雇主的PK ID,并在招聘者表中具有一个具有计数的匹配字段招聘者表中存在的招聘者帐户数的百分比。

So 所以

Employers Table = A 雇主表= 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

Recruiters Table = B 招聘人员表= B

RecruiterID int Unchecked
EmployerID  int Checked
UserID  int Checked
AccountStatus   varchar(50) Checked
JobsPosted  int Checked
ResumeViews int Checked
ResumeFavorites int Checked

For each Recruiter that exists in table B auto-increment the value in Table A's Recruiters field. 对于表B中存在的每个Recruiter,自动递增表A的Recruiters字段中的值。

Is that proper use of primary/foreign keys? 是否正确使用了主/外键? Or should I be using TSQL to accomplish this? 还是应该使用TSQL来完成此任务?

I think you are missing the point of normalizing your database. 我认为您缺少规范化数据库的意义。

Let your employer data in the Employee and Recruiter data in the Recruiter and a EmployerRecruiterAccount table where 1 employer can have 5 recruiters. 让您的雇主数据在“招聘者”和“ EmployerRecruiterAccount”表的“雇员”和“招聘者”数据中,其中1个雇主可以有5个招聘者。

So your EmployerRecruiterAccount will have EmployeeID and RecruiterID as foreign keys. 因此,您的EmployerRecruiterAccount将使用EmployeeID和RecruiterID作为外键。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM