- 论坛徽章:
- 0
|
语法:
alter table tablename add FOREIGN KEY [id] (index_col_name, ...) REFERENCES tbl_name (index_col_name, ...).
示例:
a.建立数据库:Create database msg;
b.更改数据库:Use msg;
c.建立表LeaveMSG:Create table LeaveMSG(id int AUTO_INCREMENT primary key not null,author varchar(50),ldate varchar(20),msg text);
d.建立表ReplyMSG:Create table ReplyMSG(id int AUTO_INCREMENT primary key not null,lid int not null,rauthor varchar(50),rdate varchar(20),rmsg text);
e.建立外键关系:alter table replymsg add foreign key (lid) references leavemsg(id)
本文来自ChinaUnix博客,如果查看原文请点:http://blog.chinaunix.net/u1/43804/showart_407301.html |
|