Untitled

mail@pastecode.io avatar
unknown
plain_text
2 months ago
1.7 kB
1
Indexable
Never
COMMAND TO CREATE DATABASE:

CREATE DATABASE your_database_name;

Command to use database:

USE your_database_name;

COMMAND TO CREATE TABLE:

CREATE TABLE employee (
    employee_id INT PRIMARY KEY AUTO_INCREMENT,
    name VARCHAR(50) NOT NULL,
    username VARCHAR(30) UNIQUE NOT NULL,
    phone_number VARCHAR(15),
    department VARCHAR(50),
    salary DECIMAL(10, 2)
);

COMMAND TO INSERT VALUES IN TABLE:

INSERT INTO employee (name, username, phone_number, department, salary)
VALUES
    ('John Doe', 'johndoe', '555-1234', 'HR', 50000.00),
    ('Jane Smith', 'janesmith', '555-5678', 'IT', 60000.00),
    ('Bob Johnson', 'bobjohnson', '555-9876', 'Finance', 55000.00),
    ('Alice Brown', 'alicebrown', '555-4321', 'Marketing', 52000.00);

COMMAND TO FILTER PARTICULAR SALARY (Eg: 55000):

select name from employee where salary=55000;

COMMAND TO ALTER TABLE:

ALTER TABLE employee
ADD COLUMN email VARCHAR(100);

COMMANDS TO CREATE MULTIPLE NEW COLUMNS:

ALTER TABLE employee
ADD COLUMN pincode VARCHAR(100),
ADD COLUMN district VARCHAR(100),
ADD COLUMN experience VARCHAR(100);

COMMAND TO DELETE COLUMNS:

ALTER TABLE employee
DROP COLUMN pincode,
DROP COLUMN district,
DROP COLUMN experience;

COMMAND TO ARRANGE IN ASCENDING ORDER:

SELECT * FROM employee
ORDER BY salary ASC;

COMMAND TO ARRANGE IN DESCENDING ORDER:

SELECT * FROM employee
ORDER BY hire_date DESC;

COMMAND TO MERGE 2 TABLES:

SELECT employee.*, department.department_name
FROM employee
INNER JOIN department ON employee.department = department.department_id;

➡️MAKE SURE TO REPLACE VALUES/NAMES ACCORDING TO THE QUESTION.
Leave a Comment