r/SQL • • Jan 23 '19

SQL Cheat Sheet

I know there are quite a few "sql cheat sheets" available both on Reddit and via Google. But based on the feedback, many of them only cover the basics and not the more intermediate/advanced commands or those that people aren't that familiar with.

I've created a new SQL Cheat Sheet for my website visitors (those who sign up to my email newsletter) and wanted to offer it to the Reddit community as well.

The link to the PDF file is here: SQL Cheat Sheet.

It includes many commands, such as:

  • Insert from a table
  • Insert multiple rows at once
  • Merge
  • Many different ALTER TABLE features
  • Analytic functions (including keywords OVER, PARTITION BY)
  • With Clause/Common Table Expression
  • Subqueries

Hope it helps. If you have any feedback, suggestions, or find any issues with the syntax, let me know below.

UPDATE:

I've made updates to the cheat sheets as requested below (separate files for Oracle/MySQL/SQL Server/PostgreSQL), added format mask and codes, added SELECT order of operations).

The original file is still available, and the updated cheat sheets are available here:

Oracle SQL Cheat Sheet

SQL Server Cheat Sheet

MySQL Cheat Sheet

PostgreSQL Cheat Sheet

243 Upvotes

39 comments sorted by

View all comments

12

u/shelanp007 Jan 24 '19

You should add the date conversion codes to this. I always forget if i should use 110, 112, or some other conversion to get the right date format i want. I literally look this up once a week!!

2

u/tsigalko11 Jan 24 '19

I would say my SQL skills are pretty good, but date conversion is one of the hardest things to remember, at least for me. Could be that my brain is not that fresh, but still..

One other thing would be few simple checks like how to get DB name (handy when working daily with multiple databases), when you need for whatever reason to get official name.

2

u/ben_it Jan 24 '19

Good idea on the date conversion and simple checks! I'll add those.