Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Database & SysAdmin
  3. Database
  4. Transaction , rollback ..???

Transaction , rollback ..???

Scheduled Pinned Locked Moved Database
helpquestionannouncement
4 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    devboycpp
    wrote on last edited by
    #1

    In a transaction block if any error for insert or update occures (e.g. caused by foreign key-primary key constraint violation) does the transaction automatically rolls back or do we need to manually roll it back ?

    Best regards Hossein Yahoo ID :hosseinenick

    S E 2 Replies Last reply
    0
    • D devboycpp

      In a transaction block if any error for insert or update occures (e.g. caused by foreign key-primary key constraint violation) does the transaction automatically rolls back or do we need to manually roll it back ?

      Best regards Hossein Yahoo ID :hosseinenick

      S Offline
      S Offline
      squattyarun
      wrote on last edited by
      #2

      Syntax will go like this: Begin Try Begin Transaction --Your Line of code Commit Transaction End Try Begin Catch RollBack Transaction End Catch --Your line of code You will have to call commit or rollback for your transaction.....:-D

      D 1 Reply Last reply
      0
      • S squattyarun

        Syntax will go like this: Begin Try Begin Transaction --Your Line of code Commit Transaction End Try Begin Catch RollBack Transaction End Catch --Your line of code You will have to call commit or rollback for your transaction.....:-D

        D Offline
        D Offline
        devboycpp
        wrote on last edited by
        #3

        Does such syntax really exist ? I am using SQL Server 2000. and I get error when runnig such code.It doesn't know TRY keyword.

        Best regards Hossein Yahoo ID :hosseinenick

        1 Reply Last reply
        0
        • D devboycpp

          In a transaction block if any error for insert or update occures (e.g. caused by foreign key-primary key constraint violation) does the transaction automatically rolls back or do we need to manually roll it back ?

          Best regards Hossein Yahoo ID :hosseinenick

          E Offline
          E Offline
          Elina Blank
          wrote on last edited by
          #4

          It will rollBack "autopmatically" if you will say so. E.G. BEGIN TRAN your code if @@error <> 0 goto err -- more code if @@error <> 0 goto err At the end: commit tran return 1 err: rollback tran return 0

          Sincerely, Elina Life is great!!! Enjoy every moment of it! :-O

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups