vadnica-logo
X

MySQL DROP TABLE

DROP TABLE is an SQL command used for removing tables from a database. When you delete a table, all data, indexes, and constraints associated with that table are deleted. This command cannot be undone, so it's important to use it carefully and create a backup of the data if needed.

  1. Basic syntax for deleting a table:
    DROP TABLE table;            
  2. Safer syntax with IF EXISTS:
    DROP TABLE IF EXISTS table;            
  3. Check if table exists before deletion:
    SHOW TABLES LIKE 'table';            
  4. Delete table with referential integrity check:
    SET FOREIGN_KEY_CHECKS = 0;
    DROP TABLE IF EXISTS table;
    SET FOREIGN_KEY_CHECKS = 1;            
  5. Verify if deletion was successful:
    SHOW TABLES;            
  6. Backup before deletion:
    CREATE TABLE backup AS SELECT * FROM table;
    DROP TABLE IF EXISTS table;            

Thank you for visiting! Adding privacy policy.

© 2024 All rights reserved.

Vam je koda pomagala? Če želite podpreti moj trud pri pripravi vodičev in vzdrževanju strani, mi lahko namenite donacijo za kavo.