需求是这样的,我需要扩展表,增加一列point,增加前我需要先判断是否存在该列,若不存在则添加列,反之则不做任何操作
我的sql语句总是报错,而括号中的语句是可以执行的
IF exists(select column_name from information_schema.columns where table_schema='test' and table_name='t_user' and column_name='point' )
select 'tt';求教正确写法
我的sql语句总是报错,而括号中的语句是可以执行的
IF exists(select column_name from information_schema.columns where table_schema='test' and table_name='t_user' and column_name='point' )
select 'tt';求教正确写法
DELIMITER $$
CREATE PROCEDURE gg()
BEGIN
IF EXISTS(SELECT column_name FROM information_schema.columns WHERE table_schema='test' AND table_name='t_user' AND column_name='point' ) THEN
SELECT 'tt';
END IF;
END$$
DELIMITER ;
create procedure gg()
begin
if exists(select column_name from information_schema.columns where
table_schema='test' and table_name='t_user' andn column_name='point')
then
select 'tt';
end if;
end$$
delimiter$$;
create procedure gg()
begin
if exists(select column_name from information_schema.columns where
table_schema='test' and table_name='t_user' andn column_name='point')
then
select 'tt';
end if;
end$$
delimiter;
table_schema='test' and table_name='t_user' andn column_name='point' ;
select @testresult
if (@testresult='1') then
select 'yes';
end if
到select @testresult 这没问题,但是if语句怎么又报脚本错误呢?? mysql与Sql Server差别很大啊