¦ BY:- Aslam khan CS 3

rd
YEAR 5
th
SEMESTER (VIT) ] Page 1

.AooIGùMIù1 -1.

What is SQL?
SQL is a standard language Ior accessing and manipulating databases.
SQL stands Ior Structured Query Language.
SQL lets you access and manipulate databases.
SQL is an ANSI (American National Standards Institute) standard.


What Can SQL do?
O SQL can retrieve data Irom a database.
O SQL can insert records in a database.
O SQL can update records in a database.
O SQL can delete records Irom a database
O .SQL can create new databases.
O SQL can execute queries against a database.
O SQL can set permissions on tables, procedures, and views.
O SQL can create new tables in a database.
O SQL can create stored procedures in a database.
O SQL can create views in a database.
¦ BY:- Aslam khan CS 3
rd
YEAR 5
th
SEMESTER (VIT) ] Page 2

.IOG Iù.

Description:-
In the oracle we can logged by three ways:-
%he Iirst way to logged in is that simply write the user id and password.

Syntax:-

%he deIault user id oI the oracle is 'scott¨ and the password is 'aslam¨.

Example:-




%he second way to logged in is that write the user id in the user id text box and just put
the back slash and then write the password in the same text box.
¦ BY:- Aslam khan CS 3
rd
YEAR 5
th
SEMESTER (VIT) ] Page 3


Syntax:-
%he deIault user id oI the oracle is 'scott¨ and the password is 'aslam¨.

Example:-

%he third way to logged in is that press the ok button in the tab without entering the
user id and password by this we can enter in the oracle and now enter the user id and
password.

Syntax:-
%he deIault user id oI the oracle is 'scott¨ and the password is 'aslam¨.
Example:-

¦ BY:- Aslam khan CS 3
rd
YEAR 5
th
SEMESTER (VIT) ] Page 4

.CIIAI oCIIIù.
Description:-
%his command is used to clear the whole desktop screen oI the oracle 9i.

Syntax:-
c|ear screenŤ
or
c|ear scrŤ

Example:-

¦ BY:- Aslam khan CS 3
rd
YEAR 5
th
SEMESTER (VIT) ] Page 5

.lIoCIII1IOù.

Description:-

%his command is used to give the description oI the table.

Syntax:-

desc <table name>;

Example:-

¦ BY:- Aslam khan CS 3
rd
YEAR 5
th
SEMESTER (VIT) ] Page ô

.oIIIC1.

Description:-

%his command is used to select the data oI the table.

Syntax:-
select ` from <table name>;
Example:-

¦ BY:- Aslam khan CS 3
rd
YEAR 5
th
SEMESTER (VIT) ] Page 7

.WIIII.
Description:-
%his command is used to select those data Irom table which is greater than, less than or equal to
any particular number.
Syntax:-
Select ` from <table name> where <column name>÷ 100;


Example:-





¦ BY:- Aslam khan CS 3
rd
YEAR 5
th
SEMESTER (VIT) ] Page 8

.CIIA1I.
Description:-
%his command is used to create the table in the oracle 9i database.
Syntax:-

create table <table name>(<col.name1> <data type(size)>,
<col.name2> <data type(size)>,<col.name3> <data
type(size)>,..........)
Example:-





¦ BY:- Aslam khan CS 3
rd
YEAR 5
th
SEMESTER (VIT) ] Page 9

.IlI1.
Description:-
%his command is used to edit the previous written command iI there is some mistake or error is
occurred in typing or executing. With the help oI this command we can only edit in the notepad
then by saving it we execute the command.
Syntax:-
ed

Example:-

¦ BY:- Aslam khan CS 3
rd
YEAR 5
th
SEMESTER (VIT) ] Page 1ô

.COMMI1.
Description:-
%his command is used to save the data in the database oI the oracle 9i.

Syntax:-
Commit;


Example:-





¦ BY:- Aslam khan CS 3
rd
YEAR 5
th
SEMESTER (VIT) ] Page 11

.IùoII1.
Description:-
%his command is used to insert the values in the table which is newly created.


