SQL Cheatsheet

  • Data Definition Language:
CREATEDROPALTERRENAMETRUNCATE
  • Data Manipulation Language:
INSERTUPDATEDELETESELECT
  • Data Control Language:
GRANT type_of_permission ON database_name.table_name TO ‘username’@’localhost’
REVOKE type_of_permission ON database_name.table_name TO ‘username’@’localhost’
  • Transaction Control Language:
UPDATE peopleSET address = ‘xyz’WHERE p_id = 5COMMIT ;
UPDATE peopleSET address = ‘xyz’WHERE p_id = 5ROLLBACK;
  1. SQL Stored Procedures
DELIMITER $$CREATE PROCEDURE procedure_name (IN in_param data_type, OUT out_param data_type)BEGIN
SELECT * FROM
table_1 t
JOIN
table_2 e
ON t.id = e.id
WHERE t.id = in_param ;
END$$DELIMITER ;
SET @out_param =0 ;CALL database_name.procedure_name (in_param, @out_param) ;SELECT out_param ;
DELIMITER $$CREATE FUNCTION function_name( parameter data_type) RETURNS data_typeDECLARE variable_name data_typeBEGINSELECT * INTO parameterFROM table_name tJOIN 
table_name_2 e
ON t.id = e.id
WHERE t.id = paramter ;
RETURN variable_name ;END$$DELIMITER ;
SELECT function_name(parameter) ;

--

--

--

Hi there! I am currently a data analytics student at Canada, and is passionate about writing. I also love to read! Let’s connect on vineetagupta675@gmail.com

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Tracking Deployments With New Relic

Not so FaaS: Functions are the wrong abstraction for many things

Simplify HTTP requests with these libraries

XCode 11 & iOS 13 : Migration, Issues & their fixes

Deploying on Kubernetes #11: Annotations

Installing MySQL 8 from Scratch on Ubuntu 18.04 For Use By Many Students

CS371P Spring 2021: Samantha Tuapen

Server side Swift — MVC (unit tests)

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Vineeta J Gupta

Vineeta J Gupta

Hi there! I am currently a data analytics student at Canada, and is passionate about writing. I also love to read! Let’s connect on vineetagupta675@gmail.com

More from Medium

Learning How To Use (MS-SQL) DDL Statements to create SQL OBJECTS(Tables, Constraints, Triggers…

Create Your Own Database Using CSV files

Python Class Vs Method Class

SQL And Pandas, Complimenting Tools For Data Manipulation