SQL CREATE DATABASE and DROP DATABASE Statements
These SQL commands are used to manage databases: CREATE DATABASE
creates a new database, and DROP DATABASE
deletes an existing one. Use these commands with caution, as deleting a database permanently removes all its data and structure.
CREATE DATABASE
Creating a New Database
The CREATE DATABASE
statement creates a new, empty database. You'll need administrator (or equivalent) privileges to execute this command.
Syntax
CREATE DATABASE database_name;
Example: Creating a Database Named "testDB"
Syntax
CREATE DATABASE testDB;
Output
A new, empty database named "testDB" is created. To verify, you can use the command SHOW DATABASES;
(in MySQL) or a similar command in your database system to view the list of available databases.
DROP DATABASE
Deleting a Database
The DROP DATABASE
command permanently deletes a database and all its contents. This action is irreversible (without a backup), so exercise extreme caution when using this command. Always double-check the database name before executing this statement.
Syntax
DROP DATABASE database_name;
Example: Deleting the "testDB" Database
Syntax
DROP DATABASE testDB;
Output
The database named "testDB" and all its tables and data are permanently deleted.