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. Is Insert, Delete, Update already have transaction

Is Insert, Delete, Update already have transaction

Scheduled Pinned Locked Moved Database
helpquestionannouncement
6 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.
  • _ Offline
    _ Offline
    _J_
    wrote on last edited by
    #1

    Is Insert, Delete, Update already have transaction inside if yes how it help us and for what it ?? To study, study and only to study

    C 1 Reply Last reply
    0
    • _ _J_

      Is Insert, Delete, Update already have transaction inside if yes how it help us and for what it ?? To study, study and only to study

      C Offline
      C Offline
      Colin Angus Mackay
      wrote on last edited by
      #2

      _J_ wrote: Is Insert, Delete, Update already had transaction inside I'm not entirely sure what you are asking, however I am guessing you are asking: Are INSERT, DELETE and UPDATE statements wrapped in a transaction? Yes, and the SELECT statement too unless you wrap a sequence of these statements in a transaction. SQL Server will always wrap indiivdual statements in a transaction so that the statement can complete successfully and does not interfer with other queries or so other queries do not interfere with it. Does this help?


      My: Blog | Photos | Next SQL Presentation WDevs.com - Open Source Code Hosting, Blogs, FTP, Mail and More

      _ T 2 Replies Last reply
      0
      • C Colin Angus Mackay

        _J_ wrote: Is Insert, Delete, Update already had transaction inside I'm not entirely sure what you are asking, however I am guessing you are asking: Are INSERT, DELETE and UPDATE statements wrapped in a transaction? Yes, and the SELECT statement too unless you wrap a sequence of these statements in a transaction. SQL Server will always wrap indiivdual statements in a transaction so that the statement can complete successfully and does not interfer with other queries or so other queries do not interfere with it. Does this help?


        My: Blog | Photos | Next SQL Presentation WDevs.com - Open Source Code Hosting, Blogs, FTP, Mail and More

        _ Offline
        _ Offline
        _J_
        wrote on last edited by
        #3

        OK, thanks. So if i do deletion and 100% shure that more than one row will deleted should use a transaction as i now understood No. So i don't need to wrap it with my tranascation like : Begin TRAN DELETE ..... COMMIT To study, study and only to study

        C 1 Reply Last reply
        0
        • _ _J_

          OK, thanks. So if i do deletion and 100% shure that more than one row will deleted should use a transaction as i now understood No. So i don't need to wrap it with my tranascation like : Begin TRAN DELETE ..... COMMIT To study, study and only to study

          C Offline
          C Offline
          Colin Angus Mackay
          wrote on last edited by
          #4

          I'm not sure that you understood me. If you are doing one delete statement only then you don't need to explicitly wrap it in a transaction because SQL Server will do that for you. (NOTE: Other database products may vary) So DELETE MyTable WHERE SomeColumn='SomeValue' does not have to be wrapped in a transaction. It can delete 0, 1 or many rows. However, if you need to delete from, say, two separate tables at the same time you might want to use a transaction, so

          BEGIN TRANSACTION
          DELETE MyTable WHERE SomeColumn='SomeValue'
          DELETE MyOtherTable WHERE SomeOtherColumn='SomeOtherValue'
          COMMIT TRANSACTION

          Obviously, after each delete you may want to check for errors so that you can roll back a transaction if it fails. Does this help?


          My: Blog | Photos | Next SQL Presentation WDevs.com - Open Source Code Hosting, Blogs, FTP, Mail and More

          _ 1 Reply Last reply
          0
          • C Colin Angus Mackay

            I'm not sure that you understood me. If you are doing one delete statement only then you don't need to explicitly wrap it in a transaction because SQL Server will do that for you. (NOTE: Other database products may vary) So DELETE MyTable WHERE SomeColumn='SomeValue' does not have to be wrapped in a transaction. It can delete 0, 1 or many rows. However, if you need to delete from, say, two separate tables at the same time you might want to use a transaction, so

            BEGIN TRANSACTION
            DELETE MyTable WHERE SomeColumn='SomeValue'
            DELETE MyOtherTable WHERE SomeOtherColumn='SomeOtherValue'
            COMMIT TRANSACTION

            Obviously, after each delete you may want to check for errors so that you can roll back a transaction if it fails. Does this help?


            My: Blog | Photos | Next SQL Presentation WDevs.com - Open Source Code Hosting, Blogs, FTP, Mail and More

            _ Offline
            _ Offline
            _J_
            wrote on last edited by
            #5

            Thank u, u r the best. Now everything clear me, Thanks in advance I have another question to about transaction. Transacttion in stoe proc , in the begining i save @@TRANCOUNT to local variable (@tranCount) after this i start transaction (BEGIN TRANSACTION), i do my work ... .. maybe call to other store procs, .. .. and now before COMMIT or ROLLBACK i must to check my local variable (@tranCount) with @@TRANCOUNT ?? ------------------------------------ To study, study and only to study

            1 Reply Last reply
            0
            • C Colin Angus Mackay

              _J_ wrote: Is Insert, Delete, Update already had transaction inside I'm not entirely sure what you are asking, however I am guessing you are asking: Are INSERT, DELETE and UPDATE statements wrapped in a transaction? Yes, and the SELECT statement too unless you wrap a sequence of these statements in a transaction. SQL Server will always wrap indiivdual statements in a transaction so that the statement can complete successfully and does not interfer with other queries or so other queries do not interfere with it. Does this help?


              My: Blog | Photos | Next SQL Presentation WDevs.com - Open Source Code Hosting, Blogs, FTP, Mail and More

              T Offline
              T Offline
              turbochimp
              wrote on last edited by
              #6

              There are other potential transaction configurations, depending upon the database platform and the method of access. SQL Server runs, by default, in AutoCommit mode although it can be disabled, requiring explicit COMMIT or ROLLBACK calls. Oracle does not run in AutoCommit mode by default (in fact I have never determined if it can; I doubt it). Of course, neither of the above comments really matter if the developer is using a managed data provider, all of which (along with the underlying ODBC and OleDB layers) implement some form of AutoCommit heuristics as far as I know, forcing the behavior to act as you describe. I'm mainly making the distinction between exec'ing SQL at the command line versus through a managed provider, on different DB servers. Have a good weekend.

              The most exciting phrase to hear in science, the one that heralds the most discoveries, is not 'Eureka!' ('I found it!') but 'That's funny...’

              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