用sql脚本,安全添加字段
2016-06-11 14:40
267 查看
CREATE PROCEDURE safe_add_col(tname VARCHAR(50),cname VARCHAR(50))
BEGIN
SET @a = '';
SELECT column_name into @a
FROM information_schema.columns
WHERE table_name = tname AND column_name = cname;
IF @a = '' THEN
alter table tbl_application_source_down add import_batch VARCHAR(14) DEFAULT '' NOT NULL;
END IF;
END;
call safe_add_col('user','real_name');
DROP PROCEDURE IF EXISTS safe_add_col;
BEGIN
SET @a = '';
SELECT column_name into @a
FROM information_schema.columns
WHERE table_name = tname AND column_name = cname;
IF @a = '' THEN
alter table tbl_application_source_down add import_batch VARCHAR(14) DEFAULT '' NOT NULL;
END IF;
END;
call safe_add_col('user','real_name');
DROP PROCEDURE IF EXISTS safe_add_col;
相关文章推荐