0% found this document useful (0 votes)
11 views2 pages

DBA SQL Cheat Sheet

This document is a cheat sheet for key SQL commands and syntax, covering DDL, DML, DCL, and TCL operations. It includes examples for creating and modifying tables, manipulating data, managing permissions, performing queries with joins, optimizing with indexes, and backing up/restoring databases in MySQL and PostgreSQL. The document serves as a quick reference for database administrators and developers.

Uploaded by

abirshikdar69
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views2 pages

DBA SQL Cheat Sheet

This document is a cheat sheet for key SQL commands and syntax, covering DDL, DML, DCL, and TCL operations. It includes examples for creating and modifying tables, manipulating data, managing permissions, performing queries with joins, optimizing with indexes, and backing up/restoring databases in MySQL and PostgreSQL. The document serves as a quick reference for database administrators and developers.

Uploaded by

abirshikdar69
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

DBA Cheat Sheet - Key SQL Commands & Syntax

1. DDL (Data Definition Language)

CREATE TABLE employees (


id INT PRIMARY KEY,
name VARCHAR(100),
department_id INT
);

ALTER TABLE employees ADD email VARCHAR(100);


DROP TABLE employees;

2. DML (Data Manipulation Language)

INSERT INTO employees (id, name, department_id) VALUES (1, 'John Doe', 101);
UPDATE employees SET name = 'Jane Doe' WHERE id = 1;
DELETE FROM employees WHERE id = 1;

3. DCL & TCL (Control Commands)

GRANT SELECT, INSERT ON employees TO user1;


REVOKE INSERT ON employees FROM user1;
COMMIT;
ROLLBACK;
SAVEPOINT my_savepoint;

4. Query Examples & Joins

SELECT * FROM employees e INNER JOIN departments d ON e.department_id = d.id;


SELECT * FROM employees WHERE department_id IN (SELECT id FROM departments WHERE
name = 'HR');
5. Index & Optimization

CREATE INDEX idx_dept_id ON employees(department_id);


EXPLAIN SELECT * FROM employees WHERE department_id = 101;

6. Backup & Restore (Examples)

-- MySQL
mysqldump -u root -p mydb > backup.sql
mysql -u root -p mydb < backup.sql

-- PostgreSQL
pg_dump mydb > backup.sql
psql mydb < backup.sql

You might also like