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. General Programming
  3. C#
  4. Dropping multiple tables?

Dropping multiple tables?

Scheduled Pinned Locked Moved C#
databasehelpquestion
7 Posts 5 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.
  • E Offline
    E Offline
    Emmet_Brown
    wrote on last edited by
    #1

    Hi again I want to drop multiple tables from my database starting with the same name. I've tried this:

    SQLcommand = "DROP TABLE WHERE TABLE LIKE = 'a" + identity + "%'";
    SqlCeCommand sucuk = new SqlCeCommand(SQLcommand, conn);
    sucuk.ExecuteNonQuery();

    but it didn't work My tables start with an "a", and follows by an identity number, then a "year" I want to drop all the tables with the same identity, what can be the suitable solution can anybody help me please :( ?

    L P L 3 Replies Last reply
    0
    • E Emmet_Brown

      Hi again I want to drop multiple tables from my database starting with the same name. I've tried this:

      SQLcommand = "DROP TABLE WHERE TABLE LIKE = 'a" + identity + "%'";
      SqlCeCommand sucuk = new SqlCeCommand(SQLcommand, conn);
      sucuk.ExecuteNonQuery();

      but it didn't work My tables start with an "a", and follows by an identity number, then a "year" I want to drop all the tables with the same identity, what can be the suitable solution can anybody help me please :( ?

      L Offline
      L Offline
      Luc Pattyn
      wrote on last edited by
      #2

      Hi, why don't you look it up in the documentation? just type SQL and the keywords into Google. e.g. DROP TABLE in SQL[^], as you can see there is no WHERE clause. However in MySQL one can do "SHOW TABLES LIKE 'a%'" :)

      Luc Pattyn


      I only read code that is properly indented, and rendered in a non-proportional font; hint: use PRE tags in forum messages


      E 1 Reply Last reply
      0
      • L Luc Pattyn

        Hi, why don't you look it up in the documentation? just type SQL and the keywords into Google. e.g. DROP TABLE in SQL[^], as you can see there is no WHERE clause. However in MySQL one can do "SHOW TABLES LIKE 'a%'" :)

        Luc Pattyn


        I only read code that is properly indented, and rendered in a non-proportional font; hint: use PRE tags in forum messages


        E Offline
        E Offline
        Emmet_Brown
        wrote on last edited by
        #3

        ahah yeah you're right I've tried it and a few guys like me tried this WHERE clause I couldn't find a proper syntax for C# to drop multiple tables How can I use this "SHOW" ?

        L V 2 Replies Last reply
        0
        • E Emmet_Brown

          ahah yeah you're right I've tried it and a few guys like me tried this WHERE clause I couldn't find a proper syntax for C# to drop multiple tables How can I use this "SHOW" ?

          L Offline
          L Offline
          Luc Pattyn
          wrote on last edited by
          #4

          Emmet_Brown wrote:

          I couldn't find a proper syntax for C# to drop multiple tables

          There is no direct relation to C#, whatever programming language you choose, in the end you are sending strings of SQL commands.

          Emmet_Brown wrote:

          How can I use this "SHOW" ?

          I have already told you its all in the documentation, i.e. one Google search away. I suggest you get your act together. :)

          Luc Pattyn


          I only read code that is properly indented, and rendered in a non-proportional font; hint: use PRE tags in forum messages


          1 Reply Last reply
          0
          • E Emmet_Brown

            Hi again I want to drop multiple tables from my database starting with the same name. I've tried this:

            SQLcommand = "DROP TABLE WHERE TABLE LIKE = 'a" + identity + "%'";
            SqlCeCommand sucuk = new SqlCeCommand(SQLcommand, conn);
            sucuk.ExecuteNonQuery();

            but it didn't work My tables start with an "a", and follows by an identity number, then a "year" I want to drop all the tables with the same identity, what can be the suitable solution can anybody help me please :( ?

            P Offline
            P Offline
            PIEBALDconsult
            wrote on last edited by
            #5

            Take it to the General Database forum.

            1 Reply Last reply
            0
            • E Emmet_Brown

              ahah yeah you're right I've tried it and a few guys like me tried this WHERE clause I couldn't find a proper syntax for C# to drop multiple tables How can I use this "SHOW" ?

              V Offline
              V Offline
              Vikram A Punathambekar
              wrote on last edited by
              #6

              You can query sysobjects to find out which tables match your pattern. Then you have to issue a DROP TABLE command for each of them. As pointed out, this belongs more to the Database forum.

              Cheers, Vikram. (Cracked not one CCC, but two!)

              1 Reply Last reply
              0
              • E Emmet_Brown

                Hi again I want to drop multiple tables from my database starting with the same name. I've tried this:

                SQLcommand = "DROP TABLE WHERE TABLE LIKE = 'a" + identity + "%'";
                SqlCeCommand sucuk = new SqlCeCommand(SQLcommand, conn);
                sucuk.ExecuteNonQuery();

                but it didn't work My tables start with an "a", and follows by an identity number, then a "year" I want to drop all the tables with the same identity, what can be the suitable solution can anybody help me please :( ?

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

                Query the sys.objects (or sysobjects in older versions of SQL Server) to find out the list of tables you want to delete, loop over them, construct DROP TABLE XXX commands dynamically and execute them with the EXEC command.

                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