SQL often called Structured Query Language is a declarative and multi-paradigm language that is the domain-specific language used for designing and managing data models to organize the data in relational model databases. SQL was designed by Donald Chamberlin and Raymond Boyce. SQL first appeared in the year 1974. SQL is static typing and strong discipline. SQL supports cross-platform operating systems. The file extension will be .sql and was developed by ISO/IEC. SQL has different sublanguages called statements to perform different operations based on the required operation.
Cheatsheet SQL commands can be classified into different categories which can be classified as Data Definition Commands, Data Manipulation Commands, and Data Control Commands. Below are the Cheatsheet SQL commands mentioned which perform different kinds of operations:
| QUERY | DESCRIPTION |
| DATA MANIPULATION COMMANDS | |
| Select * from <table_name>; | To query entire data from the mentioned table |
| Select col1, col2 from <table_name>; | To retrieve two columns from a table |
| Select col1, col2 from table WHERE condition; | To query data from a table based on a condition |
| Select distinct col from <table_name>; | To query distinct records from a table |
| Select distinct col from table WHERE condition; | To query distinct records from a table based on a condition to filter the data |
| Select col1, col2 from table ORDER BY col2 ASC; | To query data from a table and sort the retrieved records in ascending order |
| Select col1, col2 from table ORDER BY col2 DESC; | To query data from a table and sort the retrieved records in descending order |
| Select aggregate(col1), col2 from table GROUP BY col2; | To query data from the table to aggregate the data based on a column. |
| Select aggregate(col1), col2 from table GROUP BY col2 HAVING condition; | To query data from the table to aggregate the data based on a column and a condition. |
| Select col1, col2 from table1 INNER JOIN table2 ON condition; | To query data from multiple tables and inner join the result based on a condition and display a single result |
| Select col1, col2 from table1 LEFT JOIN table2 ON condition; | To query data from multiple tables and left join the result based on a condition and display as a single result |
| Select col1, col2 from table1 RIGHT JOIN table2 ON condition; | To query data from multiple tables and right join the result based on a condition and display as a single result |
| Select col1, col2 from table1 FULL OUTER JOIN table2 ON condition; | To query data from multiple tables and full outer join the result based on a condition and display as a single result |
| Select col1, col2 from table1 CROSS JOIN table2; | To query data from multiple tables and cross join the result to obtain a Cartesian product of the records and display as a single result |
| Select col1, col2 from table1 UNION select col1, col2 from table2; | To query data from multiple tables and combine the results of records from two tables. |
| DATA DEFINITION COMMANDS | |
| CREATE TABLE table_name (col_name DATA_TYPE CONSTRAINT); | To create a table with new columns and all the column definition can be mentioned by a comma |
| ALTER TABLE table_name; | To add a new column to the table |
| DROP TABLE table_name; | To delete the entire table from the database |
| INSERT INTO table_name(list of columns) VALUES(list of values); | To insert data into a table for one record. |
| UPDATE table SET col1=updated_value; | To update a cell value in a table based on column name |
| UPDATE table SET col1=updated_value1, col2=updated_value2 WHERE condition; | To update multiple cell values in a table based on column names and condition |
| DELETE FROM table_name; | To delete the complete data in a table. |
| DELETE FROM table_name WHERE condition; | To delete the complete data in a table based on a condition. |
| DATA CONTROL COMMANDS | |
| GRANT <Object Privileges> ON <Object Name> TO <user> [GRANT OPTION] | To grant access to a particular user based on the grant option and access requirement. |
| REVOKE <Object Privileges> ON <Object Name> FROM <user> | To revoke access to a particular user from a particular object |
| FUNCTION | DESCRIPTION |
| COUNT | To count the number of elements in a list |
| SUM | To return the total sum of the elements in a list |
| MAX | |
| AVG | To return the average of a list |
| MIN | To return the minimum value from a list |
| MAX | To return the maximum value from a list |
SQL is used to perform database operations on many relational model databases to perform several crud operations. The common language for all relational model databases is SQL (Structured Query Language). The formula only differs in all the databases. All the features in SQL cheat sheet commands can be used to performs mostly all the complex operations or data requirements in any application or directly to generate reports or data files to export or import to or from respectively from the databases.
Not a member yet? Register now
Are you a member? Login now