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