0% found this document useful (0 votes)
11 views2 pages

MySQL DDL and DML Tutorial Guide

Uploaded by

pegina4045
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views2 pages

MySQL DDL and DML Tutorial Guide

Uploaded by

pegina4045
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Tutorial Answersheet

Sample Answers (MySQL Syntax)

DDL

-- 1. Create Table
CREATE TABLE employees (
emp_id INT PRIMARY KEY,
first_name VARCHAR(50),
last_name VARCHAR(50),
hire_date DATE,
salary DECIMAL(10, 2)
);

-- 2. Add column
ALTER TABLE employees ADD email VARCHAR(100);

-- 3. Rename column
ALTER TABLE employees CHANGE salary monthly_salary DECIMAL(10,2);

-- 4. Drop column
ALTER TABLE employees DROP COLUMN email;

-- 5. Drop table
DROP TABLE employees;

-- 6. Truncate table
TRUNCATE TABLE employees;
DML

-- 1. Insert
INSERT INTO employees (emp_id, first_name, last_name, hire_date, salary)
VALUES (1, 'John', 'Doe', '2020-01-01', 5000.00);

-- 2. Update
UPDATE employees SET salary = 6000.00 WHERE emp_id = 1;

-- 3. Delete
DELETE FROM employees WHERE emp_id = 1;

-- 4. Insert multiple
INSERT INTO employees (emp_id, first_name, last_name, hire_date, salary)
VALUES
(2, 'Alice', 'Smith', '2021-06-15', 7000.00),
(3, 'Bob', 'Brown', '2022-03-10', 6500.00);

-- 5. Select by hire_date
SELECT * FROM employees WHERE hire_date > '2021-01-01';

-- 6. Select by salary
SELECT * FROM employees WHERE salary > 7000;

You might also like