Key and Forigen Key: 1. Create A Table and Specific The Primary
Key and Forigen Key: 1. Create A Table and Specific The Primary
Key and Forigen Key: 1. Create A Table and Specific The Primary
TABLE OF “EMPLOYEE”
TABLE OF “DEPARTMENT”
create table”EMPLOYEE”
EMP_CODE NUMBER(4) PRIMARY KEY,EMP_NAME
(VARCHAR2(25)NOT NULL,DESIG CHAR(10) NOT NULL,
HEAD NUMBER(4),DOJ DATE NOT NULL,
BASIC NUMBER(6,2) DEFAULT 0,
DEPT_CODE NUMBER(2)REFRENCES
DEPARTMENT(DEPT_CODE)
);
2. OPERATION ON TABLE
TABLE OF “DEPARTMENT”
DEPT_CODE DEPT_NAME FLOOR
10 Accounts 1
20 Research 2
30 Sales 3
40 Operations 4
TABLE OF “EMPLOYEE”
QUERY 1:-List all department names and their location from the
“department”table.
SQL>SELECT DEPT_NAME, FLOOR FROM
DEPARTMENT;
QUERY 5:-List the name of the employees whose name either starts
Or ends with ‘R’.
SQL>SELECT EMP_NAMEFROM EMPLOYEE
WHERE EMP_NAME LIKE ’R%’ OR EMP_NAME
LIKE’%R’;
QUERY 10:-List the name of the employees along with the name of the
People under whom they are working.
SQL>SELECT WORKER.EMP_NAME,HEADTABLE.EMP_NAME
FROM EMPLOYEE”WORKER”,EMPLOYEE”DEADTABLE”
WHERE WORKER.HEAD=HEADTABLE.EMP_CODE;
QUERY 11:-List the names of the employees who joined the company
Before there respective head did.
SQL>SELECT WORKER. EMP_NAME,WORKER.DOJ,
HEADTABLE.EMP_NAME,HEADTABLE.DOJ
FROM EMPLOYEE”WORKER”,
EMPLOYEE”HEADTABLE”WHERE
WORKER.HEAD=HEADTABLE.EMP_CODE AND WORKER
.DOJ<HEADTABLE.DOJ;
QUERY 16:-List the name of the employees who are do not head anyone
But still get highest salary in the department.
SQL>SELECT EMP_NAME FROM EMPLOYEE
WHERE BASIC>ANY(SELECT BASIC FROM EMPLOYEE
WHERE DEPT_CODE=30);