Problems when using EXISTS in Delete Statements

  • In our database I have a table table1 which has unique id's with about 11Million records. I have another table table 2 with 2Million records with an id column. I am trying to delete all rows in table 1 that exists in table 2.

    Here is my query

    delete s

    from table1 S

    where exists (SELECT m.id FROM table2 m WITH(NOLOCK) where m.id= s.id)

    go

    After I run the query, for some reason I still see some records in table 1 which exists in table 2. This happens i guess randomly. And this query runs every day in my application. So I am trying to understand why this is happening. There are no null values in my tables.

    Please help.

    Thanks in advance

    CodezillatxtPost_CommentEmoticon(':hehe:');

  • WITH(NOLOCK)

    That won't help... you may be making the decision on whether or not to delete from table1 based on updates to table2 that may be rolled back

Viewing 2 posts - 1 through 1 (of 1 total)

You must be logged in to reply to this topic. Login to reply