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 to delete data from database

How to delete data from database

Scheduled Pinned Locked Moved Database
databasetutorial
8 Posts 6 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.
  • S Offline
    S Offline
    sarang_k
    wrote on last edited by
    #1

    Hi all, Can any one tell me how to delete the data from the database. Thanks in advance.

    D A N 3 Replies Last reply
    0
    • S sarang_k

      Hi all, Can any one tell me how to delete the data from the database. Thanks in advance.

      D Offline
      D Offline
      dan sh
      wrote on last edited by
      #2

      Whatever database you are using, it must be having a delete command. Use it.

      50-50-90 rule: Anytime I have a 50-50 chance of getting something right, there's a 90% probability I'll get it wrong...!!

      S 1 Reply Last reply
      0
      • D dan sh

        Whatever database you are using, it must be having a delete command. Use it.

        50-50-90 rule: Anytime I have a 50-50 chance of getting something right, there's a 90% probability I'll get it wrong...!!

        S Offline
        S Offline
        sarang_k
        wrote on last edited by
        #3

        i want to delete by using the query.

        D 1 Reply Last reply
        0
        • S sarang_k

          i want to delete by using the query.

          D Offline
          D Offline
          dan sh
          wrote on last edited by
          #4

          Why can't you google or use the help provided with database? This is so very trivial. Anyways, here you go (assuming you are using MS SQL):

          Delete from tableName where [whatever condition you want to use]

          50-50-90 rule: Anytime I have a 50-50 chance of getting something right, there's a 90% probability I'll get it wrong...!!

          1 Reply Last reply
          0
          • S sarang_k

            Hi all, Can any one tell me how to delete the data from the database. Thanks in advance.

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

            If you don't even know how to use help, should you even consider doing a delete? Unless you know what you are doing you can lose more data than expected.

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

            1 Reply Last reply
            0
            • S sarang_k

              Hi all, Can any one tell me how to delete the data from the database. Thanks in advance.

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

              I don't know your specific requirement, but I am giving certain situations. Let me know in case of any concern General syntax:

              DELETE FROM
              {table name | view name}
              [WHERE search_conditions]

              Note: Where clause is optional Case 1: Delete all rows from the table

              Delete from tablename

              Case 2: Delete based on a condition(Suppose I want to delete those employees from Employee table whose salaries are more than 50k)

              Delete from Employees
              where Salaries > 50000

              Case 3: If you want to drop your table issue

              DROP TABLE table_name

              Case 4: Though you have not asked, but if incase you need to truncate your table issue :

              Truncate Table table_name

              Case 5: If you want to delete duplicate records like Input:

              id name
              1 name1
              10 name1
              2 name2
              3 name3
              11 name3
              4 name4

              Output:

              id name
              1 name1
              2 name2
              3 name3
              4 name4

              Query:

              delete from tblname where id in
              (
              select id
              from(select ROW_NUMBER() over(partition by name order by name) rn,
              Id, name from tblname)X
              where rn <> 1
              )

              But your question title is

              sarang_k wrote:

              delete the data from the database

              Case 6: If that is suppose to be the case, the I presume you want to drop the database (:(don't know why?) However, the command is

              Drop DataBase database_name

              For more information please look into Deleting Data from an SQL Table Hope this helps :)

              Niladri Biswas

              M 1 Reply Last reply
              0
              • N Niladri_Biswas

                I don't know your specific requirement, but I am giving certain situations. Let me know in case of any concern General syntax:

                DELETE FROM
                {table name | view name}
                [WHERE search_conditions]

                Note: Where clause is optional Case 1: Delete all rows from the table

                Delete from tablename

                Case 2: Delete based on a condition(Suppose I want to delete those employees from Employee table whose salaries are more than 50k)

                Delete from Employees
                where Salaries > 50000

                Case 3: If you want to drop your table issue

                DROP TABLE table_name

                Case 4: Though you have not asked, but if incase you need to truncate your table issue :

                Truncate Table table_name

                Case 5: If you want to delete duplicate records like Input:

                id name
                1 name1
                10 name1
                2 name2
                3 name3
                11 name3
                4 name4

                Output:

                id name
                1 name1
                2 name2
                3 name3
                4 name4

                Query:

                delete from tblname where id in
                (
                select id
                from(select ROW_NUMBER() over(partition by name order by name) rn,
                Id, name from tblname)X
                where rn <> 1
                )

                But your question title is

                sarang_k wrote:

                delete the data from the database

                Case 6: If that is suppose to be the case, the I presume you want to drop the database (:(don't know why?) However, the command is

                Drop DataBase database_name

                For more information please look into Deleting Data from an SQL Table Hope this helps :)

                Niladri Biswas

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

                I'm not sure that was a good idea, you just handed a complete novice, someone who cannot even find the simplest help topic, the code to drop and truncate tables. Talk about overkill, still he will learn something about data if he uses some of that. When he comes back with "I can't truncate the table", you can try explaining foreign keys :laugh: :laugh: :laugh: .

                Never underestimate the power of human stupidity RAH

                J 1 Reply Last reply
                0
                • M Mycroft Holmes

                  I'm not sure that was a good idea, you just handed a complete novice, someone who cannot even find the simplest help topic, the code to drop and truncate tables. Talk about overkill, still he will learn something about data if he uses some of that. When he comes back with "I can't truncate the table", you can try explaining foreign keys :laugh: :laugh: :laugh: .

                  Never underestimate the power of human stupidity RAH

                  J Offline
                  J Offline
                  Jorgen Andersson
                  wrote on last edited by
                  #8

                  Mycroft Holmes wrote:

                  When he comes back with "I can't truncate the table", you can try explaining foreign keys

                  Or Cascade. ;P

                  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