• The idea for qotd is OK, but a script is too complicated to figure out the result within few minutes I'm willing to spend on it.

    There are a lot of mistakes, typos and non standard syntax.

    --***** tidy up part 1: drop the views and table created above *****

    delete dbo.tmp1 --missing "v" -ok, a typo

    go

    delete dbo.vtmp

    go

    delete dbo.tmp1

    --missing "go"

    Delete statement deletes data, does not drop the table/view.

    Standard syntax for delete statement is DELETE FROM Table. In transact-sql you can skip FROM keyword, but unless you plan to stick with mssql for the rest of your life, forget shortcuts and use standard syntax.

    SQL code should be as simple as possible. Meaning: avoid the chain logic if possible (A triggers B, which triggers C or A, which then triggers D). If not possible, at least document the logic with embedded comments.

    Hope you'll do better next time.