Ronald writes "SQL SERVER: 2000 SP 3OS:Windows XP Pro SP 1Suppose i have two tables, SRC and DESTCREATE TABLE SRC( [PK] INT PRIMARY KEY, [GROUP] INT, [FLAG] BIT) CREATE TABLE DEST( [PK] INT PRIMARY KEY, [GROUP] INT, [FLAG] BIT)
Now, if i want to insert into table DEST all record from table SRC where SRC.GROUP = x and SRC.FLAG = 0, and then update all record from table SRC set SRC.FLAG = 1 where SRC.GROUP = x.The rule here is that there mustn't be any record in table DEST where DEST.GROUP = x and there mustn't be any record in table SRC where SRC.GROUP = x and SRC.FLAG = 1. Now my question:1. Is my query below an overkill with regard to the rule i state above (NOT EXISTS, can u suggest a better way) ?2. With the default transaction isolation level of SQL Server set to READ COMMITED, is my query below subject to the phantom reads problem ? if it it then what is the best way to solve it ?3. Can u explain to me the locking mechanism SQL Server used when executing the query below ?INSERT INTO DESTSELECT * FROM SRC WHERE SRC.GROUP = x AND SRC.FLAG = 0AND NOT EXISTS( SELECT * FROM SRC WHERE SRC.GROUP = x AND SRC.FLAG = 1)AND NOT EXISTS( SELECT * FROM DEST WHERE DEST.GROUP = x)UPDATE SRCSET SRC.FLAG = 1WHERE SRC.GROUP = x AND SRC.FLAG = 0AND NOT EXISTS( SELECT * FROM SRC WHERE SRC.GROUP = x AND SRC.FLAG = 1)
thanks in advanceRonald"