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. created tables not dropped in a transaction rollback

created tables not dropped in a transaction rollback

Scheduled Pinned Locked Moved Database
databasehelpsql-serversysadminquestion
6 Posts 4 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
    Danzy83
    wrote on last edited by
    #1

    Hello experts. I have noticed something that is unfamiliar to me in my database knowledge. My application creates tables and inserts initial values into them based on user specifications. More than two tables are created in the process. The table creation and inserts are done within a transaction. When an error occurs, the transaction is rolled back. I just noticed that when the transaction is rolled back, all inserts are erased as expected. However, the tables created within the transaction are not dropped from the database. This is unusual to me. I don't know if I am missing something or that is how it happens with SQL server (2008 R2). Is there any way the tables can be dropped without specifying them one at a time in code? Please help.

    M L 3 Replies Last reply
    0
    • D Danzy83

      Hello experts. I have noticed something that is unfamiliar to me in my database knowledge. My application creates tables and inserts initial values into them based on user specifications. More than two tables are created in the process. The table creation and inserts are done within a transaction. When an error occurs, the transaction is rolled back. I just noticed that when the transaction is rolled back, all inserts are erased as expected. However, the tables created within the transaction are not dropped from the database. This is unusual to me. I don't know if I am missing something or that is how it happens with SQL server (2008 R2). Is there any way the tables can be dropped without specifying them one at a time in code? Please help.

      M Offline
      M Offline
      Mycroft Holmes
      wrote on last edited by
      #2

      Not something I have ever needed to do. However why is explicitly dropping the table and issue, you already trap the error and have a rollback simply add the test and drop in that trap.

      Never underestimate the power of human stupidity RAH

      1 Reply Last reply
      0
      • D Danzy83

        Hello experts. I have noticed something that is unfamiliar to me in my database knowledge. My application creates tables and inserts initial values into them based on user specifications. More than two tables are created in the process. The table creation and inserts are done within a transaction. When an error occurs, the transaction is rolled back. I just noticed that when the transaction is rolled back, all inserts are erased as expected. However, the tables created within the transaction are not dropped from the database. This is unusual to me. I don't know if I am missing something or that is how it happens with SQL server (2008 R2). Is there any way the tables can be dropped without specifying them one at a time in code? Please help.

        L Offline
        L Offline
        Lost User
        wrote on last edited by
        #3

        Similar to below? That would remove the created table (and does)

        BEGIN TRANSACTION

        CREATE TABLE Test (Id BIGINT)
        INSERT INTO Test (Id) VALUES (1)

        ROLLBACK

        SELECT *
        FROM information_schema.tables
        WHERE TABLE_NAME = 'Test'

        Danzy83 wrote:

        However, the tables created within the transaction are not dropped from the database. This is unusual to me.

        It'd be erroneous. Have you changed the locking-options? FWIW, it'd probably be the wisest to use a temp-table, not a real one.

        Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^] They hate us for our freedom![^]

        1 Reply Last reply
        0
        • D Danzy83

          Hello experts. I have noticed something that is unfamiliar to me in my database knowledge. My application creates tables and inserts initial values into them based on user specifications. More than two tables are created in the process. The table creation and inserts are done within a transaction. When an error occurs, the transaction is rolled back. I just noticed that when the transaction is rolled back, all inserts are erased as expected. However, the tables created within the transaction are not dropped from the database. This is unusual to me. I don't know if I am missing something or that is how it happens with SQL server (2008 R2). Is there any way the tables can be dropped without specifying them one at a time in code? Please help.

          L Offline
          L Offline
          Lost User
          wrote on last edited by
          #4

          In almost all database systems that I have worked with, DDL statements such as CREATE and DROP are not considered part of a transaction.

          J 1 Reply Last reply
          0
          • L Lost User

            In almost all database systems that I have worked with, DDL statements such as CREATE and DROP are not considered part of a transaction.

            J Offline
            J Offline
            jschell
            wrote on last edited by
            #5

            Shameel wrote:

            In almost all database systems that I have worked with, DDL statements such as CREATE and DROP are not considered part of a transaction.

            Yes but it appears that it is part of TSQL which is what the poster asked about.

            L 1 Reply Last reply
            0
            • J jschell

              Shameel wrote:

              In almost all database systems that I have worked with, DDL statements such as CREATE and DROP are not considered part of a transaction.

              Yes but it appears that it is part of TSQL which is what the poster asked about.

              L Offline
              L Offline
              Lost User
              wrote on last edited by
              #6

              Thanks for pointing out. I didn't know that unlike Oracle, DDL statements are transactional in SQL Server.

              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