

- 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
Check if table exists in MySQL and display the warning if it exists?
To check if table exists, use the following syntax −
CREATE TABLE IF NOT EXISTS yourTableName ( yourColumnName1 dataType, . . . . N );
Here, we will try to create a table that already exists and then it will produce a warning message “Table already exists”. Let us first create a table. This table already exists −
mysql> CREATE TABLE IF NOT EXISTS DemoTable ( Id int ); Query OK, 0 rows affected, 1 warning (0.06 sec)
The warning message is as follows −
mysql> show warnings;
Output
+-------+------+-------------------------------------+ | Level | Code | Message | +-------+------+-------------------------------------+ | Note | 1050 | Table 'DemoTable' already exists | +-------+------+-------------------------------------+ 1 row in set (0.00 sec)
If table does not already exist, then it will get created −
mysql> CREATE TABLE IF NOT EXISTS DemoTable2 ( Id int ); Query OK, 0 rows affected (0.71 sec)
- Related Questions & Answers
- Check if a user exists in MySQL and drop it?
- How to check if a table exists in MySQL and create if it does not already exist?
- Check if MySQL entry exists and if it does, how to overwrite other columns?
- Check if MongoDB database exists?
- How to check if a MySQL database exists?
- Check if a value exists in a column in a MySQL table?
- Check if a table is empty or not in MySQL using EXISTS
- Drop trigger if exists in MySQL?
- Check if a file exists in Java
- Check if a File exists in C#
- Check that a table exists in MySQL?
- How to check if a python module exists without importing it?
- INSERT INTO table if a table exists in MySQL else implement CREATE TABLE and create the table
- How to check if a table already exists in the database with MySQL with INFORMATION_SCHEMA.TABLES.?
- Check if a PHP cookie exists and if not set its value
Advertisements