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

DML Commands and DCL Commands

Uploaded by

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

DML Commands and DCL Commands

Uploaded by

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

DML Commands

1. INSERT
INSERT Statement is used to insert new records into the database table.
Syntax:
INSERT INTO table_name (column1, column2, column3, ...) VALUES
(value1, value2, value3, ...);
Note: Column names are optional.
Example:
Both the below ways are correct.

INSERT INTO CUSTOMERS (InsuranceID, Name, DOB, NIN,


Location,email_id) VALUES ('123', 'Mango','2000-01-
01','56789','LO','[email protected]');
INSERT INTO CUSTOMERS VALUES ('123', 'Mango','2000-01-
01','56789','LO','[email protected]');
2. SELECT
Select statement is used to select data from database tables.
Syntax:
SELECT column1, column2, ...
FROM table_name
[where condition];
Example:
SELECT * FROM CUSTOMERS;
3. UPDATE
UPDATE statement is used to modify the existing values of records present in
the database table.
Syntax:
UPDATE table_name
SET column1 = value1, column2 = value2, ...
WHERE condition;
Example:
UPDATE CUSTOMERS SET email_id = '[email protected]' WHERE
InsuranceID='123';

4. DELETE
DELETE statement is used to delete the existing records present in the database
table.
Syntax:
DELETE FROM table_name where condition;
Example:
DELETE FROM CUSTOMERS where InsuranceID='123';
DCL Commands
In this sub section, let us learn the usage of below commands in detail.
1. GRANT
GRANT statement is used to provide access privileges to users to access the
database.
Syntax:
GRANT privileges ON object TO user;
Note: Privileges can be SELECT, INSERT, UPDATE, DELETE, TRUNCATE,
REFERENCES, TRIGGER, CREATE, ALL. You can also specify combination
of these privileges in a statement.
GRANT Connect to Database
GRANT CONNECT ON DATABASE database_name TO username;
GRANT Usage on Schema
GRANT USAGE ON SCHEMA database_name TO username;
Grant access to all tables in the database:
GRANT ALL PRIVILEGES ON ALL TABLES IN SCHEMA schema_name
TO username;
GRANT ALL PRIVILEGES ON ALL SEQUENCES IN SCHEMA
schema_name TO username;
GRANT ALL PRIVILEGES ON DATABASE database_name TO username;
Grant permission to create database:
ALTER USER username CREATEDB;
Grant superuser access to a user
ALTER USER myuser WITH SUPERUSER;

2. REVOKE
REVOKE statement is used to withdraw the access priviliges given to a user by
GRANT statement.
Syntax:
REVOKE privileges ON object FROM user;
Example:
REVOKE DELETE, UPDATE ON ORDERS FROM customer1;

You might also like