The CREATE TABLE statement defines a new database table, including column names, data types, constraints, and engine settings.
CREATE TABLE IF NOT EXISTS table_name (
column1 datatype constraints,
column2 datatype constraints,
PRIMARY KEY (column1)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
CREATE TABLE IF NOT EXISTS orders (
order_id INT AUTO_INCREMENT PRIMARY KEY,
user_id INT NOT NULL,
order_status VARCHAR(20) DEFAULT 'PENDING',
total_amount DECIMAL(10,2) NOT NULL,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
utf8mb4 Encoding: Always use utf8mb4 character set to support full Unicode (including emojis and international text).NOT NULL on required fields to maintain data integrity.Why is utf8mb4 preferred over plain utf8 in modern MySQL database configurations?
Sign in to track your learning journey, earn industry-recognized certificates, and join our elite developer community.
Quick Access With