Create and Use Database in SQL
Step 1: Create the Database
To create a database in SQL, use the CREATE DATABASE command:
CREATE DATABASE my_database;
Step 2: Use the Database
To start working with a database, use the USE command:
USE my_database;
Step 3: Create the Table
Create a table in your database using the CREATE TABLE command. For example:
CREATE TABLE employees (
id INT AUTO_INCREMENT PRIMARY KEY,
name VARCHAR(100),
role VARCHAR(50),
salary DECIMAL(10, 2)
);
Step 4: Insert Data into the Table
Add data to your table using the INSERT INTO command:
INSERT INTO employees (name, role, salary) VALUES
('John Doe', 'Manager', 75000.00),
('Jane Smith', 'Developer', 65000.00);
SELECT Command in SQL
Retrieve data from your table using the SELECT command. For example:
SELECT * FROM employees;
This command fetches all columns and rows from the employees table.
