📊

Managing Databases: Creation to Deletion

Oct 16, 2024

Lecture Notes: Creating, Altering, and Dropping a Database

Introduction to Databases

  • Database Definition: A database acts like a folder, a container for data.
  • Tables: Considered as files within the folder.

Creating a Database

  • SQL Statement: CREATE DATABASE followed by a unique database name.
    • Example: CREATE DATABASE myDB;
  • Case Sensitivity: MySQL keywords are not case-sensitive. Preferences can vary:
    • All uppercase: CREATE
    • Capitalize first letter: Create
    • All lowercase: create
  • Execution: Click the lightning bolt button to execute the statement.
  • Verification: Check the schemas tab and refresh to see the new database.

Using a Database

  • Set as Default:
    • Right-click on the database and select 'Set as Default Schema'.
    • Or use the command: USE myDB;

Dropping a Database

  • SQL Statement: DROP DATABASE followed by the database name.
    • Example: DROP DATABASE myDB;
  • Implication: Permanently deletes the database.
  • Recreation: Can recreate the database if needed: CREATE DATABASE myDB;

Altering a Database

  • Features for Beginners:
    • Setting a database to read-only.
    • Enabling encryption (not covered in detail).
  • Read-Only Mode:
    • Command: ALTER DATABASE myDB READ ONLY = 1;
    • Prevents any modifications but allows data access.
  • Attempting to Drop a Read-Only Database:
    • Results in error: Schema myDB is in read only mode.
    • To disable: ALTER DATABASE myDB READ ONLY = 0;

Conclusion

  • Summary: Steps to create, use, drop, and alter a database.
  • Next Topic: Creation of tables within the database.