旗下导航:搜·么
当前位置:网站首页 > MySQL教程 > 正文

Mysq中l竖立测试父表、子表及测试用例归结总结【MySQL教程】,mysql

作者:搜教程发布时间:2019-12-01分类:MySQL教程浏览:61评论:0


导读:竖立测试表检察版本信息selectversion();5.7.22建立父表droptableifexistsModels;CREATETABLEM...

竖立测试表

检察版本信息

select version();
5.7.22

建立父表

drop table if exists Models;
CREATE TABLE Models
  (
    ModelID SMALLINT UNSIGNED NOT NULL AUTO_INCREMENT,
   Name VARCHAR(40) NOT NULL,
    PRIMARY KEY (ModelID)
);

建立子表

drop table if exists Orders;
CREATE TABLE Orders
  (
    ID          SMALLINT UNSIGNED NOT NULL PRIMARY KEY,
   ModelID     SMALLINT UNSIGNED NOT NULL,
     Description VARCHAR(40),
    FOREIGN KEY (ModelID) REFERENCES Models (ModelID)
      ON DELETE cascade
  );

测试

测试用例-无父表响应数据,先插进去子表

insert into Orders(Id,ModelID,Description) values (1,1,'a');

效果:实行失利
非常:[2018-07-31 11:08:01] 23000 Cannot add or update a child row: a foreign key constraint fails (bov.Orders, CONSTRAINT Orders_ibfk_1 FOREIGN KEY (ModelID) REFERENCES Models (ModelID) ON DELETE CASCADE)
缘由:通不过on delete cascade 的外键束缚搜检

测试用例-先插进去主表数据,再插进去子表数据

insert into Models(ModelID,Name) values (1,'a');
insert into Orders(Id,ModelID,Description) values (1,1,'a');

效果:实行胜利

select * from Models;
1    a

select * from Orders;
1    1    a

测试用例-父子表都有数据,删除子表数据

delete from Orders where id = 1;

效果:实行胜利

select * from Models;
1    a
select * from Orders;
为空

测试用例-父子表都有数据,删除父表书库

delete from Models where ModelID = 1;

效果:实行胜利

select * from Models;
为空
select * from Orders;
为空

测试用例-父子表都有数据,更新子表外键

update Orders set ModelID = 3 where ID =1;

效果:实行失利
非常:[2018-07-31 12:33:02] 23000 Cannot add or update a child row: a foreign key constraint fails (bov.Orders, CONSTRAINT Orders_ibfk_1 FOREIGN KEY (ModelID) REFERENCES Models (ModelID) ON DELETE CASCADE)
缘由:通不过on delete cascade 的外键束缚搜检

测试用例-父子表都有数据,更新父表主键

update Models set ModelID = 2 where ModelID =1;

效果:实行失利
非常:[2018-07-31 12:34:24] 23000 Cannot delete or update a parent row: a foreign key constraint fails (bov.Orders, CONSTRAINT Orders_ibfk_1 FOREIGN KEY (ModelID) REFERENCES Models (ModelID) ON DELETE CASCADE)
缘由:通不过on delete cascade 的外键束缚搜检

测试用例-父子表都有数据,更新子表非外键

update Orders set Description = 'b' where ID =1;

效果:实行胜利

select * from Orders;
1    1    b

测试用例-父子表都有数据,更新父表非主键

update Models set Name = 'c' where ModelID =1;

效果:实行胜利

select * from Models;
1    c

相干文章:

mysql数据库索引的竖立以及机能测试

mysql 高机能压力测试(总结了良久)

相干视频:

数据结构探险之线性表篇

以上就是Mysq中l竖立测试父表、子表及测试用例归结总结的细致内容,更多请关注ki4网别的相干文章!

标签:mysql


欢迎 发表评论: