SQL Commands
SQL Commands
SQL Commands
2.
insert into employees values(2,'Jerry', 'J', 'SALESREP',3, '1966-11-19', 1600, 300, 10);
insert into employees values(3,'Jord', 'T' , 'SALESREP',4, '1967-10-21', 1700, 500, 20);
insert into employees values(4,'Mary', 'J', 'MANAGER', 5, '1968-09-22', 1800, NULL, 20);
insert into employees values(6,'Black', 'R', 'MANAGER', 7, '1970-07-24', 2000, NULL, 30);
insert into employees values(8,'White', 'S', 'TRAINER', 9, '1972-05-26', 2200, NULL, 40);
insert into employees values(9,'Yellow', 'C', 'DIRECTOR',10, '1973-04-27', 2300, NULL, 20);
3.
4.
Update Table
Once there's data in the table, we might find that there is a need to modify the data. To do so, we can use the UPDATE command. The syntax for this is UPDATE employees SET job= 'SALESREP' WHERE job = 'trainer'
5.
DROPPING A COLUMN
alter table employees drop column comm.
6.
DELETE
7.
Renaming a table
8.
10.
11.
12. LIST THE NAME OF EMPLOYEE WHOSE EMPNO ARE 7369, 7521,7839,7934,7788.
select ename from newemployee where empno in(7369,7521,7839,7934,7788)
13. LIST THE DETAILS PF EMPLOYEE BELONGING TO DEPARTMENT No 20, 30, 40.
select ename from newemployee where deptno in(20,30,40);
14. LIST THE EMPLOYEE SALARY & NAME WHOSE SALARY IS BETWEEN 1000 AND 2000.
Select * from newemployee where msal between 1000 and 2000;
16. LIST THE EMPLOYEE NME WHO ARE NOT ELIGBLE FOR COMMISSION.
Select * from newemployee where commission is Null;
17. LIST THE NAME OF THE EMPLOYEE & JOB OF THE EMPLOYEE WHO DOES NOT REPORT TO ANY BODY(MGR IS NULL)
SELECT ename,job FROM newemployee WHERE mgr IS NULL
LIST THE DETAILS OF EMPLOYEE WHERE SALARY IS GREATER THAN 2000 & COMM IS NULL.
19.
select * from newemployee where msal > 2000 and comm is null;
21. LIST THE EMPLOYEE WHOSE NAME HAVE EXACTLY 5 CHARACTER 22. LIST THE EMPLOYEE, NAME, SAL IN ASCENDING ORDER OF SALARY.
Select empno,ename,msal from newemployee order by msal ASC ;
27. LIST THE AVERAGE & NO. OF EMPLOYEE WORKING IN DEPARTMENT NO. 20
SELECT AVG(msal),count(empno) FROM newemployee where deptno=20
28. LIST THE DEPARTMENT NO. & NO OF EMPLOYEES IN EACH DEPARTMENT 29. LIST THE AVERAGE SALARY FORM EACH EXCLUDING MANAGER 30. LIST THE TOTAL SALARY, MAXSAL, MINSAL, AVERAGE SALARY ACCORDING TO EMPLOYEE JOBWISE OR DEPTNO 20 HAVING AVERAGE SALARY GREATER THAN 2000.
31. CREATE A COMPOSITE INDEX ON EMP TABLE FOR THE COLUMN EMPNO & DEPTNO
CREATE NONCLUSTERED INDEX NI_empno_deptno ON newemployee(empno,deptno)