Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Truncate and drop difference

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 471
    Comment on it

    Truncate and drop both are similar to each other as they are used to delete the complete data of a table.

    The difference between them is this truncate only delete the data of the table where as the table structure is there but when we drop the table the table data is deleted and also the table structure.

     

    truncate

     

    TRUNCATE TABLE  table_name;

    ex

    +----+----------+-----+-----------+----------+
    | ID | NAME     | AGE | ADDRESS   | SALARY   |
    +----+----------+-----+-----------+----------+
    |  1 | Ramesh   |  32 | Ahmedabad |  2000.00 |
    |  2 | Khilan   |  25 | Delhi     |  1500.00 |
    |  3 | kaushik  |  23 | Kota      |  2000.00 |
    |  4 | Chaitali |  25 | Mumbai    |  6500.00 |
    |  5 | Hardik   |  27 | Bhopal    |  8500.00 |
    |  6 | Komal    |  22 | MP        |  4500.00 |
    |  7 | Muffy    |  24 | Indore    | 10000.00 |
    +----+----------+-----+-----------+----------+
    TRUNCATE TABLE CUSTOMERS;

    now select the data

    SELECT * FROM CUSTOMERS;

    The result

    Empty set (0.00 sec)

     

    drop

     

    +---------+---------------+------+-----+---------+-------+
    | Field   | Type          | Null | Key | Default | Extra |
    +---------+---------------+------+-----+---------+-------+
    | ID      | int(11)       | NO   | PRI |         |       |
    | NAME    | varchar(20)   | NO   |     |         |       |
    | AGE     | int(11)       | NO   |     |         |       |
    | ADDRESS | char(25)      | YES  |     | NULL    |       |
    | SALARY  | decimal(18,2) | YES  |     | NULL    |       |
    +---------+---------------+------+-----+---------+-------+

    drop table

    DROP TABLE CUSTOMERS;
    select table
    
    DESC CUSTOMERS;

    The result

    ERROR 1146 (42S02): Table 'TEST.CUSTOMERS' doesn't exist

     

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: