T-SQL and transaction flow - from first to last

前端 未结 3 1415
说谎
说谎 2021-01-07 13:33

Let\'s say I have table TabA with columns:

  • col1 - primary key (but not identity)

  • col2 - foreign key

  • col3 -

3条回答
  •  春和景丽
    2021-01-07 13:50

    This is easy to test by setting up test tables as described with print statements in the triggers and simply trying to insert invalid values.

    Of course, I did it! And agree with you - get the same result from 1 to 8. And what is embarrass for me is the quote from "Microsoft SQL Server 2008 Bible" book (by Paul Nielsen). That is (on page 637):

    Every transaction moves through the various checks and code in the following order:

    1. IDENTITY INSERT check
    2. Nullability constraint
    3. Data-type check
    4. INSTEAD OF trigger execution. If an INSTEAD OF trigger exists, then execution of the DML stops here. INSTEAD OF triggers are not recursive. Therefore, if the INSERT trigger executes another DML command, then the INSTEAD OF trigger will be ignored the second time around (recursive triggers are covered later in this chapter).
    5. Primary-key constraint
    6. Check constraints
    7. Foreign-key constraint
    8. DML execution and update to the transaction log
    9. AFTER trigger execution
    10. Commit transaction

    So, as you see, this IT-Pro disagree with you and me. He, for example, give INSTEAD OF trigger number 4 whereas we give to it number 1. This quote just baffle me!

提交回复
热议问题