Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Difference between TRUNCATE and DROP in MySQL.

    • 0
    • 1
    • 0
    • 1
    • 0
    • 0
    • 0
    • 0
    • 497
    Comment on it

    TRUNCATE

    • TRUNCATE comes under DDL(Data Definition Language).
    • TRUNCATE removes only rows from the table but the structure of the table remains same.
    • Data can not be roll backed if we use "TRUNCATE" command to delete data.
    • Can not use WHERE clause.

    TRUNCATE TABLE statement is usually used to delete all the records inside a table.

    The TRUNCATE TABLE Statement

    When we want to delete all the records inside a table then, use the TRUNCATE TABLE statement.

    Syntax:

    TRUNCATE TABLE table_name;
    

    Example:

    The below statement deletes all the records of "user" table:

    TRUNCATE TABLE user;
    

    DROP

    • DROP comes under DDL(Data Definition Language).
    • It removes whole table (including table structure) from the database.
    • The data cannot be roll backed if the table is dropped by 'DROP' command.

    Syntax:

    DROP TABLE table_name;
    

    Example:

    The below statement drops the "user" table from the database:

    DROP TABLE user;  
    

    Hope this will help you :)

 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: