Oracle DDL ,DML & DCL
ABDUL REHMAN
DDL
• SCHEMA
– A database schema is the skeleton structure that
represents the logical view of the entire database. It
defines how the data is organized and how the
relations among them are associated.
• DATA DEFINATION LANGUAGE
– Are collection of those statements which are DIRECTLY
related to database Schema
• DDL STATEMENTS ARE
– CREATE, ALTER, DROP, REPLACE AND TRUNCATE
CREATE
• Used To Create Objects Like
– CREATE TABLE
– CREATE FUNCTION
– CREATE VIEW
– Etc.
CREATE TABLE STUDENT
(
STDROLLNO number(5) primary key,
NAME varchar2(20),
CAST varchar2(20)
);
STDROLLNO NAME CAST
ALTER
• Use to Alter Objects like
– ALTER TABLE
– ALTER USER
– ALTER DATABASE
ALTER TABLE STUDENT ADD
(
ADDRESS NVARCHAR2(50)
);
STDROLLNO NAME CASTSTDROLLNO NAME CAST ADDRESS
DROP
• Use to Drop Objects like
– DROP TABLE
– DROP USER
– DROP FUNCTION
– Etc
CREATE TABLE EXTRA
(
NUM number(5) primary key,
NAME nvarchar2(20)
);
NUM NAME
DROP TABLE EXTRA;
REPLACE
• Use to Rename table names.
RENAME STUDENT TO STUDENTS;
STDROLLNO NAME CAST ADDRESS
TRUNCATE
• Use to truncate (delete all rows) a table.
DML
• Data manipulation language (DML)
• Are the statements query and manipulate
data in existing schema objects.
– INSERT
– UPDATE
– DELETE
INSERT
• Insert into STUDENTS values (3,’Atif’,’Bhatti’,’UK’);
• Insert into STUDENTS values
(13,’Ahsan’,’Khanzada’,’SK’);
STDROLLNO NAME CAST ADDRESS
3 Atif Bhatti UK
13 Ahsan Khanzada SK
UPDATE
• USED TO MODIFY DATA IN DB
– UPDATE STUDENTS SET ADDRESS=‘NAWABSHAH’
WHERE NAME=‘Atif”;
STDROLLNO NAME CAST ADDRESS
3 Atif Bhatti UK
13 Ahsan Khanzada SK
STDROLLNO NAME CAST ADDRESS
3 Atif Bhatti Nawabshah
13 Ahsan Khanzada SK
DELETE
• Use the DELETE statement to delete the rows
from existing tables which are in your schema
or if you have DELETE privilege on them.
• DELETE STUDENTS WHERE NAME=‘Ahsan’;
STDROLLNO NAME CAST ADDRESS
3 Atif Bhatti Nawabshah
13 Ahsan Khanzada SK
DCL
• Data Control Language (DCL) Statements
– Data Control Language Statements are used to
grant privileges on tables, views, procedures to
other users or roles.
– The DCL statements are
• GRANK
• REVOKE
GRANT
• Use to grant privileges to other users or roles.
• grant select, update, insert on STUDENTS to
David;
REVOKE
• Use to take back privileges granted to other
users and roles.
• revoke select, update, insert on emp from
David;

Oracle Database DML DDL and TCL

  • 1.
    Oracle DDL ,DML& DCL ABDUL REHMAN
  • 2.
    DDL • SCHEMA – Adatabase schema is the skeleton structure that represents the logical view of the entire database. It defines how the data is organized and how the relations among them are associated. • DATA DEFINATION LANGUAGE – Are collection of those statements which are DIRECTLY related to database Schema • DDL STATEMENTS ARE – CREATE, ALTER, DROP, REPLACE AND TRUNCATE
  • 3.
    CREATE • Used ToCreate Objects Like – CREATE TABLE – CREATE FUNCTION – CREATE VIEW – Etc. CREATE TABLE STUDENT ( STDROLLNO number(5) primary key, NAME varchar2(20), CAST varchar2(20) ); STDROLLNO NAME CAST
  • 4.
    ALTER • Use toAlter Objects like – ALTER TABLE – ALTER USER – ALTER DATABASE ALTER TABLE STUDENT ADD ( ADDRESS NVARCHAR2(50) ); STDROLLNO NAME CASTSTDROLLNO NAME CAST ADDRESS
  • 5.
    DROP • Use toDrop Objects like – DROP TABLE – DROP USER – DROP FUNCTION – Etc CREATE TABLE EXTRA ( NUM number(5) primary key, NAME nvarchar2(20) ); NUM NAME DROP TABLE EXTRA;
  • 6.
    REPLACE • Use toRename table names. RENAME STUDENT TO STUDENTS; STDROLLNO NAME CAST ADDRESS
  • 7.
    TRUNCATE • Use totruncate (delete all rows) a table.
  • 8.
    DML • Data manipulationlanguage (DML) • Are the statements query and manipulate data in existing schema objects. – INSERT – UPDATE – DELETE
  • 9.
    INSERT • Insert intoSTUDENTS values (3,’Atif’,’Bhatti’,’UK’); • Insert into STUDENTS values (13,’Ahsan’,’Khanzada’,’SK’); STDROLLNO NAME CAST ADDRESS 3 Atif Bhatti UK 13 Ahsan Khanzada SK
  • 10.
    UPDATE • USED TOMODIFY DATA IN DB – UPDATE STUDENTS SET ADDRESS=‘NAWABSHAH’ WHERE NAME=‘Atif”; STDROLLNO NAME CAST ADDRESS 3 Atif Bhatti UK 13 Ahsan Khanzada SK STDROLLNO NAME CAST ADDRESS 3 Atif Bhatti Nawabshah 13 Ahsan Khanzada SK
  • 11.
    DELETE • Use theDELETE statement to delete the rows from existing tables which are in your schema or if you have DELETE privilege on them. • DELETE STUDENTS WHERE NAME=‘Ahsan’; STDROLLNO NAME CAST ADDRESS 3 Atif Bhatti Nawabshah 13 Ahsan Khanzada SK
  • 12.
    DCL • Data ControlLanguage (DCL) Statements – Data Control Language Statements are used to grant privileges on tables, views, procedures to other users or roles. – The DCL statements are • GRANK • REVOKE
  • 13.
    GRANT • Use togrant privileges to other users or roles. • grant select, update, insert on STUDENTS to David;
  • 14.
    REVOKE • Use totake back privileges granted to other users and roles. • revoke select, update, insert on emp from David;