Syntax:-
insert into <table name> values(<col.name1> <value>,
<col.name2> <value>`, <col.name3> <value>,
...........)

Example:-



¦ BY:- Aslam khan CS 3
rd
YEAR 5
th
SEMESTER (VIT) ] Page 12

.IIKI.
Description:-
%his command is used to Iind the words which are started Irom the any keyword.

Syntax:-
Select ` from <table name> where <column name> like Aº
or ºA or ºAº;

Example:-





¦ BY:- Aslam khan CS 3
rd
YEAR 5
th
SEMESTER (VIT) ] Page 13

.AI1II.
Description:-
It is used to alter or in other words, change the structure oI a table, view, index. %his is
particularly used when there is a scenario wherein the properties oI Iields inside a table, view,
index are supposed to be updated.
Syntax:-

i. ALTER TABLE <table name> ADD <column name> <data
type>(size);
ii. ALTER TABLE <table name> DROP COLUMN <column
name>;
iii. ALTER TABLE <table name> MODIFY COLUMN <col1>
<data type>(size);

Example:-



¦ BY:- Aslam khan CS 3
rd
YEAR 5
th
SEMESTER (VIT) ] Page 14

.lIlA1I.

Description:-
%his command is used to update the data oI any table.

Syntax:-

update <table name> set <column name>÷` where
<column name>÷ ;

Example:-

¦ BY:- Aslam khan CS 3
rd
YEAR 5
th
SEMESTER (VIT) ] Page 15

.OIlII IY.

Description:-
%his command is used to sort or order the entries oI any table in increasing order or in the
alphabets.
Syntax:-
Select ` from <table name> order by <column name>;

Example:-

¦ BY:- Aslam khan CS 3
rd
YEAR 5
th
SEMESTER (VIT) ] Page 1ô

.1IlùCA1I.
Description:-
%his command is used to delete whole table Irom the database.

Syntax:-

Truncate table <table name>;

Example:-






¦ BY:- Aslam khan CS 3
rd
YEAR 5
th
SEMESTER (VIT) ] Page 17

.lIII1I.

Description:-
%his command is used to delete only one single row.

Syntax:-
Delete from <table name> where <column name>÷ ;

Example:-





¦ BY:- Aslam khan CS 3
rd
YEAR 5
th
SEMESTER (VIT) ] Page 18

.AVIIAGI.
Description:-
%his command is used to Iind out the average oI the entries which is in the numeric Iorm.

Syntax:-
Select avg<column name> from <table name>;

Example:-






¦ BY:- Aslam khan CS 3
rd
YEAR 5
th
SEMESTER (VIT) ] Page 19

.COlù1.
Description:-
%his command is used to count the number oI rows which is present in the table.

Syntax:-

Select count<column name> from <table name>;

Example:-

¦ BY:- Aslam khan CS 3
rd
YEAR 5
th
SEMESTER (VIT) ] Page 2ô

.MAXIMlM & MIùIMlM.

Description:-
%his command is used to Iind the maximum and minimum number Irom the table.

Syntax:-

Select max<column name> from <table name>;
Select min<column name> from <table name>;

Example:-

¦ BY:- Aslam khan CS 3
rd
YEAR 5
th
SEMESTER (VIT) ] Page 21

.olM.
Description:-
%his command is used to Iind out the sum oI the entries in the table.
Syntax:-
Select sum<column name> from <table name>;

Example:-







¦ BY:- Aslam khan CS 3
rd
YEAR 5
th
SEMESTER (VIT) ] Page 22

.IIIMAIY KIY.

Description:-
%his command is used to set the primary key on the any column oI the table.

Syntax:-

Create table <table name><column name1> <data type>(size)
primary key, <column name2> <data type>(size), <column name3>
<data type>(size), .............);


Example:-





¦ BY:- Aslam khan CS 3
rd
YEAR 5
th
SEMESTER (VIT) ] Page 23

.IIùG1I.

Description:-
%his command is used to count the length oI the string.

Syntax:-

Select length<column name1> from <table name> where
<column name2>÷ ;

Example:-

¦ BY:- Aslam khan CS 3
rd
YEAR 5
th
SEMESTER (VIT) ] Page 24

.IIIIACI.

Description:-
%his command is used to replace the last name or middle name oI the any word in the table.

Syntax:-

Select replace(<column name>, , ) from <table
name>;

Example:-

¦ BY:- Aslam khan CS 3
rd
YEAR 5
th
SEMESTER (VIT) ] Page 25

.oYo1IM lA1I.

Description:-
%his command is used to display the system date on the screen.

Syntax:-

