MySql Database commands
MySql Database commands
--------------------------------------
-Create Database:
create database phpCMS;
-Create Table:
-Table users
CREATE TABLE users (
user_id INT AUTO_INCREMENT PRIMARY KEY,
user_name VARCHAR(100) NOT NULL,
user_email VARCHAR(50) NOT NULL,
user_password VARCHAR(50) NOT NULL,
user_status ENUM('active', 'inactive'),
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
created_by INT,
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
updated_by INT NOT NULL,
last_login TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
FOREIGN KEY (created_by) REFERENCES users(user_id),
FOREIGN KEY (updated_by) REFERENCES users(user_id)
);
-Table roles
CREATE TABLE roles (
role_id INT AUTO_INCREMENT PRIMARY KEY,
role_name VARCHAR(100) NOT NULL,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
created_by INT,
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
updated_by INT NOT NULL,
FOREIGN KEY (created_by) REFERENCES users(user_id),
FOREIGN KEY (updated_by) REFERENCES users(user_id)
);
-Table user_roles_mapping
CREATE TABLE users_roles_mapping (
user_id INT,
role_id INT,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
created_by INT,
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
updated_by INT NOT NULL,
FOREIGN KEY (created_by) REFERENCES users(user_id),
FOREIGN KEY (updated_by) REFERENCES users(user_id),
FOREIGN KEY (user_id) REFERENCES users(user_id),
FOREIGN KEY (role_id) REFERENCES roles(role_id)
);
-Table categories
CREATE TABLE categories (
category_id INT AUTO_INCREMENT PRIMARY KEY,
created_by INT,
category_name VARCHAR(100) NOT NULL,
category_slug VARCHAR(100) NOT NULL,
parent_category_id INT,
category_image VARCHAR(300),
category_description LONGTEXT(200),
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
updated_by INT NOT NULL,
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
FOREIGN KEY (created_by) REFERENCES users(user_id),
FOREIGN KEY (updated_by) REFERENCES users(user_id),
FOREIGN KEY (parent_category_id) REFERENCES categories(category_id)
);
-Table blogs
CREATE TABLE blogs (
blog_id INT AUTO_INCREMENT PRIMARY KEY,
created_by INT,
blog_title LONGTEXT NOT NULL,
blog_description LONGTEXT NOT NULL,
blog_date DATE,
category_id INT,
blog_tags VARCHAR(100) NOT NULL,
blog_meta_title VARCHAR(100) NOT NULL,
blog_meta_description LONGTEXT NOT NULL,
blog_keywords VARCHAR(100) NOT NULL,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
updated_by INT NOT NULL,
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
FOREIGN KEY (created_by) REFERENCES users(user_id),
FOREIGN KEY (updated_by) REFERENCES users(user_id),
FOREIGN KEY (category_id) REFERENCES categories(category_id)
);