SQLize Online / PHPize Online  /  SQLtest Online

A A A
Share      Blog   Popular
Copy Format Clear
-- Create the database CREATE DATABASE IF NOT EXISTS user_registration; -- Use the database USE user_registration; -- Create the users table CREATE TABLE IF NOT EXISTS users ( id INT AUTO_INCREMENT PRIMARY KEY, first_name VARCHAR(50) NOT NULL, last_name VARCHAR(50) NOT NULL, email VARCHAR(100) NOT NULL, age INT NOT NULL, remarks TEXT NOT NULL, time DATETIME NOT NULL, year_month INT AS (EXTRACT(YEAR_MONTH FROM time)) STORED, INDEX idx_email_year_month (email, year_month) ); -- Add a unique constraint for email per month ALTER TABLE users ADD CONSTRAINT unique_email_per_month UNIQUE (email, year_month);

Stuck with a problem? Got Error? Ask ChatGPT!

Copy Clear