为什么这个sql语句需要这么长时间?

时间:2014-01-27 12:12:06

标签: sql ms-access

我是Access的初学者。我写这个SQL语句:

INSERT INTO tbl_LaunchWeeklyPlan
IN 'C:\...\SomeDb.accdb'

SELECT ID, LaunchID, WeekYear, LaunchWeek, LaunchYear, Quantity, true AS IsActive 
FROM tbl_LaunchWeeklyPlan t 
WHERE t.ID NOT IN (SELECT ID 
FROM tbl_LaunchWeeklyPlan 
IN 'C:\...\SomeDb.accdb')

大约需要5分钟,表格中包含大约15 000条记录。

1 个答案:

答案 0 :(得分:2)

您可以尝试使用外部联接。这可以更快地执行。

INSERT INTO tbl_LaunchWeeklyPlan IN 'C:\...\SomeDb.accdb' 
SELECT ID, LaunchID, WeekYear, LaunchWeek, LaunchYear, Quantity, true AS IsActive FROM tbl_LaunchWeeklyPlan t
LEFT JOIN tbl_LaunchWeeklyPlan IN 'C:\...\SomeDb.accdb' f
ON t.ID = f.ID
WHERE f.ID = null