- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
PHP and MYSQL database connection and table creation only once if it does not already exist?
To create database only once, use the below syntax.
CREATE DATABASE IF NOT EXISTS yourDatabaseName;
To create table only once, use the below syntax −
CREATE TABLE IF NOT EXISTS yourTableName ( yourColumnName yourDatatype, . . . N );
Let us implement both the above syntaxes to create database and table only once if does not already exist −
mysql> CREATE DATABASE IF NOT EXISTS login; Query OK, 1 row affected (0.23 sec)
Above query creates a database successfully.
Following is the query to create a table −
mysql> CREATE TABLE IF NOT EXISTS DemoTable ( Id int ); Query OK, 0 rows affected (0.56 sec)
Above query creates a table successfully.
- Related Articles
- Create view in MySQL only if it does not already exist?
- How to check if a table exists in MySQL and create if it does not already exist?
- Create a table if it does not already exist and insert a record in the same query with MySQL
- MySQL create user if it does not exist?
- Add object to array in JavaScript if name does not already exist?
- How to insert only those records that does not exist in a MySQL table?
- Select a value from MySQL database only if it exists only once from a column with duplicate and non-duplicate values
- Select from table where value does not exist with MySQL?
- Insert records in MongoDB collection if it does not exist?
- Does NOT EQUAL exist in MySQL?
- MySQL SELECT from table A that does not exist in table B using JOINS?
- How to select from MySQL table A that does not exist in table B?
- How can I create a python directory if it does not exist?
- How to create a folder if it does not exist in C#?
- How to check if a table already exists in the database with MySQL with INFORMATION_SCHEMA.TABLES.?

Advertisements