1.在创建表格时就设置主键和外键
CREATE table employee2(
EmpId VARCHAR(10) PRIMARY KEY,
EmpName VARCHAR(20),
EmpPassword VARCHAR(32),
Gender VARCHAR(2),
BirthDate date,
EmpPic VARCHAR(50),
DeptId INT,
FOREIGN KEY (DeptId) REFERENCES Dept2 (DeptId)
)
1.在创建表格结束设置主键和外键
--设置主键
ALTER TABLE employee3 ADD PRIMARY KEY(EmpId)
--设置外键
ALTER TABLE employee3 ADD FOREIGN KEY(DeptId) REFERENCES Dept(DeptId)