ODBA Lab Questions
ODBA Lab Questions
Assignment-1:
1 01-FEB-13 5000
2 01-FEB-13 3000
3 01-FEB-13 4000
1 01-JAN-13 4500
2 01-JAN-13 3500
-----------------------------------------------------------------------------------------------------------------
Assignment-3:
1. Create 4 tables
employee(employee-name, street, city)
3
works(employee-name, company-name, salary)
company(company-name, city)
manages(employee-name, manager-name)
Give an expression in SQL for each of the following queries:
a) Find the names, street address, and cities of residence for all employees who work for 'First Bank
Corporation' and earn more than 10,000.
b) Find the names of all employees in the database who live in the same cities as the companies for
which they work.
c) Find the names of all employees in the database who live in the same cities and on the same streets
as do their managers.
d) Find the names of all employees in the database who do not work for 'First Bank Corporation'.
Assume that all people work for exactly one company.
e) Find the names of all employees in the database who earn more than every employee of 'Small Bank
Corporation'. Assume that all people work for at most one company.
f) Assume that the companies may be located in several cities. Find all companies located in every city
in which 'Small Bank Corporation' is located.
g) Find the names of all employees who earn more than the average salary of all employees of their
company. Assume that all people work for at most one company.
h) Find the name of the company that has the smallest payroll.
-------------------------------------------------------------------------------------------------------------------
Assignment-4:
View
====
Table: Employee
EMPNO ENAME SAL JOB DEPTNO JOIN_DATE
130 JOHN 4000 MANAGER 10 2014-03-07
140 RAKHI 3000 TEACHER 20 2014-09-07
150 MANAGER 30
160 VC 40
170 4000 MANAGER 50
180 8000 PRINCIPAL 60
Table: Dapt
DEPTNO DNAME LOCATION
10 RESEARCH BBSR
20 CSE BLS
Having clause
1. To display the deptno for which total amount of salary is greater than 10,000.
2 To display the deptno along with their total salary for which total salary is greater then 10000
corresponding to deptno 10,20.
order by clause
3. To display the employee information in the ascending order of the empno.
4. To display the employee information in the descending order of the salary.
5.To display the employee information in the ascending order of the deptno,descending order of salary.
4
Union
6. To display in deptno the jobs 10 or 20.
7. To display the jobs from emp where deptno 10 or 20
Intersect.
8.To display the jobs in deptno 10 and 20.
9.To display the jobs in deptno 10 and (20or 30 )
Minus
10. To Display the jobs in deptno 10 and not in 20
11. to list the jobs which are unique to dept 10 as compare to 20 and 30
12. Create a view with name empview for Employee table with EMPNO, ENAME, SAL.
13. Create a view name emp10 for Employee table with DEPTNO 10.
14. Insert a new record into empview.
15. To update record of empview.
16. To display the contents of emp10.
-------------------------------------------------------------------------------------------------------------------
Assignment-5:
1. Create table of CUSTOMERS( ID integer NOT NULL,NAME of size 20 NOT NULL,AGE integer
NOT NULL,ADDRESS of size 25 ,SALARY with decimalpoints(18, 2), PRIMARY KEY is ID.
2. If ORDERS table has already been created, and the foreign key has not yet been set
(Customer_ID)as foreign key by altering a table.
3. Drop a FOREIGN KEY constraint.
4. Insert table records CUSTOMERS
+----+----------+-----+-----------+----------+
| ID | NAME | AGE | ADDRESS | SALARY |
+----+----------+-----+-----------+----------+
| 1 | Ramesh | 32 | Ahmedabad | 2000.00 |
| 2 | Khilan | 25 | Delhi | 1500.00 |
| 3 | kaushik | 23 | Kota | 2000.00 |
| 4 | Chaitali | 25 | Mumbai | 6500.00 |
| 5 | Hardik | 27 | Bhopal | 8500.00 |
| 6 | Komal | 22 | MP | 4500.00 |
| 7 | Muffy | 24 | Indore | 10000.00 |
+----+----------+-----+-----------+----------+
Insert table records USTOMERS ORDERS
+-----+---------------------+-------------+--------+
|OID | DATE | CUSTOMER_ID | AMOUNT |
+-----+---------------------+-------------+--------+
| 102 | 2009-10-08 00:00:00 | 3 | 3000 |
| 100 | 2009-10-08 00:00:00 | 3 | 1500 |
| 101 | 2009-11-20 00:00:00 | 2 | 1560 |
| 103 | 2008-05-20 00:00:00 | 4 | 2060 |
+-----+---------------------+-------------+--------+
5. Join these above 2 tables.
6. Calculate the avarage salary of customers.
7. Count the no of records present in the customers table and orders table.
8. Perform the EQUIJOIN of the 2 tables.
9. Perform the LEFT JOIN of the 2 tables.
10. Perform the LEFT JOIN, RIGHT JOIN, FULL JOIN/ UNION ALL, SELF JOIN, CARTESIAN
JOIN or CROSS JOIN of the 2 tables
11. Create a UNION of 2 tables.
12. (Create a table alias )Display ID,NAME,AGE from customer and AMOUNT from orders table
with customer id present in both the tables.
5
13. column alias: SELECT CUSTOMER_ID, CUSTOMER_NAME FroM CUSTOMERS WHERE SALARY
IS NOT NULL;
--------------------------------------------------------------------------------------
Assignment-6:
CUSTOMERS
+----+----------+-----+-----------+----------+
| ID | NAME | AGE | ADDRESS | SALARY |
+----+----------+-----+-----------+----------+
| 1 | Ramesh | 32 | Ahmedabad | 2000.00 |
| 2 | Khilan | 25 | Delhi | 1500.00 |
| 3 | kaushik | 23 | Kota | 2000.00 |
| 4 | Chaitali | 25 | Mumbai | 6500.00 |
| 5 | Hardik | 27 | Bhopal | 8500.00 |
| 6 | Komal | 22 | MP | 4500.00 |
| 7 | Muffy | 24 | Indore | 10000.00 |
+----+----------+-----+-----------+----------+
CUSTOMERS ORDERS
+-----+---------------------+-------------+--------+
|OID | DATE | CUSTOMER_ID | AMOUNT |
+-----+---------------------+-------------+--------+
| 102 | 2009-10-08 00:00:00 | 3 | 3000 |
| 100 | 2009-10-08 00:00:00 | 3 | 1500 |
| 101 | 2009-11-20 00:00:00 | 2 | 1560 |
| 103 | 2008-05-20 00:00:00 | 4 | 2060 |
+-----+---------------------+-------------+--------+
1. Display record for which similar age count would be more than or equal to 2. (note: use
having clause).
2. Delete records from the table having age = 25 and then COMMIT the changes in the
database.
3. Delete records from the table having age = 25 and then ROLLBACK the changes in the
database.
4. Create a savepoint as sp1, sp2, sp3 after performing 3 transactions and then rollback and
see the changes.
5. Release the savepoint.
6. Display all the records from CUSTOMERS table where SALARY starts with 200.
7. Display the current date time.
8. Display the current date, time, month, year, day, week.
9. Display the lenth of name whose id is 5 from customer table..
10. Update the name to upper case whose id is 4 from customer table 4.
11. Create and drop a temporay table.
12. Create copies of 2 table (Clone) with different names.
13. Consider a table CUSTOMERS_BKP with similar structure as CUSTOMERS table. Now to copy
complete CUSTOMERS table into CUSTOMERS_BKP.
14. Assuming, we have CUSTOMERS_BKP table available which is backup of CUSTOMERS table.
6
Following example updates SALARY by 0.25 times in CUSTOMERS table for all the customers
whose AGE is greater than or equal to 27:
Following example deletes records from CUSTOMERS table for all the customers whose AGE
is greater than or equal to 27:
+----+-------------+------------+------------+
| id | name | date | origin |
+----+-------------+------------+------------+
16. Display the distinct record of the tables.