MySQL CREATE DATABASE Statement

MySQL CREATE DATABASE Statement

The CREATE DATABASE statement in MySQL is used to create a new database. It is one of the first steps when starting a new MySQL project.


๐Ÿ”น Syntax

CREATE DATABASE database_name;
  • database_name โ†’ Name of the database to create

  • Database names must be unique on the MySQL server.

  • Optional clauses: IF NOT EXISTS and character set/collation.


๐Ÿ”น Syntax with IF NOT EXISTS


  • Prevents an error if the database already exists.


๐Ÿ”น Syntax with Character Set and Collation


  • CHARACTER SET โ†’ Sets the default character set for the database.

  • COLLATE โ†’ Sets the default collation (sorting rules).


๐Ÿ”น Example 1: Simple Database Creation


  • Creates a new database called SchoolDB.


๐Ÿ”น Example 2: Create Database If Not Exists


  • Ensures the command doesnโ€™t fail if SchoolDB already exists.


๐Ÿ”น Example 3: Create Database with UTF8 Character Set


  • Sets database to support Unicode characters.


๐Ÿ”น Key Points

  1. Database names should be descriptive and unique.

  2. Use IF NOT EXISTS to avoid errors if the database already exists.

  3. Specify CHARACTER SET and COLLATE for multi-language support.

  4. After creating a database, use:

CodeCapsule

Sanjit Sinha โ€” Web Developer | PHP โ€ข Laravel โ€ข CodeIgniter โ€ข MySQL โ€ข Bootstrap Founder, CodeCapsule โ€” Student projects & practical coding guides. Email: info@codecapsule.in โ€ข Website: CodeCapsule.in

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *