SQL Commands
SQL Commands
CA Department
SELECT column1,
It is used to retrieve
column2, ...FROM
SELECT data from the
table_name WHERE
database
condition;
-- DQL (Data Query Language)
-- Example:
SELECT * FROM customers;
SELECT first_name, last_name FROM customers WHERE city = 'New
York';
-- 2. COUNT: Counts the number of rows in a table or a specific
column
SELECT COUNT(*) FROM orders;
SELECT COUNT(DISTINCT product_id) FROM order_items;
This revokes all privileges on the employees table from user john.
Example:
This revokes all privileges on the employees table from user john.
Transaction Control Language(TCL)
TCL commands can only use with DML commands like INSERT,
DELETE and UPDATE only.
Here are some commands that come under TCL:
•COMMIT
•ROLLBACK
•SAVEPOINT
Command Description Syntax
Creates a savepoint
SAVEPOINT within the current SAVEPOINT
transaction
MCQs
10. Which clause would you use with SELECT to retrieve unique
records only?
A) WHERE
B) DISTINCT
C) GROUP BY
D) JOIN
11. What does the COMMIT command do in SQL?
A) Removes user permissions
B) Ends a transaction and saves all changes
C) Rolls back all changes to the last save point
D) Deletes data from a table
14. Which command would you use to partially roll back a transaction
to a specific point?
A) ROLLBACK TO SAVEPOINT
B) COMMIT TO SAVEPOINT
C) REVOKE
D) DELETE
15. In SQL, which command is used to save all changes made in a
transaction to the database?
A) REVOKE
B) COMMIT
C) SAVEPOINT
D) ROLLBACK