- SQL Basics
- SQL Introduction
- SQL Syntax
- SQL Sample Database
- SQL SELECT
- SQL WHERE
- SQL ORDER BY
- SQL DISTINCT
- SQL LIMIT
- SQL FETCH
- SQL AND
- SQL OR
- SQL BETWEEN
- SQL IN
- SQL LIKE
- SQL IS NULL
- SQL Comparison Operators
- SQL Logical Operators
- SQL Alias
- SQL CASE
- Joins and Subqueries
- SQL INNER JOIN
- SQL LEFT JOIN
- SQL RIGHT JOIN
- SQL FULL OUTER JOIN
- SQL SELF JOIN
- SQL CROSS JOIN
- SQL Subquery
- SQL Correlated Subquery
- SQL UNION
- SQL INTERSECT
- SQL EXCEPT
- Aggregate Functions
- SQL AVG
- SQL COUNT
- SQL MAX
- SQL MIN
- SQL SUM
- SQL GROUP BY
- SQL HAVING
- SQL ROLLUP
- SQL CUBE
- SQL GROUPING SETS
- Database Management
- SQL CREATE DATABASE
- SQL ALTER DATABASE
- SQL DROP DATABASE
- SQL BACKUP DATABASE
- SQL SHOW DATABASES
- SQL SELECT DATABASE
- Table Management
- SQL CREATE TABLE
- SQL ALTER TABLE
- SQL ADD COLUMN
- SQL DROP COLUMN
- SQL DROP TABLE
- SQL TRUNCATE TABLE
- SQL SHOW TABLES
- SQL RENAME TABLE
- SQL Constraints
- SQL Primary Key
- SQL Foreign Key
- SQL UNIQUE Constraint
- SQL CHECK Constraint
- SQL NOT NULL Constraint
SQL CREATE DATABASE
The CREATE DATABASE
statement is used to create a new database in SQL. A database stores tables, views, and other objects that help organize and manage data efficiently.
Syntax of SQL CREATE DATABASE
CREATE DATABASE database_name;
- database_name: The name of the database to be created.
CREATE DATABASE database_name CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
Key Features of SQL CREATE DATABASE
- Creates a new database.
- The database name must be unique in the system.
- Requires appropriate permissions (e.g.,
CREATE DATABASE
privilege). - Default settings like collation and character set can be specified.
Example of SQL CREATE DATABASE
CREATE DATABASE SchoolDB;
Output:
A new database named SchoolDB
is created.
To use this database, run:
USE SchoolDB;
Checking Existing Databases
To list all databases:
SHOW DATABASES;
Dropping a Database
To delete an existing database:
DROP DATABASE SchoolDB;
Summary
CREATE DATABASE
is used to create a new database.- Ensure the database name is unique.
- Use
SHOW DATABASES
to verify its creation. - Use
DROP DATABASE
to delete it if needed.