Created
August 20, 2020 12:48
-
-
Save gbarreiro/a039c1f27d0279c0bbe5a6e795440c54 to your computer and use it in GitHub Desktop.
MySQL cheatsheet: variables
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- Local variables (must be declared inside a STORED PROCEDURE) | |
DECLARE john_age INT; -- defines the variable | |
SET john_age = 21; -- sets a hard-coded value to a variable | |
SELECT age INTO jonh_age FROM Students WHERE id = 10; -- stores the result of a query into a variable | |
-- Session (user-defined) variables | |
SET @current_age = 21; -- we don't need to define it before | |
SELECT age INTO @current_age FROM Students WHERE id = 10; -- stores the result of a query into a session variable |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment