Friday, 8 July 2016

DDL & DML

 DDL & DML

DDL-(DATA DEFINITION LANGUAGE)

1.CREATE

2.ALTER
     1.ADD
     2.MODIFY
     3.RENAME
     4.DROP
These four for Only the column level Operations

3.DROP
4.TRUNCATE

DML-(DATA MANIPULATION LANGUAGE)::

1.INSERT
2.UPDATE
3.DELETE
4.MERGE

DCL-(DATA CONTROL LANGUAGE)::

1.GRANT
2.REVOKE

TCL-(TRANSACTIONAL CONTROL LANGUAGE)::

1.COMMIT
2.ROLLBACK
3.SAVE POINT











CREATE::

Its mainly used for Create a New table.

SYNTAX::

CREATE TABLE TABLE_NAME (COL1 DATATYPE,COL2 DATATYPE.....);
EXAMPLE::

CREATE TABLE Students
(
STU_ID NUMBER(4),
STU_NAME VARCHAR(20),
STU_GENGER CHAR,
STU_DPT_ID NUMBER(10)
);

ALTER::

The ALTER is mainly used of done the column level changes like
1.ADD NEW COLUMNS
2.MODIFY THE EXISTING DATATYPES
3.RENAME THE EXISTING COLUMNS
4.DROP THE UNWANTED COLUMNS

1.ADD NEW COLUMNS::

Using ADD keyword we can add new columns in existing table.

SYNTAX::

ALTER TABLE <TABLE_NAME>
ADD <COL1_NAME DATATYPE..........>;

Example::


ALTER TABLE students
ADD Feedback VARCHAR2(50);

2.MODIFY THE EXISTING DATATYPES::

Using MODIFY keyword we can Modify existing column datatypes.

SYNTAX::

ALTER TABLE <TABLE_NAME>
MODIFY <COL1_NAME DATATYPE..........>;

Example::


ALTER TABLE students
MODIFY Feedback VARCHAR2(100);

3.RENAME THE EXISTING COLUMNS::

RENAME is mainly used for RENAME the existing column in a table.

SYNTAX::

ALTER TABLE <TABLE_NAME>
RENAME COLUMN <COL_NAME(OLD) TO COL_NAME(NEW)......>;

Example::


ALTER TABLE students
RENAME Column Feedback TO FEEDBACKS;

4.DROP THE UNWANTED COLUMNS::

DROP IN ALTER CASE is mainly used for DROP the particular unwanted columns in a table.

SYNTAX::

ALTER TABLE <TABLE_NAME>
DROP COLUMN <COL1_NAME.>;

Example::


ALTER TABLE students
DROP COLUMN FEEDBACKS;

INSERT::

The INSERT keyword is maily used for INSERT a new record into a table.

SYNTAX::

INSERT INTO TABLE_NAME VALUES('Col1_Date','Col2_Date','...','...')

Examples::

INSERT INTO Students Values('1','Arul','M','10');
INSERT INTO Students Values('2','Xavier','M','20');
INSERT INTO Students Values('4','Anu','F','30');
INSERT INTO Students Values('4','Vino','M','40');
INSERT INTO Students Values('5','Mathi','M','50');

DELETE::

The Delete is Works in Two Methods

1.We can delete Whole date from the table
2.We can Check the Condition in WHERE and delete the Particular data's.

SYNTAX_1::

DELETE FROM TABLE_NAME;
(Deletes Whole data's from the table)

SYNTAX_2::(USING WHERE CLAUSE)

DELETE FROM TABLE_NAME WHERE Col_Name='';

DELETE FROM TABLE WHERE COL_NAME IN ('','','')

Example_1::

DELETE FROM Students;
This query deletes all the data's from the table.

Example_2::

DELETE FROM Students WHERE STU_ID = '1';

Example_3::

DELETE FROM Students WHERE STU_ID IN ('2','3','4');

4.TRUNCATE::

TRUNCATE is same as the DELETE but here we cant check the WHERE Condition.It delete all the Data's from the table.
We cant roll back the data's again.

SYNTAX::

TRUNCATE TABLE TABLE_NAME;

Example::

TRUNCATE TABLE Students;

5.DROP::

DROP Is mainly used delete the Whole table and data's(Structure and data).

SYNTAX::

DROP TABLE TABLE_NAME;

Example::

DROP TABLE Students;











=====>DDL & DML END<=====

0 comments:

Post a Comment