一、“插入强制约束”、“级联删除”、“级联更新” 

 

user表:
create table user
(
userid integer not null auto_increment primary key,
username varchar(12) not null
)
type=innodb;

经多次尝试,终于看到了与MS SQL 中一样的效果了:

“插入强制约束”、“级联删除”、“级联更新” 

主要是在建password表的时候,对userid列要加 index,即:
create table password
(
userid integer not null,
password varchar(12) not null,
index (userid),
foreign key (userid) references user (userid)
on delete cascade
on update cascade
) type=InnoDB;


即可

sum-up:

1、MySQL支持外键约束,并提供与其它DB相同的功能,但表类型必须为 InnoDB
2、建外键的表的那个列要加上index.


二、让4.0以下版本支持事务处理
在my.ini文件的[mysqld]里面加上一句就可以了

innodb_data_file_path = ibdata1:10M:autoextend