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

Complete SQL Commands Guide

This document serves as a comprehensive guide to SQL commands, categorizing them into Data Definition Language (DDL), Data Manipulation Language (DML), Data Query Language (DQL), Data Control Language (DCL), and Transaction Control Language (TCL). It includes commands for creating, altering, and deleting databases and tables, as well as manipulating and querying data, managing user privileges, and handling transactions. Additionally, it covers constraints, aggregate functions, operators, indexes, views, and stored procedures/functions.

Uploaded by

ayushsharma3069
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)
6 views2 pages

Complete SQL Commands Guide

This document serves as a comprehensive guide to SQL commands, categorizing them into Data Definition Language (DDL), Data Manipulation Language (DML), Data Query Language (DQL), Data Control Language (DCL), and Transaction Control Language (TCL). It includes commands for creating, altering, and deleting databases and tables, as well as manipulating and querying data, managing user privileges, and handling transactions. Additionally, it covers constraints, aggregate functions, operators, indexes, views, and stored procedures/functions.

Uploaded by

ayushsharma3069
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

Complete SQL Commands Guide

1. Data Definition Language (DDL)

• CREATE DATABASE database_name;


• CREATE TABLE table_name (...);
• DROP DATABASE database_name;
• DROP TABLE table_name;
• ALTER TABLE table_name ADD column datatype;
• ALTER TABLE table_name MODIFY column datatype;
• ALTER TABLE table_name DROP column;
• TRUNCATE TABLE table_name;
• RENAME TABLE old_name TO new_name;

2. Data Manipulation Language (DML)

• INSERT INTO table_name VALUES (...);


• INSERT INTO table_name (column1, column2) VALUES (...);
• UPDATE table_name SET column=value WHERE condition;
• DELETE FROM table_name WHERE condition;
• SELECT * FROM table_name;

3. Data Query Language (DQL)

• SELECT column1, column2 FROM table_name;


• SELECT DISTINCT column FROM table_name;
• SELECT column FROM table_name WHERE condition;
• SELECT column FROM table_name ORDER BY column ASC/DESC;
• SELECT column, COUNT(*) FROM table_name GROUP BY column;
• SELECT column FROM table_name HAVING condition;
• SELECT column FROM table1 JOIN table2 ON condition;

4. Data Control Language (DCL)

• GRANT privilege ON object TO user;


• REVOKE privilege ON object FROM user;

5. Transaction Control Language (TCL)

• COMMIT;
• ROLLBACK;
• SAVEPOINT savepoint_name;
• SET TRANSACTION;

6. Constraints

• PRIMARY KEY
• FOREIGN KEY
• UNIQUE
• NOT NULL
• CHECK
• DEFAULT

7. Aggregate Functions

• COUNT()
• SUM()
• AVG()
• MIN()
• MAX()

8. Operators

• Arithmetic: +, -, *, /
• Comparison: =, !=, >, <, >=, <=
• Logical: AND, OR, NOT
• IN, BETWEEN, LIKE, IS NULL

9. Indexes & Views

• CREATE INDEX index_name ON table_name(column);


• DROP INDEX index_name;
• CREATE VIEW view_name AS SELECT ...;
• DROP VIEW view_name;

10. Stored Procedures & Functions

• CREATE PROCEDURE procedure_name AS ...;


• CALL procedure_name;
• CREATE FUNCTION function_name RETURNS datatype AS ...;

You might also like