Escolar Documentos
Profissional Documentos
Cultura Documentos
1)
2)
What is SQL?
3) Which is the subset of SQL commands used to manipulate Oracle Database Structures?
4)
Write a query to select the second highest salary from an employee table.
5)
Write a query to select the nth highest salary from an employee table.
6)
7)
How to create a backup table (another table with same structure and data)
8)
9)
10) How can I determine the location of identical rows in a table before attempting to place a unique index on the table?
12) What is the difference between Unique Key and Primary Key?
13) List all the employees who have atleast one person reporting to them.
14) In which year, did most people join the company? Display the year and the number of employees.
15) List the highest salary paid for each job in each department.
16) List out Employees who earn more than the average salary of their department.
17) Write a query to list the length of service of the Employees (of the form n years and m months)
18) Delete orphaned employee records when a department code is merged to another department code in the department table. For eg., Department Code A is
19) Which function is used to find the largest integer less than or equal to a specific value?
20) List down employees who are due for retirement by end of December 2009. Retirement age is 58 years.
ANSWERS:
1)Problem: The definition of first, second, third, fourth and fifth normal forms.
Solution: In the process of efficiently storing data, and eliminating redundancy, tables in a database are designed and created to be in one of five possible normal forms. Each normal form contains and enforces the rules of the previous form, and, in turn, applies some stricter rules on the design of tables.
First Normal Form: =============== Tables are said to be in first normal form when: - The table has a primary key. - No single attribute (column) has multiple values. - The non-key attributes (columns) depend on the primary key.
stories: novelist, playwright magazine columnist novella, newpaper columnist // multiple values // multiple values
Second Normal Form: ================= Tables are said to be in second normal form when: - The tables meet the criteria for first normal form. - If the primary key is a composite of attributes (contains multiple columns), the non key attributes (columns) must depend on the whole key.
Note: Any table with a primay key that is composed of a single attribute (column) is automatically in second normal form.
Third Normal Form: ================ Tables are said to be in third normal form when: - The tables meet the criteria for second normal form. - Each non-key attribute in a row does not depend on the entry in another key column.
Fourth Normal Form: ================ Tables are said to be in fourth normal form when: - The table meets the criteria for third normal form. - Situations where non-key attributes depend on the key column exclusive of other non-key columns are eliminated.
Fifth Normal Form: =============== Tables are said to be in fifth normal form when: - The table meets the criteria for fourth normal form. - The table consists of a key attribute and a non-key attribute only.
2) SQL stands for Structured Query Language. SQL is used to communicate with a database. It is the standard language for relational database management systems. SQL statements are used to perform tasks such as update data on a database, or retrieve data from a database. Some common relational database management systems that use SQL are: Oracle, Sybase, Microsoft SQL Server, Access, Ingres, etc.
3)Data Definition Language(DDL) 4) select max(salary) from emp1 where salary not in ( select max(salary) from emp1);
5) select * from (select rownum r,salary from (select distinct salary from emp1 order by salary desc))where r=&i;
6)By using REVOKE command, we can get back the privileges provided by GRANT command.
8) DELETE (i) Delete is a DML command (ii) We can insert data to the deleted memory space. (iii)ROLLBACK command is applicable. TRUNCATE (i) Truncate is a DDL command. (ii) The memory space is released back to the server (iii ) ROLLBACK command is not applicable.
10) select rowid from table_name e where e.rowid > (select min(x.rowid) from table_name x where x.column1 = e.column1);
11) when a join condition is omited when getting result from two tables then that kind of query gives us Cartesian product in which all combination of rows displayed. All rows in the first table is joined to all rows of second table.
For ex: we have two table emp and dept emp have 14 rows and dept have 5 rows if we write this query select emp.ename emp.sal dept.dname from emp dept; this query provide us 70 rows this called cartesian product 14*5.
12) PRIMARY KEY (i) There is only one Primary key for one table . (ii) It cannot contain null values. (iii)Primary key creates clustered index UNIQUE KEY (i) There may be more than one Unique Key in table. (ii) It can contain null values. (iii) unique key creates non clustered index
16) select ename , departmentno from employee where salary in ( select max(salary) from employee group by departmentno having max(salary) > avg(salary));
17) select ename ,to_char(trunc(months_between(sysdate,hire_date)/12)) as "no.of year" , to_char(trunc (mod(months_between(sysdate,hire_date),12))) as "no.of months" from employee;
19)FLOOR
20) select ename , to_char(trunc(months_between('31-DEC-09',hire_date)/12)) + age as "no.of year" from employee where to_char(trunc(months_between('31DEC-09',hire_date)/12)) + age > =58;
EMPLOYEE TABLE:
ENAME EID MANAGERID AGE HIRE_DATE arun 20 ashwin 21 basha 34 banu 30 deva 32 durai 32 gajini 47 1 10-JAN-00 2 10-FEB-06 1 16-JUN-05 3 20-JUL-04 8 02-AUG-04 1004 1005 6 1006 2002
DEPARTMENTNO 20 20 30 30 40 40 50
DEPARTMENT TABLE: