M.
NARENDER REDDY
SQL COMMANDS
By using this SQL commands, we can create tables, and modify the tables and
retrieve the tables
[Link] COMMANDS
[Link] COMMANDS
[Link] COMMANDS
[Link] COMMANDS
[Link] COMMANDS
[Link] commands
it stands for data definition language commands
By using this DDL commands we can create tables structure and alter that
table and delete that table structure also
DDL commands are
1)create
2)alter
3)drop
4)truncate
5)rename
[Link] COMMAND
It is used to create table structure in our database
Syntax SQL> create table table name (
columnname1 datatype(size),
columname2 datatype(size),
--------------------------------
column name n datatype(size));
In the above syntax create is a command and
table name is a user defined name
Ex:- SQL>create table student(
sno number(3),
name varchar2(10),
phno number(10),
marks number(5));
[Link] REDDY SINDHU DEGREE COLLEGE
[Link] REDDY
SNO NAME PHNO MARKS
[Link] COMMAND
By using alter command we can modify the structure of a table
By using alter command we can perform below operations
ADD,DROP,MODIFY table columns
ADD and DROP constraints
Enable and disable constraints
Syntax1:- ADD NEW COLUMN
SQL> alter table table name ADD(new column datatype(size));
Ex:- SQL>alter table student add(address varchar2(10));
SNO NAME PHNO MARKS ADDRESS
Syntax2:-MODIFY COLUMN DATA TYPE AND SIZE
SQL>alter table table name MODIFY(columnname datatype(size));
Ex:- SQL>alter table student modify(sno number(10));
[Link] REDDY SINDHU DEGREE COLLEGE
[Link] REDDY
Syntax2:-DROP COLIUMN FROM TABLE
SQL>alter table table name DROP column column name;
Ex:- SQL>alter table student drop column sno;
[Link] COMMAND
By using this truncate command we can delete all rows from a table
Syntax
SQL>truncate table table name;
Ex:-
SQL>truncate table student;
[Link] COMMAND
By using this drop command we can destroy the table structure.
Syntax
SQL>drop table table name;
Ex:- SQL>drop table student;
[Link] COMMAND
By using this rename command we can change our table name
Syntax
SQL>rename old table name to new table name
Ex:-
SQL>rename student to emp;
[Link] REDDY SINDHU DEGREE COLLEGE
[Link] REDDY
DML COMMANDS
DML stands for data manipulation language commands.
By using this command, we can manipulate the table data.
DML commands are
[Link] COMMAND
[Link] COMMAND
[Link] COMMAND
[Link] COMMAND-
By using insert command we can insert values in to the table
Syntax:
SQL>insert in to table name values(&column1,&column2-------------&column);
Ex:-
SQL>insert in to student values(&sno,&name,&phoneno,&marks);
SNO NAME PHONENO MARKS
10 RAJU 9874578701 98
20 MANJU 7895485788 87
30 RANI 1234878951 47
40 MAHI 9654789412 66
[Link] COMMAND
By using this command, we can update our table data in our data base.
Syntax:
SQL>update table name set columname=value where [condtion];
Ex:-
SQL>update student set name='sindhu' where sno=10;
[Link] REDDY SINDHU DEGREE COLLEGE
[Link] REDDY
SNO NAME PHONENO MARKS
10 SINDHU 9874578701 98
20 MANJU 7895485788 87
30 RANI 1234878951 47
40 MAHI 9654789412 66
[Link] COMAND
By using this command, we can delete records from our table based on
condition.
Syntax:
SQL>delete fom table name where [condtion];
Ex-
SQL>delete from student where sno=10;
SNO NAME PHONENO MARKS
20 MANJU 7895485788 87
30 RANI 1234878951 47
40 MAHI 9654789412 66
[Link] COMMAND
DQL stands for data query language.
By using this DQL command we can retrieve table data from our data base
DQL command is
I. SELECT command.
SELECT COMMAND
By using this command we can retrieve table data from data base
Syntax
SQL>select * from table name;
where * indicates all columns names of a table
[Link] REDDY SINDHU DEGREE COLLEGE
[Link] REDDY
Ex-1
SQL>select * from student;
Note---->If you want retrieve specific columns at that time in place of * you can
write that specific column name only
SNO NAME PHONENO MARKS
20 MANJU 7895485788 87
30 RANI 1234878951 47
40 MAHI 9654789412 66
Ex-2
SQL>select name from student1;
here name is column name;
NAME
MANJU
RANI
MAHI
Ex-3
SQL>select name, marks from student1;
NAME MARKS
MANJU 87
RANI 47
MAHI 46
[Link] REDDY SINDHU DEGREE COLLEGE
[Link] REDDY
DCL COMMANDS
DCL stands for data control language
DCL includes commands such as GRANT and REVOKE which mainly
deals with the rights, permissions and other controls of the database system.
DCL command are
I. GRANT
II,REVOKE
GRANT COMMAND
Gives user’s access privileges to database.
Syntax
--------
SQL> GRANT privileges ON object TO user;
SELECT------>Ability to perform SELECT statements on the table.
INSERT------->Ability to perform INSERT statements on the table.
UPDATE------>Ability to perform UPDATE statements on the table.
DELETE------->Ability to perform DELETE statements on the table
ALTER-----------> Ability to perform ALTER TABLE statements to
change the table definition.
INDEX----->Ability to create an index on the table with the create index
statement.
ALL----->All privileges on table.
object
The name of the database object that you are granting privileges for. In the
case of granting privileges on a table, this would be the table name.
user
The name of the user that will be granted these privileges.
[Link] REDDY SINDHU DEGREE COLLEGE
[Link] REDDY
Ex:-1
SQL>Grant SELECT ON student TO Sindhu;
By using above example we can give only select permission to Sindhu user
Ex-2
SQL>Grant SELECT,UPDATE ON student TO Sindhu;
By using above example we can give only select and update permissions to
Sindhu user
Ex:-3
SQL>GRANT ALL ON student to Sindhu;
By using above example, we can give all permissions to Sindhu user
REVOKE COMMAND
withdraw user’s access privileges given by using the GRANT command.
Syntax
SQL>REVOKE privileges ON object FROM user;
Ex: -
SQL>REVOKE select on student FROM Sindhu;
By using above example, we can get back select permission from Sindhu
user
SQL>REVOKE ALL on student from Sindhu;
By using above example, we can get back all permissions from Sindhu user
[Link] REDDY SINDHU DEGREE COLLEGE
[Link] REDDY
[Link] COMMANDS
TCL stands for transaction control language commands
TCL commands are
[Link]
[Link]
[Link] COMAND
COMMIT command is used to permanently save any transaction into the
database.
When we use any DML command like INSERT, UPDATE or DELETE,
the changes made by these commands are not permanent, until the current
session is closed, the changes made by these commands can be rolled back.
Syntax
SQL>commit;
[Link]
This command restores the database to last commited state.
Syntax SQL>rollback;
[Link] REDDY SINDHU DEGREE COLLEGE