1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

How to delete all table's data

Discussion in 'Databases' started by getbestproduct, Dec 23, 2010.

  1. #1
    How to delete all table's data
     
    getbestproduct, Dec 23, 2010 IP
  2. plog

    plog Peon

    Messages:
    298
    Likes Received:
    11
    Best Answers:
    1
    Trophy Points:
    0
    #2
    Assuming you know how to use an apostrophe:

    TRUNCATE TABLE your_table_name_here; 
    PHP:
     
    plog, Dec 23, 2010 IP
  3. christyzulueta

    christyzulueta Peon

    Messages:
    10
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    SQL code: you can use DELETE from yourtablename
     
    christyzulueta, Jan 29, 2011 IP
  4. Backlinkshub

    Backlinkshub Peon

    Messages:
    35
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    You can use this Query to empty table

    TRUNCATE TABLE "table_name" ;

    i.e. TRUNCATE TABLE employee;

    In this way your table "employee" will be deleted & Re-Created with NO data in it by SQL Engine.


    And if you want to delete some records then use

    DELETE FROM "table_name" WHERE "condition";

    i.e. DELETE FROM employee WHERE emp_id=5 AND emp_id=8;

    In this way the records will be deleted having ids 5 & 8 , rest of the table will remain as it was.
     
    Last edited: Feb 3, 2011
    Backlinkshub, Feb 3, 2011 IP
  5. sippsin

    sippsin Active Member

    Messages:
    237
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    63
    #5
    Make sure when you use TRUNCATE, it automatically saves the operation you do. If you use DELETE, you need to write a "COMMIT" to save the operation.
     
    sippsin, Feb 3, 2011 IP
  6. nirajkum

    nirajkum Active Member

    Messages:
    815
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    58
    #6
    you can use drop and delete database command do google for more options
     
    nirajkum, Feb 7, 2011 IP
  7. cools4u

    cools4u Peon

    Messages:
    8
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #7
    If you have to delete all the records from a table then "truncate" statement will work much faster than "delete" but for conditional deleting of records "delete" statment will work as "truncate" does not support conditional statments ...
     
    cools4u, Feb 14, 2011 IP
  8. prptl709

    prptl709 Guest

    Messages:
    83
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #8
    The answer of this question is delete tablename will delete all the tables data.
     
    prptl709, Feb 21, 2011 IP
  9. peterCx

    peterCx Peon

    Messages:
    34
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #9
    select * from tab where username=&1

    for loop
    trucate table Table_Name
    end loop
     
    peterCx, Feb 23, 2011 IP
  10. ashishy.freelancer

    ashishy.freelancer Peon

    Messages:
    50
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #10
    truncate table table_name
     
    ashishy.freelancer, Feb 23, 2011 IP
  11. Amjad2010

    Amjad2010 Peon

    Messages:
    40
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #11
    Hi this is the SQL query to delete records from the table:

    TRUNCATE TABLE "table_name" ;

    if you want to delete some records then use this statement

    DELETE FROM "table_name" WHERE "condition";

    If you wana get rid of table then use
    DROP table "table_name";

    Hope this helps
     
    Amjad2010, Mar 12, 2011 IP
  12. szas.inno

    szas.inno Peon

    Messages:
    3
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #12
    sql> delete * from tablename;

    bet of luck.
     
    szas.inno, Jun 2, 2011 IP
  13. tothemax

    tothemax Peon

    Messages:
    25
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #13
    delete *from tablename can potentially have a difference to truncate tablename when you have auto incrementing primary keys. Truncate may reset the auto increment counter
     
    tothemax, Jun 6, 2011 IP
  14. pbonweb

    pbonweb Peon

    Messages:
    172
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #14
    TRUNCATE TABLE "table_name".It is delete each record of the table .
     
    pbonweb, Jun 20, 2011 IP
  15. amkeabhi123

    amkeabhi123 Member

    Messages:
    219
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    28
    #15
    delete from table name ,it delete all records in your table so you can insert the data in the first line.
     
    amkeabhi123, Jun 21, 2011 IP
  16. amitjaura

    amitjaura Peon

    Messages:
    13
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #16
    CREATE PROCEDURE sp_EmplyAllTable

    AS

    EXEC sp_MSForEachTable ‘ALTER TABLE ? NOCHECK CONSTRAINT ALL’

    EXEC sp_MSForEachTable ‘DELETE FROM ?’

    EXEC sp_MSForEachTable ‘ALTER TABLE ? CHECK CONSTRAINT ALL’

    GO
     
    amitjaura, Jun 21, 2011 IP
  17. omeslawanya

    omeslawanya Peon

    Messages:
    69
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #17
    for particular table you can use Delete function and all over table delete of database use Truncate table table_name
     
    omeslawanya, Jun 22, 2011 IP
  18. unknownpray

    unknownpray Active Member

    Messages:
    3,831
    Likes Received:
    14
    Best Answers:
    0
    Trophy Points:
    70
    #18
    we can useTRUNCATE or DELETE to delete data from table
    example :- truncate table <tablename>
     
    unknownpray, Jun 24, 2011 IP
  19. shikhasweetie

    shikhasweetie Peon

    Messages:
    6
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #19
    you can use
    delete * from table_name
     
    shikhasweetie, Jun 25, 2011 IP
  20. amkeabhi123

    amkeabhi123 Member

    Messages:
    219
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    28
    #20
    delete from table name use the query delete the all table contents you can insert the table first row.
     
    amkeabhi123, Jul 1, 2011 IP