Home > Database > Mysql Tutorial > 用sql脚本安全添加字段_MySQL

用sql脚本安全添加字段_MySQL

WBOY
Release: 2016-06-01 13:36:53
Original
1044 people have browsed it

bitsCN.com


用sql脚本安全添加字段

 

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;    

bitsCN.com
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template