Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 8

I.

DDL :

i. Create ii. Alter(add, modify, rename, drop)


iii.Rename iv.Truncate v.Drop

i.Create:
---------

-> used to create a new database object.

object:
------

-> it is a collection of dissimilar datatypes and stored in one memory location.

ex: Table,Views, Indexes, squences, synonyms,etc.,

Table:
------

-> it is a collection of info. stored in rows and columns format.

-> max. 1000 columns are allowed and un-limited rows per a table.

-> it is common db object for any rdbms packages.

Syntax:
-------

Create Table <table_name>(Column1 datatype(size), Column2 datatype(size),...);

ex:
---

Create table Emp007(Empno Number(2),Ename Varchar2(10),Sal Number(6,2));

Create table LIbrary(Book_id Number(2), Book_Name Varchar2(10),


Author Varchar2(10));

To see the table list:


---------------------

Select * from Tab;

to see the structure of the table:


---------------------------------

Desc <table_Name>:
-----------------

-> it shows structure of the table.

ex: Desc Emp007;

ii. ALTER:
----------

-> used to modify structure of the table.

-> this command works on columns only.

-> it has 4 options.

a. add b.modify c.rename d.drop

a.add:
------

-> used to add a new column/columns into existing table.

ex: Alter table Emp007 Add(Deptno Number(2), Job Varchar2(10));

b.modify:
--------

-> used to incre/decre size of the column or to chanage datatype of a column.

to increase sizeof empno column:


--------------------------------

Alter table Emp007 Modify Empno Number(4);

to change datatype of a column:


------------------------------

Alter table Emp007 Modify Empno Varchar2(4);

note: Empno column must be empty.

c. Rename(Column Name):
----------------------

-> used to rename a column name.

ex: Alter Table Emp007 Rename Column Sal to Basic;

d. Drop(Column):
---------------

-> used to drop un-used columns from the table permanently.

ex: Alter table Emp007 Drop Column Job;

iii.Rename(table Name):
-----------------------

-> used to rename a table name.


syntax:
-------

Rename <old table_name> to <new table_name>;

ex: Rename Emp007 to Emp707;

iv. Truncate:
------------

-> used delete all records from table permanently.

-> structure is present.

syntax:
------

Truncate table <table_Name>;

ex: Truncate table Emp707;

v. Drop(Table):
--------------

-> used to delete all records and structure from the database permanently.

syntax:
------

Drop Table <table_name>;

ex: Drop table Emp707;

II. DML(Data Manipulation Language):


------------------------------------

-> used to manipulate Existing the data.

-> it has 3 commands.

i. insert 2. update 3. delete

i. Insert:
----------

-> used to insert new rows into existing table.

-> it has two syntaxes.

a. inserting values into all columns

b. inserting values into required columns


syntax a:
--------

insert into <table_name> values(value1,value2,.......);

ex: Insert into Emp007 Values(1,'KIRAN',5000);

Insert into Emp007 values(2,'Anand',3000);

to insert records continuously:


------------------------------

insert into Emp007 values(&empno,'&ename',&sal);

SQL Buffer:

-> it is a temporary buffer, used to hold last excuted query.

-> to execute Buffer's query press '/' operator on Sql Prompt.

syntax b:
---------

insert into <table_name>(column1,column2,.....)


values(value1, value2,.......);

ex: insert into Emp007(Empno,Ename) values(&Empno,'&ename');

ii. Update:
-----------

-> used to modify existing column values.

syntax:
--------

update <table_name> set <column_name>=<value> [,


<column_name>=<value>,....
where <condition>];

ex:

write a query to increment 10% salaries to all employess.

Update Emp007 Set Sal=Sal+Sal*10/100;

write a query to set employee name as 'PRASAD' and set salary 4000 for empno 5;

Update Emp007 Set Ename='Prasad',Sal=4000 where empno=5;


iii. Delete :
-------------

-> used to delete all rows or specified rows from table Temporarilly.

-> Structure is present.

syntax: Delete from <table_name> [ where <condition> ];

ex: Delete from Emp007;

Delete From Emp007 where empno=6;

III. DRL(Data Retrieval Language):


-----------------------------------

-> used to retrieve data from Existing table.

i. Select.

syntax:
-------

Select */column_list from <table_name> [where <condition>/


group by Clause/
having <condition>/
order by Clause];

ex: Select * from Emp007;

Select Empno,Ename from Emp007;

IV. DCL

V. TCL

ORACLE OPERATORS:
----------------

-> Arithametic Operators: +,-,*,/

-> Relational Operators: >,<,>=,<=,=,!= or <>

-> Logical Operators: AND OR NOT

-> Assignment Operators: := ( a:=10; 10 values is assign to 'a' variable)

-> Set Operators: UNION ALL, UNION, INTERSECT & MINUS.

-> Special Operators: IN, NOT IN, BETWEEN, NOT BETWEEN, LIKE, NOT LIKE,
IS NULL, IS NOT NULL.
5 demo tables:
--------------

emp, dept, salgrade, Bonus & Dual

-> write a query to display Employee details.

Select * from Emp;

-> Write a query to display Department details.

Select * from Dept;

-> Write a query to display Who are working in 10th Department.

Select * from Emp Where deptno=10;

-> Write a quety to display who are working 20th department and their jobs matched
with CLERK's

Select * from Emp where Deptno=20 and JOB='CLERK';

-> Write a quety to display who are working in 10 and 20 departments.

Select * from emp where deptno=10 OR deptno=20;

TRUTH TABLES:
------------

AND

T T T

T F F

F T F

F F F

-> Write a query to display who are working in 10 and 20th departments and their
jobs matched with CLERKS.

Select * from emp where (Deptno=10 or Deptno=20) and JOB='CLERK';

BODMAS Rule:
-----------

-> write a query to display who are getting salaries morethan 1000.

Select * from Emp where Sal>1000;

-> write a query to display who are joined 1981 year.

Select * from emp where Hiredate>='01-JAN-1981' AND HIREDATE<='31-DEC-1981';


-> write a query to display whose employee numbers matched with 7788,7902,
7839 & 7369.

Select * from emp where empno=7788 or empno=7902 or empno=7839 or empno=7369;

Special Operators:
-----------------

You might also like