Sunteți pe pagina 1din 7

Till now we had learned about 1. MS DOS 2.

MS word writing formatted documents,mail merge,change case,tables ,word art etc 3. MS excel performing mathematical calculations with formulas,inserting chart . Now we will begin something new and that is databases. Database Data base is the store where tables are present in forms of rows and columns. Tables hold the values of employee details,department details ,students details ,marks details ,departmental store details. So, Database is very different from programming language. In market different companies have their products for database. 1. Oracle by oracle corporation 2. SQL Server by Microsoft We will start learning database from oracle

Client Username :scott Password :tiger


We assume in oracle database there are 3 default tables named dept ,emp and salgrade The table looks like this DEPT
DEPTNO DNAME LOC --------- -------------- ------------10 ACCOUNTING New York 20 RESEARCH Dallas 30 SALES Chicago 40 OPERATIONS Boston

Demo Tables

EMP
EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO --------- ---------- --------- --------- --------- --------- --------- --------7369 SMITH CLERK 7902 17-DEC-80 800 20 7499 ALLEN SALESMAN 7698 20-FEB-81 1600 300 30 7521 WARD SALESMAN 7698 22-FEB-81 1250 500 30 7566 JONES MANAGER 7839 02-APR-81 2975 20 7654 MARTIN SALESMAN 7698 28-SEP-81 1250 1400 30 7698 BLAKE MANAGER 7839 01-MAY-81 2850 30 7782 CLARK MANAGER 7839 09-JUN-81 2572.5 10 7788 SCOTT ANALYST 7566 19-APR-87 3000 20 7839 KING PRESIDENT 17-NOV-81 5250 10 7844 TURNER SALESMAN 7698 08-SEP-81 1500 0 30 7876 ADAMS CLERK 7788 23-MAY-87 1100 20 7900 JAMES CLERK 7698 03-DEC-81 950 30 7902 FORD ANALYST 7566 03-DEC-81 3000 20 7934 MILLER CLERK 7782 23-JAN-82 1365 10

SALGRADE
GRADE LOSAL HISAL --------- --------- --------1 700 1200 2 1201 1400 3 1401 2000 4 2001 3000 5 3001 9999

Let put few queries on table and find the output ,to know how it works
1. SELECT * FROM Emp; 2. SELECT Empno, EName, job, HireDate FROM Emp; 3. SELECT Empno, HireDate, MGR FROM Emp ; 4. SELECT Empno, EName, job, HireDate FROM Emp WHERE ename = 'Scott'; 5. SELECT Empno, EName, job, HireDate FROM Emp WHERE ename <> 'Scott'; 6. SELECT Empno, EName, job, HireDate FROM Emp WHERE HireDate >= 03-dec-81'; 7. SELECT Empno, EName, job, HireDate FROM emp WHERE (HireDate >= '1-june-1992') AND (HireDate <= '15-december1993'); 8. SELECT Empno, EName, job, HireDate FROM emp WHERE HireDate BETWEEN '1-june-1992' AND '15-december-1993'; 9. SELECT Empno, EName, job, HireDate FROM emp WHERE HireDate NOT BETWEEN '1-june-1992' AND '15december-1993'; 10. SELECT Empno, EName, job, HireDate FROM emp WHERE HireDate NOT BETWEEN '1-june-1992' AND '15-december1993'; 11. SELECT Empno, EName FROM emp WHERE job IN ('manager', 'salesman'); Suppose I want to see the data of name who start with A or J use 12. SELECT * from emp where ename like A% or J% ; 13. SELECT Empno, EName, job, HireDate FROM emp ORDER BY job ; 14. Select * from dept; 15. Select * from dept where dname =sales; 16. Select dname from dept where deptno= 40; 17. Select * from salgrade;

Now read the statement below for reminding the queries :

1. SELECT * FROM Employees;

2. SELECT EmployeeID, FirstName, LastName, HireDate, City FROM Employees; 3. SELECT EmployeeID, LastName, FirstName, HireDate, City FROM Employees ; 4. SELECT EmployeeID, FirstName, LastName, HireDate, City FROM Employees WHERE City = 'London'; 5. SELECT EmployeeID, FirstName, LastName, HireDate, City FROM Employees WHERE City <> 'London'; 6. SELECT EmployeeID, FirstName, LastName, HireDate, City FROM Employees WHERE HireDate >= '1-july-1993'; 7. SELECT EmployeeID, FirstName, LastName, HireDate, City FROM Employees WHERE (HireDate >= '1-june-1992') AND (HireDate <= '15december-1993'); 8. SELECT EmployeeID, FirstName, LastName, HireDate, City FROM Employees WHERE HireDate BETWEEN '1-june-1992' AND '15-december1993'; 9. SELECT EmployeeID, FirstName, LastName, HireDate, City FROM Employees WHERE HireDate NOT BETWEEN '1-june-1992' AND '15december-1993'; 10. SELECT EmployeeID, FirstName, LastName, HireDate, City FROM Employees WHERE HireDate NOT BETWEEN '1-june-1992' AND '15december-1993'; 11. SELECT EmployeeID, FirstName, LastName, HireDate, City FROM Employees WHERE City IN ('Seattle', 'Tacoma', 'Redmond'); 12. SELECT EmployeeID, FirstName, LastName, HireDate, City FROM Employees WHERE (FirstName NOT LIKE 'M%') AND (FirstName NOT LIKE 'A%'); 13. SELECT EmployeeID, FirstName, LastName, HireDate, City FROM Employees ORDER BY City; 14. SELECT EmployeeID, FirstName, LastName, HireDate, Country, City FROM Employees ORDER BY Country, City DESC; The end You want to create your table, now lets start it quickly:

Read the next page carefully and follow the steps

May be possibility some students had created the student table lets check it. Select * from table; List of tables Emp Dept Salgrade Flight Student Student1 Emp1 So on fifth position student table is present lets check its content. Select * from student; Now I want to create my own table named student so Drop pre-existing table student from ,give the command Drop table student; Now again check whether student table is deleted or not,write Select * from table; Emp Dept Salgrade Flight Student1 Emp1 No ,there is no student table in oracle database. Now start a fresh new student table by writing the create query.. the oracle database

1. Create table student ( rno int primary key, Name varchar(2), Age int); Primary key means no two rollno (RNO) can be same ,it is unique 2. Desc student ; 3. Select * from student; No data found ,so we will insert new data by providing the insert command. 4. Insert into student values (1,geeta,20); 5. Insert into student values(2,amit,24); 6. Insert into student values(3,jatin,18); 7. Select * from student; 8. Select * from student where rno=2; 9. Select name from student where age=20; Now we will update the data 10. Update student set age=20 where rno=2; 11. Commit; Commit is used to save changes permanently in database. 12. Select * from student; 13. Select * from student where age=20; Now I want to delete one record from the table 14. Delete from student where rno=3; 15. Select * from student; To undo the changes use rollback; it is opposite of commit; 16. Rollback; 17. Select * from student; //data is back rno=3 If u want to delete the complete data in the table

Use 18. Delete from student; To drop the whole table structure from database use 19. Drop table student; Now student table is no more ,drop is opposite of create table !!! check 20. Select * from table; No table student u found

Chapter the end

S-ar putea să vă placă și