更改表错误MS SQL

时间:2017-02-09 15:22:50

标签: sql sql-server

CREATE TABLE EMPLOYEES(
EmployeeNumber INT NOT NULL IDENTITY(1,1)
LastName Char(35)  NOT NULL,
FirstName CHAR(35)  NOT NULL,
Department CHAR(35) NOT NULL,
CONSTRAINT  EMPLOYEE_PK PRIMARY KEY(EmployeeNumber));

CREATE TABLE DEPARTMENT(
DepartmentName CHAR(35) NOT NULL,
Phone CHAR(35)  NOT NULL,
BudgetCode  CHAR(35) NOT NULL,
CONSTRAINT  DEP_PK  PRIMARY KEY(DepartmentName));

我忘了把一个部门作为员工的外键,所以我做了

ALTER TABLE EMPLOYEES ADD CONSTRAINT EMP_DEP_FK
  FOREIGN KEY(Department) REFERENCES DEPARTMENT(DepartmentName)

这告诉我:

  

ALTER TABLE语句与FOREIGN KEY约束冲突   " EMP_DEP_FK&#34 ;.冲突发生在数据库" WPC",表中   " dbo.DEPARTMENT",专栏' DepartmentName'。

1 个答案:

答案 0 :(得分:1)

您的DEPARTMENT表格中有拼写错误==>的 DepartmetnName

应该是DepartmentName。