Cheat sheet SQL – Introduction
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.
Commands and Content on Cheatsheet SQL
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:
|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|
Free Tips and Tricks of using Cheatsheet SQL Commands:-
- The SQL cheat sheet commands can be used in any IDE or tool where the user has connected to the database using the JAR file of the database type.
- The different databases existing in the market are Oracle, Microsoft SQL Server, IBM DB2, etc., which all these can be connected to by using their respective jars and tools to manage the data operations.
- There is a different cheat sheet for SQL Aggregate Functions to be used along with the SQL cheat sheet commands to perform some complex operations based on the required data to query as below.
|COUNT||To count the number of elements in a list|
|SUM||To return the total sum of the elements in a list|
|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|
- Using a cheat sheet for SQL commands, VIEWS can also be managed and created.
- INDEXES and TRIGGERS can also be managed using cheat sheet SQL commands.
- The different cheat sheet SQL Operators are Arithmetic operators, Logical operators, Comparison operators, and Negation Operators similar to the general-purpose programming languages.
- The different cheat sheet for SQL Expressions is Numeric, Boolean and Date.
- The different SQL Constraints are the rules to execute the commands on the table columns to ensure reliability, redundancy, and accuracy while performing operations on a table.
- In the case of integrity, Referential Integrity plays a major role in performing integrity constraints along with the commands. The different constraints available are Integrity constraints and Dropping constraints.
- SQL Injection is another concept where the user-submitted data should always be validated before processing or running the query to avoid the data breach and to ensure safe and secure data operations without any loss of data.
Cheatsheet SQL – Conclusion
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.
This has been a guide to Cheatsheet SQL here we have discussed the content and command as well as free tips and tricks of cheat sheet SQL you may also look at the following article to learn more –
- SQL Interview Questions and answers – Top 12 Useful Questions
- Careers in SQL Server
- Careers in SQL
- Awesome Cheatsheet for UNIX
- 12 Most Successful TSQL Interview Questions And Answers
- Weblogic vs Tomcat: What are the Differences
- Examples of PostgreSQL Cross Join
- Guide to Examples of SQL Cross Join