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. Difference between Delete and Truncate?

Difference between Delete and Truncate?

Scheduled Pinned Locked Moved Database
tutorialquestion
10 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.
  • G Offline
    G Offline
    ganeshMohan
    wrote on last edited by
    #1

    hai if anyone known the difference between the delete and truncate and please give me an example thanks in advance Ganesh Mohan

    J M S 3 Replies Last reply
    0
    • G ganeshMohan

      hai if anyone known the difference between the delete and truncate and please give me an example thanks in advance Ganesh Mohan

      J Offline
      J Offline
      John ph
      wrote on last edited by
      #2

      Delete and Truncate performs Identical tasks. but there are differences... Delete is a DML command used to delete a particular record or some set of Records based on the WHERE-Clause. And It can also Delete all the Records when there is no WHERE-Clause specified. The Delete operation performed using Delete Command can be Rolled Back. Truncate is a DDL Command used to delete all the Reocrds from the Table and also it Reinitializes the Table. Primary Key Identity values will be regenerated from the initial value for the subsequent entries after deleting all reocrds. WHERE-Clause can't be used in Truncate Command. The Delete operation performed using Truncate Command can't be Rolled Back. Truncate is much faster than Delete Note : Truncate = Delete + Commit

      Regards
      J O H N :rose:
      "Even eagles need a push." David McNally


      P K G 4 Replies Last reply
      0
      • J John ph

        Delete and Truncate performs Identical tasks. but there are differences... Delete is a DML command used to delete a particular record or some set of Records based on the WHERE-Clause. And It can also Delete all the Records when there is no WHERE-Clause specified. The Delete operation performed using Delete Command can be Rolled Back. Truncate is a DDL Command used to delete all the Reocrds from the Table and also it Reinitializes the Table. Primary Key Identity values will be regenerated from the initial value for the subsequent entries after deleting all reocrds. WHERE-Clause can't be used in Truncate Command. The Delete operation performed using Truncate Command can't be Rolled Back. Truncate is much faster than Delete Note : Truncate = Delete + Commit

        Regards
        J O H N :rose:
        "Even eagles need a push." David McNally


        P Offline
        P Offline
        Pete OHanlon
        wrote on last edited by
        #3

        Good answer. Get's a 5 for its clarity and completeness.

        Deja View - the feeling that you've seen this post before.

        J 1 Reply Last reply
        0
        • P Pete OHanlon

          Good answer. Get's a 5 for its clarity and completeness.

          Deja View - the feeling that you've seen this post before.

          J Offline
          J Offline
          John ph
          wrote on last edited by
          #4

          Thanks Pete.

          Regards
          J O H N :rose:
          "Even eagles need a push." David McNally


          P 1 Reply Last reply
          0
          • J John ph

            Thanks Pete.

            Regards
            J O H N :rose:
            "Even eagles need a push." David McNally


            P Offline
            P Offline
            Pete OHanlon
            wrote on last edited by
            #5

            You're welcome. It's always a pleasure to read a detailed and accurate answer.

            Deja View - the feeling that you've seen this post before.

            1 Reply Last reply
            0
            • G ganeshMohan

              hai if anyone known the difference between the delete and truncate and please give me an example thanks in advance Ganesh Mohan

              M Offline
              M Offline
              Mike Dimmick
              wrote on last edited by
              #6

              One other difference is that the user doing the TRUNCATE must have greater permissions than doing a DELETE. DELETE permissions can be granted to a user or role on a per-table basis; on SQL Server 2000, TRUNCATE permissions are only granted to the owner of the table, members of the sysadmin server role, and members of the db_owner or db_ddladmin fixed server roles. SQL Server 2005's documentation is a little unclear, it says that the user must have ALTER permissions on the table but then repeats the sentence from SQL Server 2000 Books Online. Obviously if you're connecting to SQL Server using sa or a trusted connection (Windows authentication) using an administrator account, you have those permissions. However, this is not a good practice as those accounts have full control over the entire database server, and as such, a mistake in your application logic could lead to accidental, or even deliberate, damage. In my view, you should firewall what an application can do by setting up less-privileged server logins and database users.


              DoEvents: Generating unexpected recursion since 1991

              1 Reply Last reply
              0
              • J John ph

                Delete and Truncate performs Identical tasks. but there are differences... Delete is a DML command used to delete a particular record or some set of Records based on the WHERE-Clause. And It can also Delete all the Records when there is no WHERE-Clause specified. The Delete operation performed using Delete Command can be Rolled Back. Truncate is a DDL Command used to delete all the Reocrds from the Table and also it Reinitializes the Table. Primary Key Identity values will be regenerated from the initial value for the subsequent entries after deleting all reocrds. WHERE-Clause can't be used in Truncate Command. The Delete operation performed using Truncate Command can't be Rolled Back. Truncate is much faster than Delete Note : Truncate = Delete + Commit

                Regards
                J O H N :rose:
                "Even eagles need a push." David McNally


                K Offline
                K Offline
                kubben
                wrote on last edited by
                #7

                I think one other difference is that Delete is logged and truncate is not. Thus the ability to roll back etc. That is also part of the reason that truncate is faster. Ben

                1 Reply Last reply
                0
                • J John ph

                  Delete and Truncate performs Identical tasks. but there are differences... Delete is a DML command used to delete a particular record or some set of Records based on the WHERE-Clause. And It can also Delete all the Records when there is no WHERE-Clause specified. The Delete operation performed using Delete Command can be Rolled Back. Truncate is a DDL Command used to delete all the Reocrds from the Table and also it Reinitializes the Table. Primary Key Identity values will be regenerated from the initial value for the subsequent entries after deleting all reocrds. WHERE-Clause can't be used in Truncate Command. The Delete operation performed using Truncate Command can't be Rolled Back. Truncate is much faster than Delete Note : Truncate = Delete + Commit

                  Regards
                  J O H N :rose:
                  "Even eagles need a push." David McNally


                  K Offline
                  K Offline
                  kubben
                  wrote on last edited by
                  #8

                  Ok so I guess part of it is logged. I had to look it up. The DELETE statement removes rows one at a time and records an entry in the transaction log for each deleted row. TRUNCATE TABLE removes the data by deallocating the data pages used to store the table's data, and only the page deallocations are recorded in the transaction log. Ben

                  1 Reply Last reply
                  0
                  • J John ph

                    Delete and Truncate performs Identical tasks. but there are differences... Delete is a DML command used to delete a particular record or some set of Records based on the WHERE-Clause. And It can also Delete all the Records when there is no WHERE-Clause specified. The Delete operation performed using Delete Command can be Rolled Back. Truncate is a DDL Command used to delete all the Reocrds from the Table and also it Reinitializes the Table. Primary Key Identity values will be regenerated from the initial value for the subsequent entries after deleting all reocrds. WHERE-Clause can't be used in Truncate Command. The Delete operation performed using Truncate Command can't be Rolled Back. Truncate is much faster than Delete Note : Truncate = Delete + Commit

                    Regards
                    J O H N :rose:
                    "Even eagles need a push." David McNally


                    G Offline
                    G Offline
                    ganeshMohan
                    wrote on last edited by
                    #9

                    Thanks John

                    1 Reply Last reply
                    0
                    • G ganeshMohan

                      hai if anyone known the difference between the delete and truncate and please give me an example thanks in advance Ganesh Mohan

                      S Offline
                      S Offline
                      Sathesh Sakthivel
                      wrote on last edited by
                      #10

                      Delete - delete deletes the records from table it can be rollbacked also you can give the where condiition to it. Truncate - delete all records from table There is no rollback it always commit without givening the commit.

                      SSK. Anyone who says sunshine brings happiness has never danced in the rain.

                      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