0% found this document useful (0 votes)
17 views

CS-SQL

computer

Uploaded by

devkannan315
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views

CS-SQL

computer

Uploaded by

devkannan315
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 12

SQL

Write SQL commands for the following:


1. To create a database with your name and class in MySQL.(eg: annXIIN)
create database annXIIN;
2. To use this database in order to create tables in it.
Use annXIIN;
3. To create a table “emp ” having the following specification:
Column Name DataType Size Constraint
empno int Primary Key
ename varchar 10 NOT NULL
gender char Default M
Job Varchar 10
Sal Int
create table empl(empno int, ename varchar(10), gender char, job
varchar(10), sal int);
4. To add a new column ‘comm’ to the table “emp” whose data type is ‘int’.
alter table empl add comm int;
5. To add a new column ‘dob’ after the column ‘gender’ having data type date’.
alter table empl add dob date after gender;
6. To increase the size of column ‘ename’ to 15.
alter table empl modify ename varchar(15);
7. To rename the column ‘job’ to ‘desig’.
alter table empl change column job desig varchar(10);
8. To view the table structure.
describe empl;
9. To insert a row into the “emp” table so that each column has a value.
insert into empl values(1, ‘Aby John David’, ‘M’, ‘1990-09-12’,
‘Salesman’, 45000, 4500);
10.To insert a rows into the “empl” table where ‘comm’ is NULL.
insert into empl(empno, ename, sex, dob, desig, sal) values(13,
‘Zarina Khan’, ‘F’, ‘1989-11-11’, ‘Analyst’, 42500);
11.To increase the salary of all employees by 10 percent.
update emp set sal=sal+sal/10;
12.To reduce the salary of those employees who receive some commission by
500.
update emp set sal=sal-500 where comm is not null;
13.To display all the rows and columns of the “emp” table.
select * from empl;
14.To delete details of those employees who do not receive any commission.
delete from empl where comm is null;
15.To remove the “emp” table from the database.
drop table empl;
Consider the following table:

16.Write the command to display the names of all Managers.

17.Write the command to display the no. and name of those employees who
were hired in the year 1981.

18.Write the command to display the name and annual salary of all
employees.

19.Write the command to display the name and job of employees working in
department 20 and earning more than 1000.
20.Write the command to display the no., name and salary of employees
whose salary is not between 1000 and 2000.

21.Write the command to display the names of employees working in


departments 10 and 20.

22.Write the command to display the names of employees whose name has
the second alphabet ‘A’.

23.Write the command to display the name and job of those employees whose
job does not contain the alphabet ‘A’.
24.Write the command to display the job which has some commission.

25.Write the command to display the names of all salesmen in alphabetical


order.

26.Write the command to display the name, job and salary of employees
working in department 10, in descending order of salary.

27.Write the command to display the latest and oldest date of hiring among
all the employees.
28.Write the command to display the number of employees who have a
manager.

29.Write the command to display the total salary of the employees working in
department 20.

30.Write the command to display the average salary for each department.

31.Write the command to display the department-wise count of employees.

32.Write the command to display the maximum and minimum salary for each
job.
33.Write the command to display the average salary of those departments
whose average salary is more than 500.

34.Write the command to display the department no. and no. of employees in
those departments where the number of employees is less than 5.

35.Write the output of the following SQL commands:


(i) select ename, job from empl where deptno <> 20 and deptno != 30;

(ii) select ename, sal from empl where sal between 800 and 1300;
(iii) select ename, job from empl where ename like ‘%E_’ and job like ‘%E_’;

(iv) select distinct job from empl where comm is null;

(v) select emplno, ename, job from empl where deptno=10 order by hiredate;

(vi) select min(ename), max(ename) from empl;

(vii) select count(*) as “No. of Emp not receiving Comm”


from empl where comm is null;
(viii) select deptno, max(sal), min(sal) from empl where deptno=20 or
deptno=30 group by deptno;

(ix) select deptno, max(sal), min(sal) from empl


group by deptno having max(sal) < =5000 and min(sal) > 1000;

Consider the following tables:


36.Write the command to display the name and title of each worker.

37.Write the command to display the worker id, name, job id and salary of all
workers.

38.Write the command to display the job id and title of those workers whose
sales is more than 1250000.

39.Write the command to display the worker id and sales of those workers
who are vice president.

40.Write the command to display all the columns from both the tables
without any column getting repeated.
(OR)
select * from worker join job using(jobid);
41.Write the command to display all the possible combinations of all the rows
from both the tables.
select * from worker, job;
(OR)
select * from worker join job;
(OR)
select * from worker cross join job;
42.Write the output of the following SQL commands:
(i) select title, count(*) from worker w, job j where w.jobid=j.jobid
group by title;

(ii) select w.jobid, title from worker w, job j where w.jobid=j.jobid


group by j.jobid having avg(sales) > 1250000;

You might also like