

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
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 Questions & Answers
- 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?
- Select entries with timestamp after X time in MySQL
- Display dates after NOW() + 10 days from a MySQL table?
- How to optimize a MySQL table after deleting some rows?
- How to drop a table from JavaDB using JDBC?
- MySQL appears to DROP USER but user still exists in MySQL.users table?
- How to drop table in Android sqlite?
- How to drop a table from a database using JDBC API?
- How to subtract 3 hours from a datetime in MySQL?
- What MySQL returns when we remove all the columns from a table by using ALTER TABLE command with DROP keyword?
Advertisements