CREATE DATABASE IF NOT EXISTS database_name
will execute the CREATE DATABASE database_name
only if the database_name
does not already exist.
If the database_name
does not exit, both queries will do the same job, that is they create the database_name
.
If the database_name
exits, CREATE DATABASE database_name
will return an error similar to “the database ‘database_name’ already exists”, while CREATE DATABASE IF NOT EXISTS database_name
will not return an error (it simply does nothing).
When you write a script (let’s say you create the database, then create tables, then insert some data), you don’t want the execution to stop just because the database exits, so you use the second query.
solved difference -in “Create databse” and “create database if not exists”