Creating and Managing Databases and Tables
๐๏ธ Creating & Managing Databases and Tables in MySQL
In MySQL, databases serve as containers for related tables.
๐ ๏ธ Creating a Database
CREATE DATABASE my_database;
USE my_database;
Use the CREATE DATABASE
statement to initialize a new database, then USE
to set it as the current context.
๐ Creating Tables
Define columns with specific data types and constraints:
CREATE TABLE users (
id INT PRIMARY KEY,
name VARCHAR(100) NOT NULL,
email VARCHAR(100)
);
NOT NULL
: Ensures a value must be providedPRIMARY KEY
: Ensures unique identification
๐ง Managing Tables
- โ๏ธ
ALTER TABLE
: Modify table structure - โ
DROP TABLE
: Delete a table - ๐
RENAME TABLE
: Change a tableโs name
๐ Proper management ensures structured data and facilitates maintenance, backups, and scalability.