Select sysdate from <table name>;


Example:-

¦ BY:- Aslam khan CS 3
rd
YEAR 5
th
SEMESTER (VIT) ] Page 2ô

.GIOlI IY.

Description:-
%his command is used to group by the same names and do the sum oI it.

Syntax:-

Select <column name1>, sum(<column name2>) from <table
name> group by <column name1>;

Example:-




¦ BY:- Aslam khan CS 3
rd
YEAR 5
th
SEMESTER (VIT) ] Page 27

.IAVIùG.
Description:-
%his command is used to group by the same names and do the sum oI it and we can also Iind
greater than or less than numbers.

Syntax:-

Select <column name1>, sum(<column name2>) from <table
name> group by <column name1> having sum(<column name2>)>
or< 1000;

Example:-





¦ BY:- Aslam khan CS 3
rd
YEAR 5
th
SEMESTER (VIT) ] Page 28

.CIICK.

Description:-
%his command is used to check the condition whether it is true or not.

Syntax:-

Create table <table name>(<column name1> <data type>
check(<column name1>>0), <column name2> <data type(size)>,
<column name3> data type(size),...............);

Example:-


¦ BY:- Aslam khan CS 3
rd
YEAR 5
th
SEMESTER (VIT) ] Page 29

.IOW Il.

Description:-
%his command is used to Iind row id oI the any row in the table.

Syntax:-
e|ect row |d from Ƽtab|e nameƽŤ
Example:-

¦ BY:- Aslam khan CS 3
rd
YEAR 5
th
SEMESTER (VIT) ] Page 3ô

.GIAù1.

Description:-
1hls command ls used Lo glve Lhe dlfferenL Lypes of permlsslons Lo any oLher usersŦ

Syntax:-

rant create session to user name;
rant create view to username;
rant resource to user name;

Example:-





¦ BY:- Aslam khan CS 3
rd
YEAR 5
th
SEMESTER (VIT) ] Page 31

.CIIA1I loII.
Description:-
%his command is used Ior creating the new user in the oracle 9i.

Syntax:-

Create user <user name> identified by <password>;

Example:-





¦ BY:- Aslam khan CS 3
rd
YEAR 5
th
SEMESTER (VIT) ] Page 32

.IùlIX.
Description:-
%his command is used Ior Iast searching the name or any other thing Irom the whole table.

Syntax:-

Create index <index name> on <table name>(<column
name>);

Example:-











¦ BY:- Aslam khan CS 3
rd
YEAR 5
th
SEMESTER (VIT) ] Page 33

.IMIOI1 & IXIOI1.
Description:-
%his command is used to export the tables Irom the one user and import to another user.

Syntax:-



Example:-






¦ BY:- Aslam khan CS 3
rd
YEAR 5
th
SEMESTER (VIT) ] Page 34

.IIVOKI.
Description:-
%his command is used to we take the permission Irom another user.

Syntax:-

Revoke select, create, insert on <table name> from
<user name>;

Example:-





¦ BY:- Aslam khan CS 3
rd
YEAR 5
th
SEMESTER (VIT) ] Page 35

.lùIQlI KIY.

Description:-
%his command is used Ior unique column.

Syntax:-

Create table <table name>(<Column name1>
<datatype>(size) unique key, <columnname2>
<datatype>(size));

Example:-




¦ BY:- Aslam khan CS 3
rd
YEAR 5
th
SEMESTER (VIT) ] Page 3ô

.lIOI.
Description:-
%his command is used to drop the table.

Syntax:-

