) SELECT CONCAT( 'DROP TABLE ', GROUP_CONCAT( schema, '.',table_name)), ' ')ĪND table_name LIKE display the dynamic sql statement SELECT execute dynamic sql PREPARE stmt FROM stmt ĭEALLOCATE PREPARE stmt Code language: SQL (Structured Query Language) ( sql ) build dynamic sql (DROP TABLE tbl1, tbl2. set table schema and pattern matching for tables SET schema = 'classicmodels' A) Using MySQL DROP TABLE to drop a single table exampleįirst, create a table named insurances for testing purpose: Let’s take some examples of using the DROP TABLE statement. To execute the DROP TABLE statement, you must have DROP privileges for the table that you want to remove. The RESTRICT and CASCADE options are reserved for the future versions of MySQL. Therefore, if you create a table with the same name as the dropped one, MySQL will apply the existing privileges to the new table, which may pose a security risk. It doesn’t remove specific user privileges associated with the tables. Note that the DROP TABLE statement only drops tables. If you drop a non-existing table with the IF EXISTS option, MySQL generates a NOTE, which can be retrieved using the SHOW WARNINGS statement. The IF EXISTS option conditionally drop a table only if it exists. It ensures that you do not accidentally remove non-temporary tables. The TEMPORARY option allows you to remove temporary tables only. In MySQL, you can also remove multiple tables using a single DROP TABLE statement, each table is separated by a comma (,). The DROP TABLE statement removes a table and its data permanently from the database. Code language: SQL (Structured Query Language) ( sql )
0 Comments
Leave a Reply. |
Details
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |