You are on page 1of 16

DML COMMANDS:

1. Create the following schemas and add the constraints wherever it is


applicable.  
emp_details (empno, emp_name, DOB, address, doj,  dept_no,
salary, designation).  
dept_details (dept_no, dept_name, location). 
Worksfor(Empno,Deptno,No_of_hours) 
2) Add email id attribute to emp relation and describe the structure 
QUERY:
Alter table emp_details add email_id varchar(20);
Desc emp_details
3) Change the data type of emp_name in emp_details relation and
describe the structure 
QUERY:
Alter table emp_details modify emp_name varchar(20);

4) Change the size of any attribute and describe the structure 


QUERY :

Alter table dept_details modify dept_name char(15);

5. Add phone number attribute to emp_details relation and describe


the structure 
QUERY:
Alter table emp_details add phone_no number(10);
6. Rename the empno attribute as Emp_id in emp_details relation and
describe the structure 
QUERY:
Alter table emp_details rename column empno to emp_id;

7. Delete the location attribute from dep_details and describe the


structure 
QUERY:
Alter table dept_details drop column location;
8. Add Emp_id attribute to dept_details relation and describe the
structure 
QUERY:
Alter table dept_details add emp_id varchar(20);
Desc dept_details

9. Insert 5 records each to all the schemas 


QUERY:
10. Display the contents of all the schemas 
QUERY:
Select * from dept_details;

Select * from emp_details;


Select * from worksfor;

11. Copy the contents of emp_details table and name the table


as employee_data. 
QUERY:

Create table employee_data as select * from emp_details;


12. Delete the contents of employee_data table, describe the
structure and display the contents of the table 
QUERY:

Truncate table employee_data ;


Desc employee_data
Select * from employee_data;

13. Delete the structure of  employee_data table , describe the


structure and display the contents of the table 
QUERY:
Drop table employee_data;
Desc employee_data
Select * from employee_data;
DDL commands:
1. Insert required records to all tables. 
2. List all employee details whose salary is > 10000 
QUERY:
Select * from emp_details where salary >10000;
3. List the name of employee whose designation is ‘Professor’ 
QUERY:
Select * from emp_details where designation =’professor’;

4. List the dept name, dept number and employee Id .


QUERY:
Select dept_name, dept_no,emp_id from dept_details;

5. List the name and designation of the employee who receives


salary between 1 lakh and 2 lakhs 
QUERY:
Select emp_name,designation from emp_details where salary
>100000 and salary < 200000;

6. Sort the employee details in ascending order based on the


salary they receive. 
QUERY:
Select * from emp_details order by salary asc;
7. Sort the designation of the employee by descending order and
name of the employee in ascending order. 
QUERY:
Select * from emp_details order by emp_name asc, designation
desc;
8. List the name of the employee whose name starts with ‘d’. 
QUERY:
Select * from emp_details where name like ‘d%’;

9. List the dept name which has ‘E’ in it.  


QUERY:
Select * from emp_details where dept_name like ‘%e%’;

10. Update the mobile number of emp_id=22090 


QUERY:
Update emp_details set phone_no=’1563623’ where
emp_id=’22090’;

You might also like