mysql 外键约束举例

来源:互联网 发布:阿里妈妈淘宝客赚钱 编辑:程序博客网 时间:2024/05/14 04:47

废话少说,直接上代码:

create table policy 
(
    id int not null unique auto_increment primary key,
    name varchar(40) not null,
    description varchar(255)
);



create table policy_profit
(
    id int not null unique auto_increment primary key,
    policy_id INT not null,
     time char(40) not null,
    profit float not null
     
);

alter table policy_profit add CONSTRAINT C1 foreign key (policy_id) references policy(id) on delete CASCADE

0 0
原创粉丝点击