I'm writing an script to update a db schema, the script is the following:
delimiter //
begin
set @check_exists = 0;
select count(*)
into @check_exists
from information_schema.columns
where table_schema = 'my_app'
and table_name = 'users'
and column_name = 'points';
if (@check_exists = 0) then
alter table my_app.users
add points int not null default 0
end if;
end //
delimiter
when I run it, i get the below error:
Reason:
SQL Error [1064] [42000]: (conn=34) You have an error in your SQL syntax;
check the manual that corresponds to your MariaDB server version for the right syntax
to use near 'set @check_exists = 0;
I have already checked the answers the below two posts but none solves my problem.