我是新来的休眠对象,需要使用名为 channel_id 的表 channels 的外键为表 transactions 建立主键以及每个 channel_id 的自动生成的序列。
例如:
<!DOCTYPE HTML>
<html>
<head>
<style>
.sectionP
{
width:100px;
height:200px;
}
.section1,.section2,.section3,.section4
{
width:200px;
height:200px;
position:absolute;
}
.section3,.section4
{
z-index:10;
}
</style>
<script>
function allowDrop(ev) {
ev.preventDefault();
}
function drag(ev) {
ev.dataTransfer.setData("text", ev.target.id);
}
function drop(ev) {
ev.preventDefault();
var data = ev.dataTransfer.getData("text");
ev.target.appendChild(document.getElementById(data));
}
</script>
</head>
<body>
<h2>Drag and Drop</h2>
<p>Drag the image back and forth between the two div elements.</p>
<section id ="sectionP">
<section id = "section1">
<svg width="200" height="200" id="svg1">
<circle id="cir1" cx="100" cy="100" r="80"
stroke="green" stroke-width="4" fill="white">
</circle>
</svg>
</section>
<section class ="section3" width="200" height="200" ondrop="drop(event)" ondragover="allowDrop(event)"></section>
<section id = "section2">
<svg width="200" height="200" id="svg2">
<circle id="cir2" cx="100" cy="100" r="80"
stroke="yellow" stroke-width="4" fill="white">
</circle>
</svg>
</section>
<section class ="section4" width="200" height="200" ondrop="drop(event)" ondragover="allowDrop(event)"></section>
</section>
<section>
<img src="img_w3slogo.gif" draggable="true" ondragstart="drag(event)" id="drag1" width="88" height="31">
</section>
</body>
</html>
序列 transaction_id 应该从1开始并在同一 channel_id 内以1 递增:
TABLE channels {
channel_id
....Other channels fields
PK (channel_id)
}
TABLE transactions {
transaction_id
channel_id
...Other transactions fields
PK(transaction_id, channel_id)
FK(channel_id)
}
如果相关,我使用MySQL 8.0.17