SQL Practical Questions and Solutions
Question 1: Create a database named 'xyz'.
Solution:
CREATE DATABASE xyz;
Question 2: Select the database 'xyz'.
Solution:
USE xyz;
Question 3: Create a table named 'employees' containing eid, name, post and
salary.
Solution:
CREATE TABLE employees (
eid INT,
name VARCHAR(50),
post VARCHAR(50),
salary FLOAT
);
Question 4: Delete the column named salary.
Solution:
ALTER TABLE employees DROP COLUMN salary;
Question 5: Add a column salary with datatype INTEGER.
Solution:
ALTER TABLE employees ADD salary INT;
Question 6: Modify the datatype of salary from INTEGER to FLOAT.
Solution:
ALTER TABLE employees MODIFY salary FLOAT;
Question 7: Rename 'eid' to 'empid'.
Solution:
ALTER TABLE employees CHANGE eid empid INT;
Question 8: Rename the table 'employees' to 'emp_details'.
Solution:
RENAME TABLE employees TO emp_details;
Question 9: Insert any five records into the table 'emp_details'.
Solution:
INSERT INTO emp_details (empid, name, post, salary) VALUES
(101,'Ram','Manager',55000),
(102,'Sita','Accountant',45000),
(103,'Hari','Clerk',30000),
(104,'Gita','Officer',40000),
(105,'Shyam','Supervisor',35000);
Question 10: Delete all records from the table 'emp_details'.
Solution:
DELETE FROM emp_details;
Question 11: Delete the table name 'emp_details'.
Solution:
DROP TABLE emp_details;
Question 12: Delete the database 'xyz'.
Solution:
DROP DATABASE xyz;