How a Insert works ?

  • Hi

    I just want to know how a INSERT statement works.

    For eg.

    In a Table that have Identity Column, Primary Key, Index, Default value, Check constraint, etc. If the user tries to insert a record, in what order the data will be validated and inserted into this table.

    If there is a trigger for this table, then how the trigger is executed.

    Pls. clarify me.

    Thanks

    Sathish

  • If the record violates the pk constraint, any of the fk constraints or any of the check constraints, it won't be inserted and the trigger, if any, won't fire.

    If the record passes all the checks, then it is inserted into the table (and the indexes, if any are updated to include the new record).

    The after triggers then fire, within the context of the transaction begin by inserting the row (if a transaction didn't already exist) After triggers can be executed in any order. After ann the triggers have completed then (assuming auto-commit mode) th insert is committed and the locks placed on the table for the insert are removed.

    Does that help?

    Gail Shaw
    Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
    SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

    We walk in the dark places no others will enter
    We stand on the bridge and no one may pass

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

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