What is DDL?
DDL stands for Data Definition Language.
It is used to create or modify the structure of a database (tables, schemas).
Purpose
• To define, change, or remove database objects.
2️⃣ Main DDL Commands
Command Use Example
CREATE Create new table CREATE TABLE student(id INT);
ALTER Modify table structure ALTER TABLE student ADD age INT;
DROP Delete table permanently DROP TABLE student;
TRUNCATE Remove all rows but keep structure TRUNCATE TABLE student;
3️ What is DML? How is it different from DDL?
DML = Data Manipulation Language
Used to insert, update, delete data inside tables.
• DDL affects structure
• DML affects data
4️⃣ INSERT, UPDATE, DELETE
Command Purpose Example
INSERT Add new data INSERT INTO employee VALUES(1,'Arkan');
UPDATE Modify existing data UPDATE employee SET salary=60000 WHERE id=1;
DELETE Remove data DELETE FROM employee WHERE id=1;
5️⃣ What is DQL?
DQL = Data Query Language
Used to retrieve data from the database.
6️⃣ Role of SELECT in DQL
• Used to retrieve and display data from tables
Example:
SELECT * FROM employee;
7️⃣ WHERE vs ORDER BY
Clause Purpose Example
WHERE Filters data WHERE salary > 50000
ORDER BY Sorts data ORDER BY salary DESC
8️⃣ Constraints (Short Explanation)
Constraint Meaning
Primary Key Unique + Not Null (identifies each row)
Unique All values must be different
Not Null Column cannot be empty
9️⃣ Structure of a SQL Query
Basic form:
SELECT column_names
FROM table_name
WHERE condition
ORDER BY column;
10 Difference: DROP vs DELETE vs TRUNCATE
Command Affects Description
DROP Removes entire table Structure deleted
DELETE Removes selected rows Uses WHERE
TRUNCATE Removes all rows quickly Structure remains
1 Write a DDL query to create a database named company.
-> create database company_1;
2 Write a DDL query to create a table employee with the
fields: id, name, age, salary, department.
- > create table employee(
- -> emp_id int primary key,
- -> emp_name varchar(50),
- -> age int,
- -> salary int,
- -> department varchar(50)
- -> );
3 Write a DDL query to add a new column email to the employee
table.
- > alter table employee add email varchar(50);
4 Write a DDL query to change the datatype of salary to FLOAT.
- > alter table employee modify salary float;
5 Write a DDL query to delete the age column from the employee
table.
- > alter table employee drop column age;
6 Write a DML query to insert five records into the employee
table.
INSERT INTO employee(emp_id, emp_name, salary,
department)
- -> VALUES
- -> (1, 'Arkan', 50000, 'Software'),
- -> (2, 'Rushi', 60000, 'Finance'),
- -> (3, 'Arfat', 70000, 'AI'),
- -> (4, 'Faizan', 80000, 'Marketing'),
- -> (5, 'Aaditya', 90000, 'Sales');
7 Write a DML query to update the salary of an employee whose
id is 2.
- > update employee
- -> set salary =45000
- -> where emp_id =2;
8 Write a DML query to delete all employees from the sales
department.
- > DELETE FROM employee
- -> WHERE department = 'Sales';
9 Write a DQL query to display all employee names and
salaries.
- > select emp_name,salary
- -> from employee;
10 Write a DQL query to display employees whose salary is
greater than 50000.
- > select emp_name
- -> from employee
- -> where salary > 50000;