MySQL 约束求教
MySQL 支持不支持约束啊 我下面写的为什么出错啊 大家来指点啊--add constraints
-- add primary key
alter table users add constraints users_id_pk primary key(id);
alter table user_infos add constraints user_infos_id_pk primary key(id);
alter table products add constraints products_id_pk primary key(id);
alter table orders add constraints orders_id_pk primary key(id);
alter table orderLines add constraints orderLines_id_pk primary key(id);
-- add foreign key
alter table user_infos add constraints user_info_id_fk foreign key(id) refencese users(id);
alter table orders add constraints orders_user_id_fk foreign key(user_id) refencese users(id);
alter table orderLines add constraints orderLines_order_id_fk foreign key(order_id) refencese orders(id);
alter table orderLines add constraints orderLines_product_id_fk foreign key(procudt_id) refencese product(id);
-- add uniue key
alter table users add constraints users_login_name unique(login_name);
alter table products add constraints products_code unique(code);
alter table orders add constraints orders_code unique(code);
-- add not null
alter table users modify login_name not null;
alter table procudts modify code not null;
alter table orders modify user_id not null;
alter table orders modify code not null;
alter table orderLines modify order_id not null;
alter table orderLines modify product_id not null;
-- add sequence
drop sequence my_key;
create sequence my_key;