Creating a Database
Introduction to SQL
Database
SQL Basics
Creating a Database
Using a Database
Creating a Table
Common Data Types
Inserting Data
Selecting Data
WHERE Clause
Comparison Operators
AND, OR, and NOT
ORDER BY Clause
LIMIT Clause
DISTINCT
LIKE Operator
IN, BETWEEN, and IS NULL
Updating Data
Deleting Data
ALTER TABLE
DROP TABLE
PRIMARY KEY and NOT NULL
FOREIGN KEY and Relationships
Aggregate Functions
GROUP BY Clause
HAVING Clause
JOIN Basics
INNER JOIN
LEFT JOIN
Aliases
Subqueries
Indexes
User Permissions and Security
Common Mistakes Beginners Make
Practice Ideas
Creating a Database
Creating a Database
Definition: The CREATE DATABASE statement is used to initialize a brand-new, empty database container within your database management system (DBMS).
Learning Outcome: Creating and managing databases is a fundamental skill. Before you can build tables or store information, you must first establish the root environment where all your data assets will live.
Syntax
The syntax is straightforward. You use the CREATE DATABASE keyword followed by the unique name you wish to give your new database.
CREATE DATABASE database_name;
Example
If you are building a system to manage a learning institution, you might run the following command:
CREATE DATABASE school;
Explanation
- Execution: When this command is executed, the system reserves space and sets up the necessary background files for a database named
school. - Naming Rules: Database names should be descriptive, unique, and typically do not contain spaces (use underscores like
school_managementinstead).
Key Notes
- Administrative Privileges: In many professional environments, you need specific "admin" or "create" permissions assigned to your user account to execute this command.
- The Next Step: Once the database is created, you usually need to tell the system you want to work inside it by using the
USEcommand (e.g.,USE school;). - Case Sensitivity: While SQL keywords are not case-sensitive, some operating systems (like Linux) may treat the actual database name as case-sensitive. It is best practice to be consistent.
🏋️ Test Yourself With Exercises
Take our quiz on Creating a Database to test your knowledge.
Browse Quizzes »