Table Definition
• A table is uniquely identified by its name and consists of rows that
contain the stored information,
• each row containing exactly one tuple (or record ). A table can have
one or more columns.
DDL
DML(DRL)
TCL
DCL
DDL
• When ever SQL Statement is terminated it will be placed in " afiedt.buf ".
Later if there are no errors Transaction will be carried out. Otherwise error
message will be displayed.
INSERT
• DML Command.
• To insert rows in to Table.
• Syntax 1 : INSERT INTO < TABLE_NAME > VALUES (VAL1,VAL2,
...........,Val n);
Example : INSERT INTO EMP VALUES (1001,'BABU','MANAGER','20-
JAN-2004',8000,20);
To insert Multiple rows in to a Table with this Syntax we have type the
Command repeatedly.
• DRL Command.
• To retrieve information from the Tables.
• Syntax : SELECT * FROM < TABLE_NAME >;
Example : SELECT * FROM EMP;
ALTER
• DDL Command.
• To Modify any Existing Tables.
• Syntax : ALTER TABLE < TABLE_NAME >
[ADD | MODIFY | DROP | DISABLE | ENABLE]
(COL_NAME1 DEFINITION,
COL_NAME2 DEFINITION,
........
COL_NAME n DEFINITION )
ALTER (...CONTINUED)
ADD
• DDL Command.
• To remove any object from schema.
• Drops both Information and Structure of the Table.
• Syntax : DROP < OBJECT_TYPE > <
OBJECT_NAME >;
• Example : DROP TABLE EMP;
TRUNC
• DDL Command.
• Removes rows in the Table Permanently.
• Syntax : TRUNC TABLE < TABLE_NAME >;
• Example : TRUNC TABLE EMP;
• WHERE Clause cannot be used with TRUNC.
• Only information deleted, Not Structure.
• Auto-Commit Command.
• EXIT and QUIT are Implicit Commit statements.
UPDATE
• DML Command.
• To Modify any existing information in the table.
• Syntax : UPDATE < TABLE_NAME > SET <
COLUMN_NAME > = < VALUE > [ WHERE
<CONDITION> ];
• Example : UPDATE EMP SET SAL = 9000 WHERE
EMPNO=1002;
• To UPDATE multiple columns with in a row separate
them by Commas.
• Example: UPDATE EMP SET SAL =
9000,COMM=1000 WHERE EMPNO=1002;
DELETE
• DML Command.
• To Delete rows from the Table.
• Syntax : DELETE FROM < TABLE_NAME > [ WHERE
<CONDITION> ];
• If Condition not specified all rows of the table will be
deleted.
• Example : DELETE FROM EMP;
• If Condition specified all rows of the table satisfying the
Condition will be deleted.
• Example : DELETE FROM EMP WHERE JOB =
'MANAGER‘;
COMMIT & ROLL BACK
• TCL Commands.
• Whenever we update data it will be first placed in o buffer.
• If we COMMIT the buffer information will be stored
permanently in physical location.
• If we ROLLBACK we get previous values.
• DDL Commands are AUTO-COMMIT statements.
• If DDL Commands are used after Transactions all those
transactions will Automatically Commit.
SAVEPOINT
• Suppose there are 'N' transactions after COMMIT Point.
• If 'Nth' transaction is to be ROLLED BACK all previous
N-1 transactions will also get ROLLED BACK.
• To avoid this we have SAVEPOINT.
• If we have SAVEPOINT in between Transactions, If we
ROLLBACK only transactions after specified
SAVEPOINT will be ROLLED BACK.
• On using COMMIT there will be no more SAVEPOINTs.
SAVEPOINT (...CONTINUED)
• Example :
• UPDATE EMP SET SAL = 9000 WHERE EMPNO=1002;
SAVEPOINT A;
• Example : ROLLBACK TO B;
GRANT
• DCL Command.
• To Grant Permission to user to any Table.
• The Data Dictionary Tables related to Privileges:
• USER_TAB_PRIVS_MADE : What privileges are
given?
• USER_TAB_PRIVS_RECD : Who gave the privileges?
GRANT (...CONTINUED)
• To give all the privileges to user.
Syntax : GRANT ALL ON < TABLE_NAME > TO <USER_NAME
>;
ALL means INSERT, DELETE, SELECT, ALTER & INDEX.
Object Description
Oracle Server
iSQL*Plus
USER_VIEWS
SELECT * EMPVU30
FROM EMPVU30; SELECT EMPNO,
ENAME, SAL
FROM EMP
WHERE DEPTNO=30;
EMP
What is an Index?
An index:
• Is a schema object
• Is used by the Oracle server to speed up the retrieval of
rows by using a pointer
• Can reduce disk I/O by using a rapid path access method to
locate data quickly
• Is independent of the table it indexes
• Is used and maintained automatically by the Oracle server
How Are Indexes Created?
• NOT NULL
• UNIQUE
• PRIMARY KEY
• CHECK
• REFERENTIAL
LEVELS OF CONSTRAINTS
• COLUMN LEVEL
SYNTAX: CONSTRAINT <CONSTRAINT_NAME>
<CONSTRAINT_TYPE>
• TABLE LEVEL
SYNTAX: CONSTRAINT <CONSTRAINT_NAME>
<CONSTRAINT_TYPE> (COLUMN_NAME)
Functionally no difference between Column level and
Table level constraints.
CONSTRAINTS(…Contd)
• NOT NULL is Column level constraint.
• To add NOT NULL constraint after table creation use
MODIFY. For others we use ADD.
• If constraint name is not given, the system will provide its
own name.
• The constraints information will be stored under
USER_CONSTRAINTS ,USER_CONS_COLUMN.
• Only one Primary Key is allowed per table.
• On a single column four types of constraints can be
enforced at a time
• Two or more check constraints can be enforced on a
column at a time.
COLUMN LEVEL CONSTRAINT