短的
我的表格结构看起来像这样
这是 Sql 语句
$stmt = $this->db->prepare("DELETE FROM chapters WHERE (subject_id=? AND id = ?)") or die($this->db->error());
$stmt->bind_param("ii", $subject_id, $node);
$stmt->execute();
$stmt = $this->db->prepare("DELETE FROM sections WHERE (subject_id=? AND chapter_id=? )") or die($this->db->error());
$stmt->bind_param("ii", $subject_id, $node);
$stmt->execute();
$stmt = $this->db->prepare("DELETE FROM paragraphs WHERE (subject_id=? AND chapter_id=?)") or die($this->db->error());
$stmt->bind_param("ii", $subject_id, $node);
$stmt->execute();
所以我想做的是,merge
把这3条语句合二为一,优化服务器负载。
详细的
例如,如果我想从chapters
表中删除 id=1 的行,那么还要从另外 2 个表中删除:sections
,paragraphs
通过 2 个参数:$node
和$subject_id
(当然,如果有这些参数的行。我的意思是必须加入防止任何错误)。
问题是..
那可能吗?我不知道,sql语句必须是什么样子。有什么建议么?