This article serves as an SQL cheat sheet, summarizing key SQL commands handy for anyone working with databases. You can also download a detailed SQL cheat sheet here.
SQL commands are grouped as follows:
DML Commands
These include SELECT
, INSERT
, UPDATE
, and DELETE
.
SELECT *
FROM customers
WHERE age > 30;
Fetches customers over 30 years old.
INSERT INTO customers (name, age)
VALUES ('Alice', 22);
Adds a new customer.
DDL Commands
Commands like CREATE
and DROP
help in structuring and managing database objects.
CREATE TABLE employees (id INT, name VARCHAR(100));
Creates a new table.
DROP TABLE employees;
Deletes the table.
FAQ
What are aggregate functions?
Functions like COUNT
, SUM
, and AVG
, which perform calculations on a set of values.
Can SQL handle date and time?
Yes, using functions like CURRENT_DATE()
and DATE_ADD()
.
Can SQL update multiple records at once?
Yes, the UPDATE
command can modify multiple records simultaneously, for example,
UPDATE employees SET status = 'Active'
WHERE status = 'Inactive';
What is the role of SQL in database security?
SQL includes DCL commands like GRANT
and REVOKE
to manage access and permissions, enhancing database security.
Conclusion
For those looking to enhance their database skills, this SQL cheat sheet offers a solid foundation without overwhelming details. Read this article SQL Cheat Sheet: The Ultimate Guide to All Types of SQL JOINS.