^[p table <table name>,

Example:-



     

08.75943 
39047,.00.,340/-9700,8  

%01789,9440/389,982579090:807/,3/5,8847/  

$39,  

%0/01,:9:807/419047,.08 8.499 ,3/905,8847/8 ,8,2  
,250 
 

  

%080.43/,9440/389,979090:807/390:807/909-4,3/:895:9
90-,.8,8,3/903790905,8847/3908,20909-4   

8,2,3$7/#9$$%# '% < 

!,0

 $39, 

%0/01,:9:807/419047,.08 8.499 ,3/905,8847/8 ,8,2  
,250  

 %097/,9440/389,957088904-:99433909,-94:903907390
:807/,3/5,8847/-980.,30390739047,.0,3/340390790:807/,3/ 5,8847/  

$39, 

%0/01,:9:807/419047,.08 8.499 ,3/905,8847/8 ,8,2  
,250    

8,2,3$7/#9$$%# '% < 

!,0

2.79040/089458.0 .3/8:80/94.3$7/#9$$%# '% <   !.    n f¾n °   n f¾n   .7003419047.422.0   $39.0.. #$#  08.250     8.75943  %8.

0 .-0   $39.090/08.-03.422.250     8.9.3$7/#9$$%# '% <  !.   /08.75943   %8.2.3/8:80/94. $#!%    08.7594341909.20  .

3$7/#9$$%# '% <  !.  800.9.75943   %8.990/.9 17429.422.-0   $39. $%   08.-03.0 .2.41909.250    8.3/8:80/94800.20 .

422.-03. #  08.9 17429.  $00.3/8:80/94800.20    .75943  %8.0 .9.4:233.34706:.2.9079.79.99480/.94 .20070.-0.17429.:.73:2-07  $39.35.870.3 0889.250        8.3$7/#9$$%# '% <  !.

-03.-.3/8:80/94.3$7/#9$$%# '% <  !.950 80   .20/.2.70.75943  %8.250        8.950 80  .20 .-09.4 3.  950 80  .70.422.-039047.9.0/.9..4 3.20/.   .9.4 3. #%  08.20/.90909.0 .80  $39.9.909.

:770/39534700.422. %  08.3$7/#9$$%# '% <  !.422.0 ..  0/  .3/  $39./ 903-8.422.75943  %8.39000.3/0.3/8:80/940/990570.:9090.:93 990054198.3/1907088420289..3430/939034905.422..047077478 4.2.250       8.4:879903.

2.0  .-.090/..80419047.250        8.3$7/#9$$%# '% <  !.    %8.9.3/8:80/948.390/.75943   $39.0  4229   .422.  % 08..9.

4 3.:0  .  380793949.4 3.:083909.75943  %8.0 . $#%  08.-03.20..20.70.830.:08 .422.2.:0 .20.-0..3/8:80/943807990.20...:0     S\W     8.3$7/#9$$%# '% <  !.4 3.90/    $39..

7089.  $00.4:233.790/174290.20070.422.9 17429.75943  %8.3/8:80/9413/9047/8.0 .3$7/#9$$%# '% <  !.-03.2..   08.3047/   $39.200 4747   S\W       8.

0 .4:23 3. %#  08.20.9:7041.950 80   .20/. 950 80    %#%9.9.4 /.-03.-03.708:55480/94-0:5/.20  &.4:233.9.0 3/0 %88 5.:.     %#%9.8.-03.250      8.20# ! &.0  3/0.9.3$7/#9$$%# '% <  !.20   %#%9.907473490747/8 .-0 .79.-0 .2.9..90/  $39.740703905745079084110/838/0.7:80/0390708.3090897:.75943  98:80/94.03.

0 .   :5/.9.20  .-0   $39.909.4:233.3/8:80/94:5/.2. &!%   08.4:233.20809.250       8.3$7/#9$$%# '% <  !.9090/.39.-03.41.20  070 .422.75943  %8.

2.8347/0747390 .4:233. ##   08.75943  %8.250      8.39.70.  $00.2047/07-.5.-033.3/8:80/9484794747/079003970841.20  .-03.0 .9 17429.-098  $39.3$7/#9$$%# '% <  !.422.

3$7/#9$$%# '% <  !.. %#&%  08.-0174290/.2.-03.-.75943  %8.909.   %7:3.250         8.3/8:80/94/0090409.0 .20  .-09.9.422.80   $39.

3$7/#9$$%# '% <  !.3/8:80/94/00904343083074   $39.2.4:233.250        8.0 .-03. %   08.  009017429.75943  %8.422.20070.20  .

07.1472  $00.20  .9.422..2.75943   $39.250         8.04190039708... '# 08.0 .4:233.2017429.3$7/#9$$%# '% <  !.   %8.3/8:80/9413/4:990.83903:207.-03.

9.250        8.2017429.4:233.0 .  &%  08.4:39.422.   $00.-03.857080393909.3$7/#9$$%# '% <  !.75943  %8.20  .2.-0   $39.3/8:80/94.4:39903:2-0741748.

   $00.2017429.92.-03.3/8:80/9413/902.3/232:23:2-071742909.250       8.2.20  ..2:2.20 $00. & &   08.2017429.-0   $39.3$7/#9$$%# '% <  !.422.0  .4:233.923.4:233.75943  %8.-03.

20  .422.3$7/#9$$%# '% <  !.0 .-03.4:233.  $00. $&  08.98:2.250          8.75943  %8.-0  $39.2017429.3/8:80/9413/4:9908:241900397083909.2.

20/.3$7/#9$$%# '% <  !.9.909.4:2341909.-03.9.20.0 .   70. !##   08.704390.20 /.950 80  572.950 80     .4:233.950 80 .75943  %8.-09.9.3.3/8:80/9480990572.250        8.70 .20/.-0   $39.422.2.4:233.4:233.

75943  %8.4:233.4:399003941908973   $39.4:233.0 .20070 .2017429.3/8:80/94.3$7/#9$$%# '% <  !.422.20  .9039. %   08.2.250       8.-03.   $00.

090.347/3909.   $00.-0   $39.20472//03.0 .-0 3.3$7/#9$$%# '% <  !.3/8:80/94705.893.75943  %8.9705..2.20  .20     17429.0 .4:233..204190.250     8. #!   08.422.

422.988/.0 .9017429.-03.9088902/.3$7/#9$$%# '% <  !.20   .250      8.3/8:80/94/85.9043908.   $00. $$%%   08.75943  %8.7003   $39.2.

3//4908:2419   $39.0 .250       8.3/8:80/9474:5-908.208.4:233.2074:5-.2. # &!   08.   $00.20 8:2 .203.4:233.422.4:233.-0 3.20 17429.9.75943  %8.3$7/#9$$%# '% <  !.20  .

20  47   .20 17429.2.3/0.208.9.8413/ 70..4:233.3.2074:5-.38:2 .20 8:2 .422..4:233.3470889.3//4908:2419. ' 08.   $00.-0 3.4:233.250        8.9079.20.75943    %8.33:2-078  $39.4:233.3$7/#9$$%# '% <  !.3/8:80/9474:5-908.0 .203.

20/.20 .   70.0.75943  %8.3$7/#9$$%# '% <  !.-09.0 .90.20/.20 .3/8:80/94.950 80   .9.0.43/94309079897:047349   $39.2.4:233.950 80   .422.    08.950 .9.9.4:233.20/.250        8. .909.4:233.4:233.-03.

3/8:80/9413/74/4190.0 .422.75943  %8.3743909.3$7/#9$$%# '% <  !.-0   $39. #    08.    n €¯ f  °f¯   S\W      8.2.

20 7.70.3$7/#9$$%# '% <  !. #%   08.250        8.094:8073.90.2.20  .70.75943  @¾n¯¯f° ¾¾ –   €€  °½ ¾€½ ¯¾¾°¾f° ¾ ¾    Z`S   7.20 7.397084:7.094:8073.9080884394:8073.39.0  .39.

250        8.8847/  .3$7/#9$$%# '% <  !. #%&$# 08..3/8:80/147.422.0    $39.20/03910/-5.0 .939030:80739047.75943  %8.2.70.   70.90:807:8073.

250              8.4:23 3.3490793174290409.-03.2.3$7/#9$$%# '% <  !.422.75943    %8.20439.20 .3903.  08.   70.903/03/03.3/8:80/1471.2047.0 .7.8980.20   .-0  $39.

250         8.2.     .3/2547994.3/8:80/9405479909. ! #% ! #%  08.0 .34907:807   $39.75943  %8.3$7/#9$$%# '% <  !.422.-08174290430:807.

090507288431742.201742 :8073.70.90 38079439.0 .34907:807   $39.   #0.3$7/#9$$%# '% <  !.9 .250        8.2. #'   08.-03.40800.75943  %8.20  .422.3/8:80/9409.

3/8:80/147:36:0.422.4:23   $39.950 80   .   70.-09.2. &"&   08.-03.75943  %8.20 /.0 .20 4:233.4:233.250       8.20 /.909.3$7/#9$$%# '% <  !.950 80 :36:00 .9.9.

-0   $39.75943  %8.3$7/#9$$%# '% <  !.2.   ^[\`STW`STWZSW  . # !  08.422.0 .250          8.3/8:80/94/745909.

Sign up to vote on this title
UsefulNot useful