create table department(
D_id char(9) primary key,
D_name varchar(10) unique,
aAddress varchar(20),
D_num smallint,
D_time datetime,
MW_id char(12),
foreign key (MW_id) references worker(W_id)
);
create table worker(
W_id char(12) primary key,
D_id char(9),
W_name varchar(10) not null,
W_sex char(2),
W_age smallint,
W_address varchar(50),
D_pid char(12),
foreign key(D_id) references department(D_id),
foreign key(D_pid) references worker(W_id)
);
解决办法:
方法一:建表时在外面使用外键应用
alter table shop_employee add constraint fk_shop_employee_shop_role
foreign key (shop_role_id) references shop_role (shop_role_id)
方法二:先创建表,再使用外键引用