Untitled

 avatar
DMITRYZIMKOV
plain_text
2 months ago
1.9 kB
159
Indexable
Never
➡️MAKE SURE TO REPLACE VALUES/NAMES ACCORDING TO THE QUESTION.
➡️UNDERSTAND THE LINKING OF YOUR OWN DATA ACCORDING TO THE NEED.
➡️VALUES HERE ARE FULLY DUMMY AND NOT ACCORDING TO CE 2 QUESTION.



➡️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;
Leave a Comment