DDL (DATA DEFINATION LANGUAGE):
- To handle the database object we use DDL commands.
- They are auto commit commands.
- They are session independent.
ALTER
DROP
RENAME(9I)
PURGE(10G)
FLASHBACK(10G)
COMMENT
TRUNCATE……
-----------------------------------------------------------------------------------------
CREATE:
- Which is used to define database
- Objects (tables, view, sequences…)
- Creating a table is our main concern for us here.
SYN: CREATE TABLE
(
COL1 DTPS(S),
COL2 DTPS(S),
….);
EG: CREATE TABLE NEWTAB
(SNO NUMBER (5),SNAME VARCHAR2(10));
Note:
A table can contain max of 1000 columns.
--------------------------------------------------------------------------------------------
ALTER:
We use alter to modify the structure of database
objects with the help of keywords.
KEY WORDS:
a) ADD - To add columns
b) MODIFY - To modify column datatypes and size
c) RENAME -To
rename column and table names
d) DROP - To drop columns
-------------------------------------------------------------------------------------------
a) ADD:
SYN:
ALTER TABLE ADD
(
COL DTPS(S),
COL1 DTPS(S),
…);
EG: ALTER TABLE NEWTAB ADD(ID NUMBER(5),LOC
VARCHAR2(10));
------------------------------------------------------------------------------------------
b) MODIFY: To modify the column datatype & even size also
SYN: ALTER TABLE MODIFY
(
COL NEW DATA TYPE(S),
COL NEW DATA TYPE(S)
);
EG:
ALTER TABLE NEWTAB MODIFY (ID NUMBER (10), LOC NUMBE R(5));
-----------------------------------------------------------------------------------------
c) RENAME:
To rename a
column name
SYN:
ALTER
TABLE RENAME COLUMN OLD COLUMN NAME
TO
NEW COLUMN NAME.
------------------------------------------------------------------------------------------
d) DROP:
To drop columns
SYN: ALTER TABLE DROP COLUMN COLUMNAME;
(OR)
ALTER TABLE TABLENAME DROP (COL1, COL2,
COL3,..);
EG: ALTER TABLE NEWTAB DROP COLUMN LOC;
(OR)
ALTER TABLE NEWTAB DROP (ID, BALANCE);
--------------------------------------------------------------------------------------------
RENAME:
To rename a
database object name
SYN: RENAME OLDNAME TO NEWNAME;
EG: RENAME NEWTAB TO NEWTAB1;
--------------------------------------------------------------------------------------------
DROP:
To drop database
objects
SYN: DROP TABLE
TABLENAME;
EG : DROP TABLE NEWTAB1;
-------------------------------------------------------------------------------------------- TRUNCATE(DELETE+COMMIT):
SYN: TRUNCATE TABLE
;
EG: TRUNCATE TABLE NEWTAB;
--------------------------------------------------------------------------------------
PURGE: TO DROP THE TABLE FROM RECYCLEBIN;
SYN:
PURGE TABLE ;
TO BIPASS THE TABLE
FROM RECYCLEBIN;
SYN:
DROP TABLE PURGE;
-----------------------------------------------------------------------------------------
FLASHBACK:
- To retrieve the drop table
- From 10g onwards we have a concept called recycle in
- If you drop the table or database object for that matter
- They store in the recyclebin.to get back the object from
- Recycle in we user flashback (10g)
SYN: FLASHBACK TABLE TO BEFORE DROP;
EG:
DROP
TABLE TL;
SELECT * FROM TL;
FLASHBACK TABLE TL TO BEFORE
DROP;
SELECT * FROM TL;
------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------------------
COMMENT:
SYN:
COMMENT ON TABLE |COLUMN
TABLENAME.COLUMNAME IS ‘TEXT’
EG: COMMENT ON TABLE TL IS
‘HELLO’;
SELECT * FROM USER_TAB_COMMENTS
WHERE TABLE_NAME=’TL’;
No comments:
Post a Comment