Step-by-Step Guide to Create a MySQL Table
1. Access MySQL Server:
First, Log in to your MySQL server using a command-line interface like MySQL Shell or a GUI tool like MySQL Workbench.
2. Select Database:
If you haven’t already selected a database choose the database where you want to create the table. Use the
USE statement:USE your_database_name;
3. Create Table:
Create a table named employees with columns id, first_name, last_name, email, hire_date, salary and department_id. Here’s how you would define this table:
CREATE TABLE employees (
id INT AUTO_INCREMENT PRIMARY KEY,
first_name VARCHAR(50) NOT NULL,
last_name VARCHAR(50) NOT NULL,
email VARCHAR(100) NOT NULL,
hire_date DATE NOT NULL,
salary DECIMAL(10, 2) NOT NULL,
department_id INT,
CONSTRAINT A_department
FOREIGN KEY (department_id)
REFERENCES departments(id)
ON DELETE SET NULL
);
Verify Table Creation:
After creating table then verify the table, use below command
SHOW TABLES;


0 Comments