| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 858 人关注过本帖
标题:向MYSQL中插入数据出问题了
只看楼主 加入收藏
david168520
Rank: 2
来 自:湖北
等 级:论坛游民
帖 子:227
专家分:50
注 册:2009-2-16
结帖率:100%
收藏
 问题点数:0 回复次数:0 
向MYSQL中插入数据出问题了
create table student(number varchar(10) not null primary key,name varchar(10) not null,loanNumber varchar(10),
ID varchar(20) not null,sex varchar(5) not null,birthday varchar(50) not null,enterSchoolTime varchar(50) not null,address varchar(50),
postID varchar(10) not null,telNumber varchar(15),class varchar(50),academy varchar(50),major varchar(20),
loanType int,loanAmount int,loanState varchar(10))TYPE=INNODB;这是学生信息表

create table loan(loanNumber varchar(10) ,name varchar(10) not null,number varchar(10) not null ,
applyLoanTime varchar(20) not null,
class varchar(50),academy varchar(50),major varchar(20),
loanType int,loanAmount int,loanState varchar(10),primary key(number,loanNumber))TYPE=INNODB;这是学生贷款信息表

create unique index index_loan on loan(loanNumber,name,number,class,academy,major,loanType,loanAmount,loanState);
create unique index index_student on student(loanNumber,name,number,class,academy,major,loanType,loanAmount,loanState);

alter table loan add FOREIGN KEY (loanNumber,name,number,class,academy,major,loanType,loanAmount,loanState)
REFERENCES student(loanNumber,name,number,class,academy,major,loanType,loanAmount,loanState)ON UPDATE CASCADE ON DELETE CASCADE;

以上是我创建的表:
我 在student表中插入了一行数据,我想修改loan表的loanNumber属性但是提示发生了SQLException异常,这是异常信息:Cannot add or update a child row: a foreign key constraint fails,本来我想利用级联属性来达到修改loan表中的属性进而可以自动的修改student表中的属性,但就是有问题,而删除一行loan表的记录可以,但student中对应的记录没删除,请问这是为什么,我不 是已经添加级联属性了嘛?
请各位高手们赐教,谢谢你们的帮助!
搜索更多相关主题的帖子: 数据 MYSQL 
2009-08-04 01:10
快速回复:向MYSQL中插入数据出问题了
数据加载中...
 
   



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

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