MySQL: Setting a variable to a value

This entry is part 21 of 26 in the series Learn MySQL

To set a variable explicitly to a particular value, use a SET statement.

SET syntax can use either := or = to assign the value.

set @price = 5.00;
update artist set price = @price where artiste = 'Rod Stewart'

select * from artist


Notice that in SQL, we have always used set to update a value in a table.

Series Navigation<< MySQL: Null variable
MySQL: Setting a select result to a variable >>