0% found this document useful (0 votes)
5 views6 pages

Dbms

The document contains SQL commands for creating and populating tables related to companies, employees, and their relationships. It includes queries for retrieving employee details, calculating average salaries, updating salaries, and counting companies based on specific criteria. The structure includes tables for company, employee, emp_company, and manager, along with relevant data inserts and queries for data manipulation and retrieval.

Uploaded by

greenlouisa
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views6 pages

Dbms

The document contains SQL commands for creating and populating tables related to companies, employees, and their relationships. It includes queries for retrieving employee details, calculating average salaries, updating salaries, and counting companies based on specific criteria. The structure includes tables for company, employee, emp_company, and manager, along with relevant data inserts and queries for data manipulation and retrieval.

Uploaded by

greenlouisa
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 6

DATABASE SQL FILE

CREATE TABLE `company` (

`cname` varchar(50) NOT NULL,

`city` varchar(50) NOT NULL

) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;

--

-- Dumping data for table `company`

--

INSERT INTO `company` (`cname`, `city`) VALUES

('Beximco', 'Dhaka'),

('Beximco', 'Rangpur'),

('Opsonin', 'Chittagong'),

('Opsonin', 'Rangpur'),

('Square', 'Bogra'),

('Square', 'Chittagong');

-- --------------------------------------------------------

--

-- Table structure for table `employee`

--

CREATE TABLE `employee` (

`ename` varchar(50) NOT NULL,

`street` varchar(50) DEFAULT NULL,

`city` varchar(50) DEFAULT NULL

) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;


--

-- Dumping data for table `employee`

--

INSERT INTO `employee` (`ename`, `street`, `city`) VALUES

('Adil', 'Link Road', 'Bogra'),

('Jahid', 'Tajmahal Road', 'Chittagong'),

('Matin', 'Arambag', 'Dhaka'),

('Nashid', 'Station Road', 'Rangpur'),

('Rahim', 'Nasirabad', 'Chittagong'),

('Rini', 'Station Road', 'Rangpur');

-- --------------------------------------------------------

--

-- Table structure for table `emp_company`

--

CREATE TABLE `emp_company` (

`ename` varchar(50) DEFAULT NULL,

`caname` varchar(50) DEFAULT NULL,

`salary` int(20) NOT NULL

) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;

--

-- Dumping data for table `emp_company`

--
INSERT INTO `emp_company` (`ename`, `caname`, `salary`) VALUES

('Adil', 'Square', 20000),

('Nashid', 'Opsonin', 25000),

('Matin', 'Beximco', 17000),

('Jahid', 'Square', 30000),

('Rahim', 'Opsonin', 23000),

('Rini', 'Beximco', 12000);

-- --------------------------------------------------------

--

-- Table structure for table `manager`

--

CREATE TABLE `manager` (

`ename` varchar(50) DEFAULT NULL,

`mname` varchar(50) DEFAULT NULL,

`shift` varchar(50) DEFAULT NULL

) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;

--

-- Dumping data for table `manager`

--

INSERT INTO `manager` (`ename`, `mname`, `shift`) VALUES

('Adil', 'Sabbir', 'Morning'),

('Nashid', 'Nashid', 'Day'),

('Matin', 'Sabbir', 'Morning'),

('Jahid', 'Ripon', 'Night'),


('Rahim', 'Shimu', 'Night'),

('Rini', 'Shimu', 'Day');

--

-- Indexes for dumped tables

--

--

-- Indexes for table `company`

--

ALTER TABLE `company`

ADD PRIMARY KEY (`cname`,`city`);

--

-- Indexes for table `employee`

--

ALTER TABLE `employee`

ADD PRIMARY KEY (`ename`);

--

-- Indexes for table `emp_company`

--

ALTER TABLE `emp_company`

ADD KEY `ename` (`ename`);

-- Indexes for table `manager`

--

ALTER TABLE `manager`

ADD KEY `ename` (`ename`);


Queary ANS:
1.Find names, street address and cities of residence of all employees who work under
manager Sabbir.
SELECT E.ename, E.street, E.city
FROM employee AS E
JOIN manager AS M ON E.ename = M.ename
WHERE M.mname = 'Sabbir';
2.Find The names and salary of each employees who lives in Rangpur.
SELECT EC.caname, EC.ename, EC.salary
FROM emp_company AS EC
JOIN employee AS E ON EC.ename = E.ename
WHERE E.city = 'Rangpur';
3.Find the names of the employees living in the same city whare Rahim is residing.
SELECT E1.ename
FROM employee AS E1
JOIN employee AS E2 ON E1.city = E2.city
WHERE E2.ename = 'Rahim';
4.Display The average salary of each company.
SELECT EC.caname, AVG(EC.salary) AS AvgSalary
FROM emp_company AS EC
GROUP BY EC.caname;

5.Increase the salary of employees by 10% for the Opsonin company.


UPDATE emp_company
SET salary = (salary * 110) / 100
WHERE caname = 'Opsonin';

6.Find the number of companies whare the company name starts with S or O.
SELECT COUNT(*) AS CountOfCompanies
FROM `company`
WHERE cname LIKE 'S%' OR cname LIKE 'O%';

You might also like