Академический Документы
Профессиональный Документы
Культура Документы
SOLUTION
Enter password: ****
Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved.
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> create database MYORG;
Database changed
+------------------+
| MONTH(CURDATE()) |
+------------------+
| 6|
+------------------+
+---------------------+
| sysdate() |
+---------------------+
| 2019-06-15 16:17:05 |
+---------------------+
+----------+
| pow(6,3) |
+----------+
| 216 |
+----------+
, Location varchar(25));
+--------+----------+-------+-----------+
+--------+----------+-------+-----------+
+--------+----------+-------+-----------+
mysql> create table emp(EmpID int primary key, EmpName varchar(30) Not Null,
Designation char(10), DOJ date, sal int check(sal>1000), comm int, DeptID int re
ferences DEPT(DeptID));
mysql> insert into emp values(8369, "SMITH", "CLERK", "1990-12-18", 1050.00, 200
.00, 10);
00.00, 20);
0, NULL, 30);
400.00, 20);
, NULL, 10);
0.00, 10);
ULL, 20);
,0.00, 30);
+-------+-----------+-------------+------------+---------+------+--------+
+-------+-----------+-------------+------------+---------+------+--------+
+-------+-----------+-------------+------------+---------+------+--------+
+-----------+---------+
| EmpName | sal |
+-----------+---------+
| MAHADEVAN | 2985.00 |
| BINA | 2850.00 |
| AMIR | 5000.00 |
| SHIVANSH | 2450.00 |
| SCOTT | 3000.00 |
+-----------+---------+
+-------+-----------+-------------+------------+---------+------+--------+
+-------+-----------+-------------+------------+---------+------+--------+
+-------+-----------+-------------+------------+---------+------+--------+
mysql> select empname, sal from emp where sal not between 2500 and 4000;
+----------+---------+
| empname | sal |
+----------+---------+
| SMITH | 1050.00 |
| ANYA | 1600.00 |
| MOMIN | 1250.00 |
| AMIR | 5000.00 |
| KULDEEP | 1500.00 |
| SHIVANSH | 2450.00 |
+----------+---------+
mysql> select empname from emp where empname like("_A%") order by empname asc;
+-----------+
| empname |
+-----------+
| MAHADEVAN |
+-----------+
mysql> select sal+comm as "Total Incentive" from emp where comm is not null;
+-----------------+
| Total Incentive |
+-----------------+
| 1250.00 |
| 1900.00 |
| 1650.00 |
| 3100.00 |
| 1500.00 |
| 3150.00 |
+-----------------+
+-------------+
| designation |
+-------------+
| CLERK |
| SALESMAN |
| MANAGER |
| PRESIDENT |
| ANALYST |
+-------------+
+----------+
| count(*) |
+----------+
| 3|
| 3|
| 3|
+----------+
+-----------+
| EmpName |
+-----------+
| SMITH |
| ANYA |
| MAHADEVAN |
| MOMIN |
| BINA |
| AMIR |
| KULDEEP |
| SHIVANSH |
| SCOTT |
+-----------+
+-------+-----------+-------------+------------+------+------+--------+
+-------+-----------+-------------+------------+------+------+--------+
+-------+-----------+-------------+------------+------+------+--------+
+-------+-----------+-------------+------------+------+------+--------+
+-------+-----------+-------------+------------+------+------+--------+
+----------+
| max(sal) |
+----------+
| 3000 |
| 5000 |
| 2985 |
+----------+
+----------+----------+-----------+
+----------+----------+-----------+
+----------+----------+-----------+
+-------------+
| EmpName |
+-------------+
| MrANYA |
| MrMAHADEVAN |
| MrMOMIN |
| MrBINA |
| MrAMIR |
| MrKULDEEP |
+-------------+
+----------+
| sum(sal) |
+----------+
| NULL |
+----------+
+----------+
| sum(sal) |
+----------+
| NULL |
+----------+
+-------+-------------+-------------+------------+------+------+--------+
+-------+-------------+-------------+------------+------+------+--------+
+-------+-------------+-------------+------------+------+------+--------+
+-------+-------------+-------------+------------+------+------+--------+
+-------+-------------+-------------+------------+------+------+--------+
+-------+-------------+-------------+------------+------+------+--------+--------+----------+-------+----------+-------+
| EmpID | EmpName | Designation | DOJ | sal | comm | DeptID | DeptID | DeptName | MgrID |
Location | state |
+-------+-------------+-------------+------------+------+------+--------+--------+----------+-------+----------+-------+
| 8566 | MrMAHADEVAN | MANAGER | 1991-04-02 | 3433 | 100 | 30 | 30 | Accounts | 8882 |
Delhi | NULL |
+-------+-------------+-------------+------------+------+------+--------+--------+----------+-------+----------+-------+
QUESTION II
1. Write a command to display the system date .
2. Write a command to display the name of current month
3. Write command to print the day of the week of your birthday in the year
2015
4. Write the command to round off value 15.193 to nearest tens ie.20.
5. Write a query to find the out the result of 6^3.
6. Create and open database named MYORG.
7. Create a table name EMP with following structure (EMPID Primary Key )
9. Write a query to display all the records with all the columns .
10.Write a query to display EmpName and sal of employees whose salary are
greater than or equal to 2200.
11.Write a query to display details of employees who are not getting
commission .
12.Write a query to display employee name and salary of those employees
who don’t have their salary in range of 2500 to 4000.
13.Write a query to display the name of employee whose name contains “a”
as third alphabet in ascending order of employee names.
14.Write a query to display the ENAME and sal with 50% of sal as DA.
15.Display the distinct job titles offered by the organization
16.Display the names of employees who are working as manager or analyst .
17.Display the name of employees who join on or after 01-05-1991.
18.Display the employee record in order by DOJ.
19.Display the distinct designation in the organization .
SOLUTION
Enter password: *********
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
+---------------------+
| sysdate() |
+---------------------+
| 2019-06-27 19:31:46 |
+---------------------+
+-------------------------+
| dayofweek("2015-12-30") |
+-------------------------+
| 4|
+-------------------------+
+-----------------+
| round(15.193,2) |
+-----------------+
| 15.19 |
+-----------------+
1 row in set (0.00 sec)
+-----------------+
| round(15.193,1) |
+-----------------+
| 15.2 |
+-----------------+
+----------+
| pow(6,3) |
+----------+
| 216 |
+----------+
Database changed
mysql> create table Emp(EmpID int primary key, EmpName varchar(25), Designation char(10), DOJ date,
sal int, comm int);
mysql> insert into Emp values(8499, "ANYA", "SALESMAN", "1991-02-20", 1600.00, 300.00);
mysql> insert into Emp values(8521, "SETH", "SALESMAN", "1991-02-22", 1250.00, 500.00);
mysql> insert into Emp values(8566, "MAHADEVAN", "MANAGER", "1991-04-02", 2985.00, NULL);
mysql> insert into Emp values(8654, "MOMIN", "SALESMAN", "1991-09-28", 1250.00, 400.00);
mysql> insert into Emp values(8698, "BINA", "MANAGER", "1991-05-01", 2850.00, NULL);
mysql> insert into Emp values(8882, "SHIVANSH", "MANAGER", "1991-06-09", 2450.00, NULL);
mysql> insert into Emp values(8888, "SCOTT", "ANALYST", "1992-12-09", 3000.00, NULL);
mysql> insert into Emp values(8839, "AMIR", "PRESIDENT", "1991-11-18", 5000.00, NULL);
mysql> insert into Emp values(8844, "KULDEEP", "SALESMAN", "1991-09-08", 1500.00, 0.00);
Query OK, 1 row affected (0.00 sec)
+-------+-----------+-------------+------------+------+------+
+-------+-----------+-------------+------------+------+------+
+-------+-----------+-------------+------------+------+------+
+-----------+------+
| EMPNAME | SAL |
+-----------+------+
| MAHADEVAN | 2985 |
| BINA | 2850 |
| AMIR | 5000 |
| SHIVANSH | 2450 |
| SCOTT | 3000 |
+-----------+------+
5 rows in set (0.00 sec)
+-------+-----------+-------------+------------+------+------+
+-------+-----------+-------------+------------+------+------+
+-------+-----------+-------------+------------+------+------+
mysql> SELECT EMPNAME, SAL FROM EMP WHERE SAL BETWEEN ! 2500 AND 4000;
+-----------+------+
| EMPNAME | SAL |
+-----------+------+
| SMITH | 800 |
| ANYA | 1600 |
| SETH | 1250 |
| MAHADEVAN | 2985 |
| MOMIN | 1250 |
| BINA | 2850 |
| KULDEEP | 1500 |
| SHIVANSH | 2450 |
| SCOTT | 3000 |
+-----------+------+
9 rows in set (0.00 sec)
mysql> SELECT EMPNAME FROM EMP WHERE EMPNAME LIKE("__A%") ORDER BY EMPNAME ASC;
+-----------+------+-----------+
| EMPNAME | SAL | DA |
+-----------+------+-----------+
+-----------+------+-----------+
+-------------+
| DESIGNATION |
+-------------+
| CLERK |
| SALESMAN |
| MANAGER |
| PRESIDENT |
| ANALYST |
+-------------+
+-----------+
| EMPNAME |
+-----------+
| MAHADEVAN |
| BINA |
| SHIVANSH |
| SCOTT |
+-----------+
+-----------+
| EMPNAME |
+-----------+
| SMITH |
| ANYA |
| SETH |
| MAHADEVAN |
| MOMIN |
| BINA |
| AMIR |
| KULDEEP |
| SHIVANSH |
| SCOTT |
+-----------+
+-------+-----------+-------------+------------+------+------+
+-------+-----------+-------------+------------+------+------+
+-------+-----------+-------------+------------+------+------+
+-------------+
| DESIGNATION |
+-------------+
| CLERK |
| SALESMAN |
| MANAGER |
|
DeptID DeptName MgrID Location
Number VarChar(25) Number Char(40)
PRESIDENT |
| ANALYST |
+------
------- DeptID DeptName MgrID Location
+ 10 Sales 8566 Mumbai
5
20 Personnel 8698 Delhi
rows 30 Accounts 8882 Delhi
in set 40 Research 8839 Bangalore
(0.00
sec)
QUESTION III
1. Open database MYORG.
2. Create the following table DEPT with DeptId as Primary Key .
SOLUTION
Enter password: *********
Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved.
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
Database changed
+-----------------+
mysql> create table DEPT(DeptID int, DeptName varchar, MgrID int, Location char(40));
Query OK, 0 rows affected (0.01 sec)
+-----------------+
+-----------------+
+-----------------+
+-----------------+
+-----------------+
+-----------------+
+----------+----------+-----------+
+----------+----------+-----------+
+----------+----------+-----------+
+--------------------+
| COUNT(DESIGNATION) |
+--------------------+
| 1|
+--------------------+
+-----------+------+------------+
+-----------+------+------------+
+----------+
| COUNT(*) |
+----------+
| 6|
+----------+
+-----------+
| AVG(SAL) |
+-----------+
| 2268.5000 |
| 2268.5000 |
| 2268.5000 |
| 2268.5000 |
+-----------+
+----------+
| COUNT(*) |
+----------+
| 3|
| 3|
| 2|
| 2|
+----------+
mysql> SELECT MAX(SAL) FROM EMP,DEPT WHERE DEPT.DEPTID = EMP.DEPTID GROUP BY DEPTNAME;
+----------+
| MAX(SAL) |
+----------+
| 2450 |
| 2850 |
| 3000 |
| 5000 |
+----------+
+-----------+-------------+-----------+
+-----------+-------------+-----------+
+-----------+-------------+-----------+
+----------+
| COUNT(*) |
+----------+
| 2|
+----------+
mysql> SELECT EMPNAME FROM EMP,DEPT WHERE LOCATION = "DELHI" AND DEPT.DEPTID =
EMP.DEPTID;
+----------+
| EMPNAME |
+----------+
| ANYA |
| BINA |
| KULDEEP |
| SETH |
| SHIVANSH |
+----------+
mysql> SELECT EMPNAME FROM EMP,DEPT WHERE DEPTNAME = "SALES" AND DEPT.DEPTID =
EMP.DEPTID;
+---------+
| EMPNAME |
+---------+
| SMITH |
| MOMIN |
| AMIR |
+---------+
mysql> SELECT EMPNAME FROM EMP,DEPT WHERE LOCATION="DELHI" AND SAL>5000 AND
DEPT.DEPTID = EMP.DEPTID;
mysql> SELECT * FROM EMP,DEPT WHERE DEPTNAME = "RESEARCH" AND DEPT.DEPTID = EMP.DEPTID;
+-------+-----------+-------------+------------+------+------+--------+--------+----------+-------+-----------+
| EmpID | EmpName | Designation | DOJ | sal | comm | DeptID | DeptID | DeptName | MgrID |
Location |
+-------+-----------+-------------+------------+------+------+--------+--------+----------+-------+-----------+
+-------+-----------+-------------+------------+------+------+--------+--------+----------+-------+-----------+
SOLUTION
Enter password: *********
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.5.16 MySQL Community Server (GPL)
Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> create table order(orderno int(5) Primary Key, CustNo int(7) references c
ustomer(CustID), ItemName varchar(30), Qty int(5) check(Qty>=2), Price decimal(6
,2) Not Null);
mysql> create table demand(orderno int(5) Primary Key, CustNo int(7) references
customer(CustID), ItemName varchar(30), Qty int(5) check(Qty>=2), Price decimal(
6,2) Not Null);
Query OK, 0 rows affected (0.42 sec)
mysql> insert into demand values (6857, 123, "Nestle Dahi", 10, 800.00);
Query OK, 1 row affected (0.34 sec)
mysql> insert into demand values (6754, 12, "Blue Lays", 50, 1500.00);
Query OK, 1 row affected (0.09 sec)
mysql> insert into demand values (8754, 1, "Hide & Seek", 15, 500.00);
Query OK, 1 row affected (0.08 sec)
QUESTION I
31) Create and open database named MYORG.
32) Write a command to display the name of current month
33) Write command to display the system date
34) Write a query to find out the result of 6^3.
35) Write command to show the tables in the MYORG database.
36) Add one column state of datatype varchar and size 30 to table DEPT.
37) Create a table name EMP with following structure:
38) Insert the first record in table EMP (8369,SMITH,CLERK,18-12-
1990,800.00, 200.00, 10)
39) Write a query to display EmpName and sal of employees whose
salary are greater than or equal to 2200
40) Write a query to display the details of employee who are not getting
commission .
41) Write a query to display employee name and salary of those
employees who don’t have their salary in rang of 2500 to 4000.
42) Write a query to display the name of employee whose name contains
“A” as third alphabet in ascending order of employee names.
43) Display the sum of salary and commissions of employees as “Total
Incentive”.
44) Show the average salary for all departments with more than 5
working people .
45) Display the distinct designation offered by the organization.
46) List the count of employees grouped by DeptID
47) Display the names of employees who join on or after “01-05-1991”
48) Display the employee record in order by DOJ.
49) Display the maximum salary of employees in each department.
50) Update all the records as add “MR.” with EmpName .
51) Display the name of employees who are working in sales department
.
52) Drop the emp table.
53) Delete all the records who is working as “CLERK”.
54) Show the minimum,maximum and average salary of managers .
55) Increase the salary of managers by 15%.
56) To display the name of those employees whose location is “delhi”.
57) To display total salary of employees of sales department.
58) To show details of employees who joined in the year “1991”.
59) Delete all the records who is working as “SALESMAN” AND SALARY
MORE THAN 1500.
60) SET THE COMMISSION AS 100 WHO ARE NOT GETTING ANY
COMMISSION.
SOLUTION
Enter password: ****
Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved.
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
Database changed
+------------------+
| MONTH(CURDATE()) |
+------------------+
| 6|
+------------------+
| sysdate() |
+---------------------+
| 2019-06-15 16:17:05 |
+---------------------+
+----------+
| pow(6,3) |
+----------+
| 216 |
+----------+
mysql> create table DEPT(DeptID int Primary Key, DeptName varchar(25), MgrID int
, Location varchar(25));
+--------+----------+-------+-----------+
+--------+----------+-------+-----------+
+--------+----------+-------+-----------+
mysql> create table emp(EmpID int primary key, EmpName varchar(30) Not Null,
Designation char(10), DOJ date, sal int check(sal>1000), comm int, DeptID int re
ferences DEPT(DeptID));
mysql> insert into emp values(8369, "SMITH", "CLERK", "1990-12-18", 1050.00, 200
.00, 10);
Query OK, 1 row affected (0.02 sec)
00.00, 20);
0, NULL, 30);
400.00, 20);
0.00, 30);
, NULL, 10);
0.00, 10);
ULL, 20);
Query OK, 1 row affected (0.03 sec)
,0.00, 30);
+-------+-----------+-------------+------------+---------+------+--------+
+-------+-----------+-------------+------------+---------+------+--------+
+-------+-----------+-------------+------------+---------+------+--------+
+-----------+---------+
| EmpName | sal |
+-----------+---------+
| MAHADEVAN | 2985.00 |
| BINA | 2850.00 |
| AMIR | 5000.00 |
| SHIVANSH | 2450.00 |
| SCOTT | 3000.00 |
+-----------+---------+
+-------+-----------+-------------+------------+---------+------+--------+
+-------+-----------+-------------+------------+---------+------+--------+
+-------+-----------+-------------+------------+---------+------+--------+
mysql> select empname, sal from emp where sal not between 2500 and 4000;
+----------+---------+
| empname | sal |
+----------+---------+
| SMITH | 1050.00 |
| ANYA | 1600.00 |
| MOMIN | 1250.00 |
| AMIR | 5000.00 |
| KULDEEP | 1500.00 |
| SHIVANSH | 2450.00 |
+----------+---------+
mysql> select empname from emp where empname like("_A%") order by empname asc;
+-----------+
| empname |
+-----------+
| MAHADEVAN |
+-----------+
mysql> select sal+comm as "Total Incentive" from emp where comm is not null;
+-----------------+
| Total Incentive |
+-----------------+
| 1250.00 |
| 1900.00 |
| 1650.00 |
| 3100.00 |
| 1500.00 |
| 3150.00 |
+-----------------+
+-------------+
| designation |
+-------------+
| CLERK |
| SALESMAN |
| MANAGER |
| PRESIDENT |
| ANALYST |
+-------------+
+----------+
| count(*) |
+----------+
| 3|
| 3|
| 3|
+----------+
+-----------+
| EmpName |
+-----------+
| SMITH |
| ANYA |
| MAHADEVAN |
| MOMIN |
| BINA |
| AMIR |
| KULDEEP |
| SHIVANSH |
| SCOTT |
+-----------+
+-------+-----------+-------------+------------+------+------+--------+
+-------+-----------+-------------+------------+------+------+--------+
+-------+-----------+-------------+------------+------+------+--------+
+-------+-----------+-------------+------------+------+------+--------+
+----------+
| max(sal) |
+----------+
| 3000 |
| 5000 |
| 2985 |
+----------+
+----------+----------+-----------+
+----------+----------+-----------+
+----------+----------+-----------+
1 row in set (0.00 sec)
+-------------+
| EmpName |
+-------------+
| MrANYA |
| MrMAHADEVAN |
| MrMOMIN |
| MrBINA |
| MrAMIR |
| MrKULDEEP |
+-------------+
+----------+
| sum(sal) |
+----------+
| NULL |
+----------+
+----------+
| sum(sal) |
+----------+
| NULL |
+----------+
+-------+-------------+-------------+------------+------+------+--------+
+-------+-------------+-------------+------------+------+------+--------+
+-------+-------------+-------------+------------+------+------+--------+
+-------+-------------+-------------+------------+------+------+--------+
+-------+-------------+-------------+------------+------+------+--------+
+-------+-------------+-------------+------------+------+------+--------+--------+----------+-------+----------+-------+
| EmpID | EmpName | Designation | DOJ | sal | comm | DeptID | DeptID | DeptName | MgrID |
Location | state |
+-------+-------------+-------------+------------+------+------+--------+--------+----------+-------+----------+-------+
+-------+-------------+-------------+------------+------+------+--------+--------+----------+-------+----------+-------+
28. Write a query to display all the records with all the columns .
29.Write a query to display EmpName and sal of employees whose salary are
greater than or equal to 2200.
30.Write a query to display details of employees who are not getting
commission .
31.Write a query to display employee name and salary of those employees
who don’t have their salary in range of 2500 to 4000.
32.Write a query to display the name of employee whose name contains “a”
as third alphabet in ascending order of employee names.
33.Write a query to display the ENAME and sal with 50% of sal as DA.
34.Display the distinct job titles offered by the organization
35.Display the names of employees who are working as manager or analyst .
36.Display the name of employees who join on or after 01-05-1991.
37.Display the employee record in order by DOJ.
38.Display the distinct designation in the organization .
SOLUTION
Enter password: *********
Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved.
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
+---------------------+
| sysdate() |
+---------------------+
| 2019-06-27 19:31:46 |
+---------------------+
+-------------------------+
| dayofweek("2015-12-30") |
+-------------------------+
| 4|
+-------------------------+
+-----------------+
| round(15.193,2) |
+-----------------+
| 15.19 |
+-----------------+
+-----------------+
| round(15.193,1) |
+-----------------+
| 15.2 |
+-----------------+
+----------+
| pow(6,3) |
+----------+
| 216 |
+----------+
Database changed
mysql> create table Emp(EmpID int primary key, EmpName varchar(25), Designation char(10), DOJ date,
sal int, comm int);
mysql> insert into Emp values(8369, "SMITH", "CLERK", "1990-12-18", 800.00, NULL);
mysql> insert into Emp values(8499, "ANYA", "SALESMAN", "1991-02-20", 1600.00, 300.00);
mysql> insert into Emp values(8521, "SETH", "SALESMAN", "1991-02-22", 1250.00, 500.00);
mysql> insert into Emp values(8566, "MAHADEVAN", "MANAGER", "1991-04-02", 2985.00, NULL);
mysql> insert into Emp values(8654, "MOMIN", "SALESMAN", "1991-09-28", 1250.00, 400.00);
Query OK, 1 row affected (0.00 sec)
mysql> insert into Emp values(8698, "BINA", "MANAGER", "1991-05-01", 2850.00, NULL);
mysql> insert into Emp values(8882, "SHIVANSH", "MANAGER", "1991-06-09", 2450.00, NULL);
mysql> insert into Emp values(8888, "SCOTT", "ANALYST", "1992-12-09", 3000.00, NULL);
mysql> insert into Emp values(8839, "AMIR", "PRESIDENT", "1991-11-18", 5000.00, NULL);
mysql> insert into Emp values(8844, "KULDEEP", "SALESMAN", "1991-09-08", 1500.00, 0.00);
+-------+-----------+-------------+------------+------+------+
+-------+-----------+-------------+------------+------+------+
+-------+-----------+-------------+------------+------+------+
+-----------+------+
| EMPNAME | SAL |
+-----------+------+
| MAHADEVAN | 2985 |
| BINA | 2850 |
| AMIR | 5000 |
| SHIVANSH | 2450 |
| SCOTT | 3000 |
+-----------+------+
+-------+-----------+-------------+------------+------+------+
+-------+-----------+-------------+------------+------+------+
+-------+-----------+-------------+------------+------+------+
+-----------+------+
| EMPNAME | SAL |
+-----------+------+
| SMITH | 800 |
| ANYA | 1600 |
| SETH | 1250 |
| MAHADEVAN | 2985 |
| MOMIN | 1250 |
| BINA | 2850 |
| KULDEEP | 1500 |
| SHIVANSH | 2450 |
| SCOTT | 3000 |
+-----------+------+
mysql> SELECT EMPNAME FROM EMP WHERE EMPNAME LIKE("__A%") ORDER BY EMPNAME ASC;
+-----------+------+-----------+
| EMPNAME | SAL | DA |
+-----------+------+-----------+
+-----------+------+-----------+
+-------------+
| DESIGNATION |
+-------------+
| CLERK |
| SALESMAN |
| MANAGER |
| PRESIDENT |
| ANALYST |
+-------------+
+-----------+
| EMPNAME |
+-----------+
| MAHADEVAN |
| BINA |
| SHIVANSH |
| SCOTT |
+-----------+
+-----------+
| EMPNAME |
+-----------+
| SMITH |
| ANYA |
| SETH |
| MAHADEVAN |
| MOMIN |
| BINA |
| AMIR |
| KULDEEP |
| SHIVANSH |
| SCOTT |
+-----------+
+-------+-----------+-------------+------------+------+------+
+-------+-----------+-------------+------------+------+------+
|
8882 DeptID DeptName MgrID Location
| Number VarChar(25) Number Char(40)
SHIVANSH | MANAGER | 1991-06-09 | 2450 | NULL |
+-------+-----------+-------------+------------+------+------+
+-------------+
| DESIGNATION |
+-------------+
| CLERK |
| SALESMAN |
| MANAGER |
| PRESIDENT |
| ANALYST |
+-------------+
QUESTION III
21.Open database MYORG.
22.Create the following table DEPT with DeptId as Primary Key .
23.Insert the following in the Dept Table:
SOLUTION
Enter password: *********
Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved.
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
Database changed
+-----------------+
mysql> create table DEPT(DeptID int, DeptName varchar, MgrID int, Location char(40));
+-----------------+
+-----------------+
+-----------------+
+-----------------+
+-----------------+
mysql> alter table EMP add DeptID(int);
+-----------------+
+----------+----------+-----------+
+----------+----------+-----------+
+----------+----------+-----------+
+--------------------+
| COUNT(DESIGNATION) |
+--------------------+
| 1|
+--------------------+
+-----------+------+------------+
+-----------+------+------------+
+-----------+------+------------+
+----------+
| COUNT(*) |
+----------+
| 6|
+----------+
+-----------+
| AVG(SAL) |
+-----------+
| 2268.5000 |
| 2268.5000 |
| 2268.5000 |
| 2268.5000 |
+-----------+
+----------+
| COUNT(*) |
+----------+
| 3|
| 3|
| 2|
| 2|
+----------+
mysql> SELECT MAX(SAL) FROM EMP,DEPT WHERE DEPT.DEPTID = EMP.DEPTID GROUP BY DEPTNAME;
+----------+
| MAX(SAL) |
+----------+
| 2450 |
| 2850 |
| 3000 |
| 5000 |
+----------+
4 rows in set (0.00 sec)
+-----------+-------------+-----------+
+-----------+-------------+-----------+
+-----------+-------------+-----------+
+----------+
| COUNT(*) |
+----------+
| 2|
+----------+
+----------+
| EMPNAME |
+----------+
| ANYA |
| BINA |
| KULDEEP |
| SETH |
| SHIVANSH |
+----------+
mysql> SELECT EMPNAME FROM EMP,DEPT WHERE DEPTNAME = "SALES" AND DEPT.DEPTID =
EMP.DEPTID;
+---------+
| EMPNAME |
+---------+
| SMITH |
| MOMIN |
| AMIR |
+---------+
mysql> SELECT EMPNAME FROM EMP,DEPT WHERE LOCATION="DELHI" AND SAL>5000 AND
DEPT.DEPTID = EMP.DEPTID;
mysql> SELECT * FROM EMP,DEPT WHERE DEPTNAME = "RESEARCH" AND DEPT.DEPTID = EMP.DEPTID;
+-------+-----------+-------------+------------+------+------+--------+--------+----------+-------+-----------+
| EmpID | EmpName | Designation | DOJ | sal | comm | DeptID | DeptID | DeptName | MgrID |
Location |
+-------+-----------+-------------+------------+------+------+--------+--------+----------+-------+-----------+
Column Name Cust ID Cust Name Cust Add Cust City Cust Phone
Datatype Number Varchar Varchar Varchar Varchar
Length 7 30 40 30 10
Constraints Primary Not Null
| 8566 | MAHADEVAN | MANAGER | 1991-04-02 | 2985 | NULL | 40 | 40 | RESEARCH | 8839 |
BANGALORE |
+-------+-----------+-------------+------------+------+------+--------+--------+----------+-------+-----------+
QUESTION IV
16.Create table Customer as per following table structure:
SOLUTION
Column Name Order No. Cust No. Item Name Qty. Price
DataType Number Number Varchar Number Number
Length 5 7 30 5 6,2
Constraints Primary <=2 Not Null
Enter password: *********
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.5.16 MySQL Community Server (GPL)
Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> create table order(orderno int(5) Primary Key, CustNo int(7) references c
ustomer(CustID), ItemName varchar(30), Qty int(5) check(Qty>=2), Price decimal(6
,2) Not Null);
mysql> create table demand(orderno int(5) Primary Key, CustNo int(7) references
customer(CustID), ItemName varchar(30), Qty int(5) check(Qty>=2), Price decimal(
6,2) Not Null);
Query OK, 0 rows affected (0.42 sec)
mysql> insert into demand values (6857, 123, "Nestle Dahi", 10, 800.00);
Query OK, 1 row affected (0.34 sec)
mysql> insert into demand values (6754, 12, "Blue Lays", 50, 1500.00);
Query OK, 1 row affected (0.09 sec)
mysql> insert into demand values (8754, 1, "Hide & Seek", 15, 500.00);
Query OK, 1 row affected (0.08 sec)