3. Structured Query Language (SQL)
• SQL (Structured Query Language) is a language to operate databases; it
includes Database Creation, Database Deletion, Fetching Data Rows,
Modifying & Deleting Data rows, etc.
• Types of SQL Statements-
1. DML(Data Manipulation Language)
2. DDL(Data Definition Language)
3. DCL(DataControl Language)
4. Introduction of DML
• The DML commands in StructuredQuery Language change the data present
in the SQL database. We can easily access, store, modify, update and delete
the existing records from the database using DML commands.
• Four Main types of DML commands
1. SELECTCommand
2. INSERT Command
3. UPDATE Command
4. DELETECommand
5. SELECT DML Command
• SELECT is the most important data manipulation command in Structured Query
Language.The SELECT command shows the records of the specified table. It also
shows the particular record of a particular column by using the WHERE clause.
• Syntax:
SELECT * FROM table_name;
• Example:
SELECT * FROM Student;
• Output:-
6. INSERT DML Command
• The INSERT INTO command in SQL allows the database users to insert one
or more records into the SQL table.
• Syntax:
INSERT INTOTable_Name VALUES(Value_1,Value_2,Value_3, .....,Value_N);
• Example
7. • You can create a record in CUSTOMERS table by using this syntax also.
INSERT INTOCUSTOMERS VALUES (6, PRATIK, 24, KANPUR);
OUTPUT:-
8. UPDATE DML Command
• SQL UPDATE statement is used to change the data of the records held by
tables. Which rows is to be update, it is decided by a condition.To specify
condition, we useWHERE clause.
• Syntax:
UPDATE table_name SET column_name = expression WHERE conditions .
• Example
9. • Example: here we are going to update an entry in the source table.
UPDATE students SET User_Name = 'beinghuman' WHERE Student_Id = '3' ;
• OUTPUT:-
10. DELETE DML Command
• The SQL DELETE statement is used to delete rows from a table. Generally
DELETE statement removes one or more records from a table.
• Syntax:
DELETE FROM table_name [WHERE condition];
• Example
11. • Example of delete with WHERE clause is given below:
DELETE FROM EMPLOYEE WHERE ID=101;
• OUTPUT:-
12. Introduction of DCL
• Data Control Language (DCL) deals with the commands used in SQL that
permit a user to access, modify or work on the different privileges in order to
control the database. It allows the database owner to give access, revoke
access, and change the given permissions as and when required. DCL is
basically used for enforcing data security.
• Types of DCL Commands in SQL
• Two types of DCL commands can be used by the user in SQL.
1. REVOKE Command
2. GRANT Command
13. GRANT DCL Command
• GRANT, as the name itself suggests, provides.This command allows the
administrator to provide particular privileges or permissions over a database
object, such as a table, view, or procedure. It can provide user access to
perform certain database or component operations.
• In simple language, the GRANT command allows the user to implement
other SQL commands on the database or its objects.The primary function
of the GRANT command in SQL is to provide administrators the ability to
ensure the security and integrity of the data is maintained in the database.
14. Implementing GRANT Statement
• Consider a scenario where you are the database administrator, and a
student table is in the database. Suppose you want a specific user Aman to
only SELECT (read)/ retrieve the data from the student table.Then you can
use GRANT in the below GRANT statement.
GRANT SELECT ON student TO Aman;
• This command will allow Aman to implement the SELECT queries on the
student table.This will enable the user to read or retrieve information from
the student table.
15. REVOKE DCL Command
• As the name suggests, revoke is to take away.The REVOKE command
enables the database administrator to remove the previously provided
privileges or permissions from a user over a database or database object,
such as a table, view, or procedure.The REVOKE commands prevent the
user from accessing or performing a specific operation on an element in the
database.
• In simple language, the REVOKE command terminates the ability of the
user to perform the mentioned SQL command in the REVOKE query on the
database or its component.The primary reason for implementing the
REVOKE query in the database is to ensure the data's security and integrity.
16. Implementing REVOKE Statement
• Consider a scenario where the user is the database administrator. In the
above implementation of the GRANT command, the user Aman was
provided permission to implement a SELECT query on the student table
that allowed Aman to read or retrieve the data from the table. Due to
certain circumstances, the administrator wants to revoke the
abovementioned permission.To do so, the administrator can implement the
below REVOKE statement:
REVOKE SELECT ON student FROM Aman;
• This will stop the user Aman from implementing the SELECT query on the
student table.The user may be able to implement other queries in the
database..
17. CONCLUSION
Understanding the role of DCL in managing permissions and DML in data
manipulation is fundamental for effective database management. By
implementing best practices and avoiding common mistakes, data security
and integrity can be upheld, ensuring the reliability of the database.