Я хотел бы выполнить следующие операции:
TRUNCATE TABLE Table1;
TRUNCATE TABLE Table2;
-- I do not want to allow possibly the viewing and definitely the modification
-- of Table1 or Table2 at this point, so that I can make changes to them atomically
-- possibly even regardless of the isolation level in other sessions (or this one).
-- So, I lock both tables. I want to remove any data that could have made its way into
-- the tables, due to the current isolation level, for example, and remove any rows.
-- Also, from this point on, I want the tables to be unviewable (all queries blocked)
-- and unmodifyable (all INSERTs, UPDATEs, DELETEs blocked)
DELETE FROM Table1 WITH(TABLOCKX, HOLDLOCK);
DELETE FROM Table2 WITH(TABLOCKX, HOLDLOCK);
-- This is a long running complex INSERT operation into Table1
INSERT INTO Table1... SELECT ...
-- This is a long running complex INSERT operation into Table2, based on the
-- data in Table1 and some other ancillary tables
INSERT INTO Table2... SELECT ... FROM Table1...
COMMIT;
Я хочу заблокировать весь доступ к обеим таблицам Table1
и Table2
с момента завершения выполнения команд TRUNCATE
доотметьте, что они полностью построены, а изменения зафиксированы с помощью COMMIT
.Предпочтительно, даже от клиентов, использующих уровень изоляции READ_UNCOMMITTED, и даже от тех, кто выполняет NOLOCK
запросов, если это возможно.
Буду признателен за любой совет.