如何检查表A是否为空?如果为空,如何将表B的内容插入表A? (它们是相同的)。如果表A为空,我想创建类似的东西:
INSERT INTO tableA
SELECT * FROM tableB
答案 0 :(得分:0)
您可以在NOT EXISTS
子句中使用WHERE
:
INSERT INTO tableA
SELECT * FROM tableB
WHERE NOT EXISTS (SELECT 1 FROM tableA)
或:
INSERT INTO tableA
SELECT * FROM tableB
WHERE (SELECT COUNT(*) FROM tableA) = 0