CREATE DATABASE Statement ποΈ¶
Mentor's Note: Before you can build a table, you need a house for it. The Database is that house. Creating it is the very first step in any project. π‘
π The Scenario: The Empty Plot πΊοΈ¶
Imagine you just bought a piece of land. - Currently, it's just "System Space". - You need to officially mark it as "My Office" or "My Home". - Once marked, you can start building rooms (tables) inside it.
π» 1. The Basic Syntax¶
Example: Creating a School Database¶
π» 2. Advanced Creation (With Checks)¶
It's good practice to check if a database already exists before trying to create it, to avoid errors.
π» 3. Selecting the Database (USE)¶
Once created, you must "enter" the house to start working.
(Note: PostgreSQL uses \c school_db in the command line tool, but USE is standard for most GUI clients).
π‘ Best Practices for Naming¶
- Lowercase:
school_db(Avoids OS case-sensitivity issues). - Underscores:
my_app_db(Easier to read thanmyappdb). - Descriptive:
ecommerce_prodvsdb1.