
- Learn MySQL
- MySQL - Home
- MySQL - Introduction
- MySQL - Installation
- MySQL - Administration
- MySQL - PHP Syntax
- MySQL - Connection
- MySQL - Create Database
- MySQL - Drop Database
- MySQL - Select Database
- MySQL - Data Types
- MySQL - Create Tables
- MySQL - Drop Tables
- MySQL - Insert Query
- MySQL - Select Query
- MySQL - Where Clause
- MySQL - Update Query
- MySQL - Delete Query
- MySQL - Like Clause
- MySQL - Sorting Results
- MySQL - Using Join
- MySQL - NULL Values
- MySQL - Regexps
- MySQL - Transactions
- MySQL - Alter Command
- MySQL - Indexes
- MySQL - Temporary Tables
- MySQL - Clone Tables
- MySQL - Database Info
- MySQL - Using Sequences
- MySQL - Handling Duplicates
- MySQL - SQL Injection
- MySQL - Database Export
- MySQL - Database Import
Drop a MySQL Table after x hours?
You need to create event to drop table after x hours. The syntax is as follows −
CREATE EVENT yourEventName ON SCHEDULE AT CURRENT_TIMESTAMP + INTERVAL x HOUR DO DROP TABLE IF EXISTS yourTableName;
Let us first create a table −
mysql> create table DemoTable ( StudentId int NOT NULL AUTO_INCREMENT PRIMARY KEY, StudnetFirstName varchar(20), StudentLastName varchar(20), StudnetAge int ); Query OK, 0 rows affected (0.52 sec)
Now implement the above event in order to drop table after 2 hours −
mysql> CREATE EVENT drop_table_event_after2HoursDemo ON SCHEDULE AT CURRENT_TIMESTAMP + INTERVAL 2 HOUR DO DROP TABLE IF EXISTS DemoTable; Query OK, 0 rows affected (0.17 sec)
Now the table ‘DemoTable’ will drop after 2 hours.
- Related Articles
- How to Drop MySQL Table using Java?
- Fix Drop table view #1051 unknown table error in MySQL
- How can we drop UNIQUE constraint from a MySQL table?
- How can I drop an existing column from a MySQL table?
- Does MySQL DROP TABLE completely remove the table or just the structure?
- Reorder keys after deleting a record from MySQL table?
- How to optimize a MySQL table after deleting some rows?
- Display dates after NOW() + 10 days from a MySQL table?
- MySQL appears to DROP USER but user still exists in MySQL.users table?
- What MySQL returns when we remove all the columns from a table by using ALTER TABLE command with DROP keyword?
- How to drop a table from JavaDB using JDBC?
- Select entries with timestamp after X time in MySQL
- How to auto increment with 1 after deleting data from a MySQL table?
- How to drop table in Android sqlite?
- How to drop a table from a database using JDBC API?

Advertisements