我有一个查找表 ( ##lookup
)。我知道这是一个糟糕的设计,因为我在复制数据,但它极大地加快了我的查询速度。我有一个填充此表的查询
insert into ##lookup select distinct col1,col2,... from table1...join...etc...
我想模拟这种行为:
delete from ##lookup
insert into ##lookup select distinct col1,col2,... from table1...join...etc...
这将清楚地正确更新表。但这是很多插入和删除。它弄乱了我的索引并锁定了表格以供选择。
该表也可以通过以下方式更新:
delete from ##lookup where not in (select distinct col1,col2,... from table1...join...etc...)
insert into ##lookup (select distinct col1,col2,... from table1...join...etc...) except if it is already in the table
第二种方式可能需要更长的时间,但我可以说“没有锁”,我将能够从表中进行选择。
关于如何以第二种方式编写查询的任何想法?