0% found this document useful (0 votes)
3 views

SQL Statements

Uploaded by

tarunnayak60
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

SQL Statements

Uploaded by

tarunnayak60
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 8

SQL STATEMENTS

Master flow chart DDL DCL DML

DDL COMMANDS

CREATE TABLE:

1.
2. DROP TABLE
3. alter
DML

DML(Data Manipulation Language)

The SQL commands that deal with the manipulation of data present in the database belong to DML
or Data Manipulation Language and this includes most of the SQL statements.

It is the component of the SQL statement that controls access to data and to the database. Basically,
DCL statements are grouped with DML statements.

1. SELECT- Used to retrieve data from a database.

2. insert

3. update
4. Delete

DCL COMMANDS

DCL Commands

Data Control Language commands control access to the database and manage user permissions. DCL
commands include:

 GRANT: It is used to give access privileges to a user.

 REVOKE: It is used to revoke or withdraw the access privileges given.

TCL Commands

Transaction Control Language Commands are used to manage transactions within a database. TCL
commands include:

 COMMIT: To commit a transaction.

 ROLLBACK: To roll back or cancel a transaction if any error occurs.

 SAVEPOINT: To set a save point.

Also read, Natural Join in SQL

How is Data Control done in SQL?

Data control, as the name suggests, means controlling the data stored in the database. It refers to
managing access and permissions to a database. Data control is done with the help of (Data Control
Language) DCL Commands in SQL.

 DCL commands in SQL provide a way to authorize access to the data. They limit the users to
access the data and manipulate it.

 Some Data Control Language (DCL) commands are GRANT, REVOKE, and DENY.

 GRANT command grants the privileges, and the REVOKE command takes away the authority
or the privileges.

 This ensures the security and integrity of the database management system.

Various DCL Commands in SQL?


DCL (Data Control Language) commands in SQL are necessary for managing permissions and
privileges that control access to database objects. They play a crucial role in ensuring data security
and integrity. Here are various essential DCL (Data Control Language) commands in SQL that are
widely used for managing permissions and privileges related to database objects, ensuring secure
and controlled access:

Also read about, gzip command in linux

1. GRANT Command

This DCL command grants specific privileges to users on a table, view, or stored procedure.

Syntax

GRANT [privilege_name] ON [object_name] TO [user_name]

or

GRANT privilege_name ON object_name TO user_name WITH GRANT OPTION

where

privilege_name

It refers to the name of the privilege to be granted.

object_name

It refers to the name of the table, view, or object on which the privilege has to be granted.
user_name

It refers to the user or role to which the privilege is granted.

WITH GRANT OPTION

It means that the user who has been granted some privileges can further grant those privileges to
other users.

Example

Suppose we have a table named STUDENT created in the following way:

CREATE TABLE STUDENT(RNO NUMBER(10),NAME CHAR(20),AGE NUMBER(2),CITY CHAR(10),MARKS


NUMBER(3));

INSERT INTO STUDENT VALUES(1, 'Sasha',17,'Faridabad',80);

INSERT INTO STUDENT VALUES(2,'John',18,'Agra',91);

INSERT INTO STUDENT VALUES(3,'Sara',17,'Hisar',86);

INSERT INTO STUDENT VALUES(4,'Rohan',16,'Faridabad',79);

INSERT INTO STUDENT VALUES(5,'Virat',18,'Delhi',80);

SELECT * FROM STUDENT;


RNO Name Age City Marks

1 Sasha 17 Faridabad 80

2 John 18 Agra 91

3 Sara 17 Hisar 86

4 Rohan 16 Faridabad 79

5 Virat 18 Delhi 80

2.REVOKE Command

This command revokes the previously granted privileges through the GRANT command. from a user.
It reverts to the point when there is no access.

Syntax

REVOKE [privilege_name] ON [object_name] FROM [user_name]

where

privilege_name

It refers to the privilege that was granted.

object_name

It refers to the specific object whose access was granted.

user_name

It refers to the name of the user from which the privilege is being revoked.

Example

Suppose we have a table named STUDENT created in the following way:

CREATE TABLE STUDENT(RNO NUMBER(10),NAME CHAR(20),AGE NUMBER(2),CITY CHAR(10),MARKS


NUMBER(3));

INSERT INTO STUDENT VALUES(1, 'Sasha',17,'Faridabad',80);

INSERT INTO STUDENT VALUES(2,'John',18,'Agra',91);

INSERT INTO STUDENT VALUES(3,'Sara',17,'Hisar',86);

INSERT INTO STUDENT VALUES(4,'Rohan',16,'Faridabad',79);

INSERT INTO STUDENT VALUES(5,'Virat',18,'Delhi',80);

SELECT * FROM STUDENT;


RNO Name Age City Marks

1 Sasha 17 Faridabad 80

2 John 18 Agra 91

3 Sara 17 Hisar 86

4 Rohan 16 Faridabad 79

5 Virat 18 Delhi 80

Benefits of Implementing DCL Commands

 Enhanced security: DCL commands enable administrators to restrict access to sensitive


system resources.

 Automation: DCL commands facilitate automated execution of tasks, streamlining


administrative processes.

 Customization: DCL commands allow customization of user permissions and system


configurations according to specific requirements.

Disadvantages of Implementing DCL Commands

 Complexity: Implementing DCL commands may require a steep learning curve for
administrators unfamiliar with command-line interfaces.

 Risk of errors: Manual entry of commands increases the likelihood of human error,
potentially leading to system misconfigurations or data loss.

 Limited user interface: DCL commands typically lack graphical user interfaces, making them
less intuitive for novice users compared to graphical management tools.

Additional : sql basic commands for bolean and sql injection and how do the logic work

You might also like