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

Create Database Test

The document creates a database called "test" and two tables within it called "EMP" and "DEPT". It then inserts sample data into the tables. It provides 10 SQL queries to retrieve, update, and delete data from the tables. The queries select, filter, join, group, order, and manipulate the data in the tables.

Uploaded by

Rajarshi Pain
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
175 views

Create Database Test

The document creates a database called "test" and two tables within it called "EMP" and "DEPT". It then inserts sample data into the tables. It provides 10 SQL queries to retrieve, update, and delete data from the tables. The queries select, filter, join, group, order, and manipulate the data in the tables.

Uploaded by

Rajarshi Pain
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 5

// create database test

CREATE DATABASE test;

//connect to the database

CONNECT test;

//create table EMP

CREATE TABLE `test`.`EMP` (


`emp_no` INT( 4 ) PRIMARY KEY NOT NULL ,
`emp_name` VARCHAR( 25 ) NULL ,
`degisnation` CHAR( 4 ) NULL ,
`joining_date` DATE NULL ,
`salary` DECIMAL( 7, 2 ) NULL ,
`dept_no` INT( 2 ) NULL ,
);

// create table DEPT

CREATE TABLE `test`.`DEPT` (


`dept_no` INT( 2 ) PRIMARY KEY NOT NULL,
`dept_name` VARCHAR( 25 ) NULL,
`budget` DECIMAL( 15, 2 ) NULL ,
`manager` VARCHAR( 25 ) NULL ,
);

// insert data to table DEPT

INSERT INTO `dept` (`dept_no`, `dept_name`, `budget`, `manager`) VALUES


(1, 'development', '6543210.00', 'R Pain'),
(2, 'testing', '35550.00', 'S Nanda'),
(3, 'support', '876540.50', 'Y'),
(4, 'r&d', '2543210.00', 'X'),
(5, 'training', '976540.50', 'T');

// insert data to table EMP

INSERT INTO `emp` (`emp_no`, `emp_name`, `degisnation`, `joining_date`, `salary`,


`dept_no`) VALUES
(256, 'Y', 'PM', '1980-11-08', '15650.50', 3),
(458, 'Swati', 'ASE', '2000-01-21', '4200.00', 2),
(1000, 'Rajarshi Sankar Pain', 'ASE', '2011-02-21', '2619.00', 5),
(1002, 'Suman Dutta', 'ASE', '2011-01-04', '2619.00', 5),
(1234, 'Rajesh Kumar', 'ITA', '2004-01-04', '4555.00', 1),
(1665, 'T', 'PM', '1985-11-29', '16550.00', 5),
(2548, 'Kundan', 'ITA', '1881-05-18', '8600.00', 3),
(2589, 'Tina Das', 'STL', '1981-01-04', '13000.00', 4),
(3651, 'Krishna Iyer', 'TL', '1991-01-17', '9543.00', 2),
(4514, 'R Pain', 'PM', '1995-08-25', '16550.00', 1),
(5632, 'KK', 'CEO', '1970-01-13', '55000.00', 4),
(7789, 'Paresh Mukherjee ', 'STL', '1981-01-28', '12550.00', 1),
(8521, 'X', 'PM', '1998-12-12', '14500.00', 4),
(9854, 'S Nanda', 'PM', '1990-01-15', '18000.00', 2);

1. Display each employee’s name and date of joining.


Ans: Select emp_name,joining_date from EMP;

2. Display employees earning more than Rs.5,000. Label the column name “Employee”.
Ans: Select emp_name as Employee from EMP where salary>5000;

3. Display all employee names and employee numbers in the alphabetical order of names.
Ans: select emp_no,emp_name from EMP order by emp_name ASC;

4. Display all employee names containing the letter “S”.


Ans: select emp_name from EMP where emp_name like ‘s%’;

5. Display the employees hired in 1981.


Ans: select * from EMP where joining_date like ‘ 1981%’;
6. Display the minimum and maximum salary.
Ans: select MAX(salary) as Max_Salary,MIN(salary) as Min_Salary from EMP;

7. Display the list of employees along with their department name and its manager.

Ans: select EMP.emp_name as Employee,DEPT.dept_name as Deperment ,DEPT.manager as Manager from


EMP,DEPT where EMP.dept_no=DEPT.dept_no;

8. Display the number of different employees listed for each department.

Ans: select DEPT.dept_name as Department,count(emp_name) as Total_Employee from DEPT,EMP where


DEPT.dept_no=EMP.dept_no group by DEPT.dept_name;

9. Delete the records of all the employees hired in 1981 from EMP table.
Ans: delete from EMP where joining_date like ‘1981%’;

10. Update the salary of all the employees to Rs. 10,000.


Ans: update EMP set salary=10000;

You might also like