标题:MySQL 约束求教
只看楼主
心动音符
Rank: 1
等 级:禁止访问
威 望:1
帖 子:832
专家分:0
注 册:2005-9-15
 问题点数:0 回复次数:0 
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;
搜索更多相关主题的帖子: MySQL 
2006-12-23 15:54



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-111542-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.840831 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved