我哪里错了?我收到错误150无法创建debit_card表。我知道的东西要做的事情,只是不知道到底是什么。帮助
create table customer(
cust_id int auto_increment,
first_name varchar(25),
last_name varchar(25),
street varchar(25),
city varchar(25),
state char(2),
zip varchar(10),
CONSTRAINT customer_pk primary key(cust_id)
);
create table card_account(
acct_no char(16),
exp_date date,
card_type ENUM("Debit","Credit") not null,
CONSTRAINT card_account_pk primary key(acct_no,exp_date)
);
create table debit_card(
bank_no char(9) not null,
acct_no char(16),
exp_date date,
CONSTRAINT debit_card_pk primary key(acct_no,exp_date),
CONSTRAINT debit_card_acct_no_fk foreign key(acct_no) references card_account(acct_no) on delete cascade,
CONSTRAINT debit_card_exp_date_fk foreign key(exp_date) references card_account(exp_date) on delete cascade
);
答案 0 :(得分:2)
您的card_account
表格中有composite primary key
。您不能在foreign key
约束中单独使用这些列。
但您可以添加foreign key
引用composite primary key
:
create table debit_card(
bank_no char(9) not null,
acct_no char(16),
exp_date date,
CONSTRAINT debit_card_pk primary key(acct_no,exp_date),
CONSTRAINT debit_card_acct_no_fk foreign key(acct_no,exp_date) references card_account(acct_no,exp_date) on delete cascade
);