我有一个数据库,它是从一个实用程序中填充的,它不能很好地处理同时请求。
在这些表中插入行的逻辑是有缺陷的,这允许派生表中的重复。我的目标是修复那些重复。
有两种类型的重复项:
情况如何出现
#history_table{
display:block;
position:relative;
background-color:#CCCCCC;
border:2px solid black;
margin-left: initial;
/*width:9px;*/
width:100%;
table-layout: fixed; /* Include this code */
}
#history_table td{
display:block;
}
这导致以下表格:
基
/** Sequence of events **/
/** First Set (Correct) **/
Insert into Base values(100,'Base1');
/** Find the biggest IKey in Base Table **/
/** Set that as IKey in Derived Table (IKey = 1)**/
Insert into Derived values(1,100,'Derived1');
Insert into Base values(101,'Base2');
/** Find the biggest IKey in Base Table **/
/** Set that as IKey in Derived Table (IKey = 2)**/
Insert into Derived values(2,101,'Derived2');
/** Second Set ( duplicate IKey )**/
Insert into Base values(200,'Base3');
/** Find the biggest IKey in Base Table **/
/** We would have gotten 3, but there was another insert before this query could be run **/
Insert into Base values(201,'Base4');
/** Because of the insert, we got a 4 instead of a 3 **/
/** Set that as IKey in Derived Table (IKey = 4)**/
Insert into Derived values(4,200,'Derived3');
/** Find the biggest IKey in Base Table **/
/** Set that as IKey in Derived Table (IKey = 4)**/
Insert into Derived values(4,201,'Derived4');
/** Third Set ( duplicate IKey and Number )**/
Insert into Base values(300,'Base5');
/** Find the biggest IKey in Base Table **/
/** We would have gotten 5, but there was another insert before this query could be run **/
/** This even had the "Number" column same as previous insert **/
Insert into Base values(300,'Base6');
/** Because of the insert, we got a 6 instead of a 5 **/
/** Set that as IKey in Derived Table (IKey = 6)**/
Insert into Derived values(6,300,'Derived5');
/** Find the biggest IKey in Base Table **/
/** Set that as IKey in Derived Table (IKey = 6)**/
Insert into Derived values(6,300,'Derived6');
派生
IKey Number Base
1 100 Base1
2 101 Base2
3 200 Base3
4 201 Base4
5 300 Base5
6 300 Base6
我已经能够找到案例#1的解决方案。
IKey Number Derived
1 100 Derived1
2 101 Derived2
4 200 Derived3
4 201 Derived4
6 300 Derived5
6 300 Derived6
我想找到#2的解决方案。
这是一个用于试验问题的工作空间。 http://sqlfiddle.com/#!3/e5f4e/4