| 编程中国 | 业界新闻 | 技术文章 | 视频教程 | 下载频道 | 程序源码 | 个人空间 | 编程论坛
全能ASP/PHP/ASP.NET主机,支持月付专业 MSSQL 数据库空间,支持月付专业 MySQL 数据库空间,支持月付买域名,送MP3、MP4
高端软件开发 = 年薪十万不是梦赛孚耐:软件保护加密专家身份认证令牌USB KEY买空间,免费送域名(厦门中资源)
共有 1003 人关注过本帖
标题:MySQL 约束求教
收藏  订阅  推荐  打印 
心动音符
Rank: 4
等级:高级会员
威望:1
帖子:831
积分:8476
注册:2005-9-15
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
关于我们 | 广告合作 | 编程中国 | 清除Cookies | Archiver | WAP | TOP

编程中国 版权所有,并保留所有权利。鲁ICP备08000592号
Powered by Discuz, Processed in 0.045925 second(s), 9 queries.
Copyright©2004-2008, BCCN.NET, All Rights Reserved