MySQL Applications – Complete Questions and Answers
Q1. Write SQL commands to create database COMPANY.
Answer:
CREATE DATABASE COMPANY;
Q2. Display all databases.
Answer:
SHOW DATABASES;
Q3. Select the database COMPANY.
Answer:
USE COMPANY;
Q4. Create Employee table with constraints.
Answer:
CREATE TABLE Employee (
EmpCode VARCHAR(5) PRIMARY KEY,
Name VARCHAR(20) NOT NULL,
Department VARCHAR(20),
City VARCHAR(20),
Salary INT
);
Q5. Display structure of Employee table.
Answer:
DESC Employee;
Q6. Display all tables.
Answer:
SHOW TABLES;
Q7. What is degree and cardinality?
Answer:
Degree = 5, Cardinality = 5.
Q8. What is NULL?
Answer:
NULL represents missing or unknown value.
Q9. Display employees working in IT.
Answer:
SELECT Name FROM Employee WHERE Department='IT';
Q10. Display EmpCode of HR employees.
Answer:
SELECT EmpCode FROM Employee WHERE Department='HR';
Q11. Salary more than 10000.
Answer:
SELECT * FROM Employee WHERE Salary>10000;
Q12. Increase salary by 2000 without update.
Answer:
SELECT Salary+2000 AS Increased_Salary FROM Employee;
Q13. Salary between 8000 and 15000.
Answer:
SELECT * FROM Employee WHERE Salary BETWEEN 8000 AND 15000;
Q14. City NOT NULL.
Answer:
SELECT Name,Department FROM Employee WHERE City IS NOT NULL;
Q15. Department IT or Finance.
Answer:
SELECT * FROM Employee WHERE Department IN('IT','Finance');
Q16. Add Experience column.
Answer:
ALTER TABLE Employee ADD Experience INT;
Q17. Change Department datatype.
Answer:
ALTER TABLE Employee MODIFY Department VARCHAR(30);
Q18. Rename EmpCode column.
Answer:
ALTER TABLE Employee RENAME COLUMN EmpCode TO Employee_Code;
Q19. Delete Experience column.
Answer:
ALTER TABLE Employee DROP Experience;
Q20. Delete Employee table.
Answer:
DROP TABLE Employee;