Written by Sai Sandeep Thota on February 24, 2014 in Programming > SQL

Difference between DDL, DML and DCL Commands

GET ALERTS:

Get our Latest updates delivered to your mailbox!

In this article we are going to explain Difference between DDL, DML and DCL Commands and their usage with examples. So let us get started.
1. DDL – Data Definition Language
2. DML – Data Manipulation Language
3. DCL – Data Control Language

Data Definition Language – DDL

1. CREATE

CREATE is used to create tables in a Database.
Example:

CREATE TABLE tblname (fname varchar(50), lname varchar(50));

2. ALTER

ALTER is used to alter/modify table structure.
Example:

ALTER TABLE tblname ADD email varchar(50);

3. DROP

DROP is used to delete a table or column in a database.
Example:

DROP TABLE tblname;

4. TRUNCATE

TRUNCATE is used to remove all the records in a Database table.
Example:

TRUNCATE TABLE tblname;

Data Manipulation Language – DML

1. SELECT

SELECT is used to retrieve data from a Database table.
Example:

SELECT * FROM tblname;

2. INSERT

INSERT is used to insert/add records to a Database table.
Example:

INSERT INTO tblname (fname, lname, email) VALUES ('Sandeep', 'Thota', 'me@saisthota.com');

3. UPDATE

UPDATE is used to modify/update an existing record.
Example:

UPDATE tblname SET fname='Sai Sandeep' where fname='Sandeep';

4. DELETE

DELETE is used to remove a Record.
Example:

DELETE FROM tblname WHERE id=10;

We recommend reading: Basic SQL Queries – You must know.

Data Control Language – DCL

1. GRANT

GRANT is used to give permissions/rights to users on a Database.
Example:

GRANT ALL PRIVILEGES ON *.* TO 'sandeep'@'localhost';

The above command specifies to GRANT all permissions to user ‘sandeep’.

2. REVOKE

REVOKE is used to remove permission/rights to users on a Database.
Example:

REVOKE ALL PRIVILEGES, GRANT OPTION FROM 'sandeep'@'localhost';

You can read more on GRANT/REVOKE Permissions Commands in SQL here.

{ 0 comments… add one now }

Leave a Comment

Previous post:

Next post: