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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. Database & SysAdmin
  3. Database
  4. How can we Empty the whole tables by one single query

How can we Empty the whole tables by one single query

Scheduled Pinned Locked Moved Database
database
12 Posts 7 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.
  • L lrsalunkhe

    Respected, How can we truncate the whole tables value from my DataBase by single query. Thanks

    N Offline
    N Offline
    Niladri_Biswas
    wrote on last edited by
    #2

    truncate table tblName :)

    Niladri Biswas

    1 Reply Last reply
    0
    • L lrsalunkhe

      Respected, How can we truncate the whole tables value from my DataBase by single query. Thanks

      D Offline
      D Offline
      David Mujica
      wrote on last edited by
      #3

      Drop database: The DROP DATABASE statement is used to delete a database. Everything is deleted ... tables, views, indexes, stored procedures, etc Drop Table: The DROP TABLE statement is used to delete a table. Truncate Table: Delete the data inside the table, and not the table itself Use this as reference: http://www.w3schools.com/SQl/sql_drop.asp[^]

      L 1 Reply Last reply
      0
      • D David Mujica

        Drop database: The DROP DATABASE statement is used to delete a database. Everything is deleted ... tables, views, indexes, stored procedures, etc Drop Table: The DROP TABLE statement is used to delete a table. Truncate Table: Delete the data inside the table, and not the table itself Use this as reference: http://www.w3schools.com/SQl/sql_drop.asp[^]

        L Offline
        L Offline
        lrsalunkhe
        wrote on last edited by
        #4

        Respected, But I have given the Relations to Tables. Thanks.

        _ N 2 Replies Last reply
        0
        • L lrsalunkhe

          Respected, But I have given the Relations to Tables. Thanks.

          _ Offline
          _ Offline
          _Damian S_
          wrote on last edited by
          #5

          Then do it one table at at time, starting from the leaf tables... eg: Persons have one or more Addresses. Delete Addresses first, then Persons.

          I don't have ADHD, I have ADOS... Attention Deficit oooh SHINY!! Booger Mobile (n) - A bright green 1964 Ford Falcon - our entry into the Camp Quality esCarpade!! Do something wonderful - make a donation to Camp Quality today!!

          1 Reply Last reply
          0
          • L lrsalunkhe

            Respected, But I have given the Relations to Tables. Thanks.

            N Offline
            N Offline
            Niladri_Biswas
            wrote on last edited by
            #6

            You could have specified that in the post.. How can one come to know that you want to perform a CASCADE DELETION ? e.g.

            CREATE TABLE tblPK
            ( id int primary key )

            CREATE TABLE tblFK
            (id int,
            name varchar(50),
            age int
            FOREIGN KEY (id) REFERENCES tblPK ON DELETE CASCADE)

            :)

            Niladri Biswas

            modified on Wednesday, November 4, 2009 12:51 AM

            M 1 Reply Last reply
            0
            • N Niladri_Biswas

              You could have specified that in the post.. How can one come to know that you want to perform a CASCADE DELETION ? e.g.

              CREATE TABLE tblPK
              ( id int primary key )

              CREATE TABLE tblFK
              (id int,
              name varchar(50),
              age int
              FOREIGN KEY (id) REFERENCES tblPK ON DELETE CASCADE)

              :)

              Niladri Biswas

              modified on Wednesday, November 4, 2009 12:51 AM

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

              In 20+ years of database design and development I've never actually used cascade delete, I wonder why!

              _ A 2 Replies Last reply
              0
              • M Mycroft Holmes

                In 20+ years of database design and development I've never actually used cascade delete, I wonder why!

                _ Offline
                _ Offline
                _Damian S_
                wrote on last edited by
                #8

                Mycroft Holmes wrote:

                I wonder why!

                Because you are scared of it? :laugh:

                I don't have ADHD, I have ADOS... Attention Deficit oooh SHINY!! Booger Mobile (n) - A bright green 1964 Ford Falcon - our entry into the Camp Quality esCarpade!! Do something wonderful - make a donation to Camp Quality today!!

                M 1 Reply Last reply
                0
                • _ _Damian S_

                  Mycroft Holmes wrote:

                  I wonder why!

                  Because you are scared of it? :laugh:

                  I don't have ADHD, I have ADOS... Attention Deficit oooh SHINY!! Booger Mobile (n) - A bright green 1964 Ford Falcon - our entry into the Camp Quality esCarpade!! Do something wonderful - make a donation to Camp Quality today!!

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

                  I always envisage someone going to the settings table and using cascade delete on the Standard Customer record or something. Scared does not even cover it, terrified is closer.

                  _ J 2 Replies Last reply
                  0
                  • M Mycroft Holmes

                    I always envisage someone going to the settings table and using cascade delete on the Standard Customer record or something. Scared does not even cover it, terrified is closer.

                    _ Offline
                    _ Offline
                    _Damian S_
                    wrote on last edited by
                    #10

                    Meh... don't let users have access to the tables... have a good backup strategy!! ;-)

                    I don't have ADHD, I have ADOS... Attention Deficit oooh SHINY!! Booger Mobile (n) - A bright green 1964 Ford Falcon - our entry into the Camp Quality esCarpade!! Do something wonderful - make a donation to Camp Quality today!!

                    1 Reply Last reply
                    0
                    • M Mycroft Holmes

                      I always envisage someone going to the settings table and using cascade delete on the Standard Customer record or something. Scared does not even cover it, terrified is closer.

                      J Offline
                      J Offline
                      J4amieC
                      wrote on last edited by
                      #11

                      Thats even the worst side effect. Imagine a header table with, lets say, 1000 records in it. Each header has 100,000 (badly indexed) child records. Cascade delete is turned on. Someone comes along and says "Ah header table only has 1000 rows, it will be easy to delete a record from there". Database reduced to treacle.

                      1 Reply Last reply
                      0
                      • M Mycroft Holmes

                        In 20+ years of database design and development I've never actually used cascade delete, I wonder why!

                        A Offline
                        A Offline
                        Ashfield
                        wrote on last edited by
                        #12

                        Probably for the same reason as I haven't - we are control freaks who like to explicitly delete things when we want to, not sudenly finding it happening 'on its own' :)

                        Bob Ashfield Consultants Ltd Proud to be a 2009 Code Project MVP

                        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