1. 首页 > 重庆网络营销 > 小潘杂谈 >

Mysq中l建立测试父表、子表及测试用例归纳总结

建立测试表查看版本信息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(IDSMALLINT UNSIGNED NOT NULL PRIMARY KEY,ModelIDSMALLINT 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;1aselect * from Orders;11a测试用例-父子表都有数据,删除子表数据delete from Orders where id = 1;结果:执行成功select * from Models;1aselect * 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;11b测试用例-父子表都有数据,更新父表非主键update Models set Name = 'c' where ModelID =1;结果:执行成功select * from Models;1c相关文章:

mysql数据库索引的建立以及性能测试

mysql 高性能压力测试(总结了好久)

相关视频:

数据结构探险之线性表篇以上就是Mysq中l建立测试父表、子表及测试用例归纳总结的详细内容,更多请关注小潘博客其它相关文章!

本文由重庆小潘seo博客网发布,不代表重庆小潘seo博客网立场,转载联系作者并注明出处:http://www.hkxiaopan.com/column/xiaopan/57996.html

联系我们

在线咨询:点击这里给我发消息

微信号:86345

工作日:9:30-18:30,节假日休息