本篇文章將通過儲存過程來判斷列(字段)是否存在。請看詳情。
判斷字段是否存在:drop procedure if exists schema_change;
delimiter //
create procedure schema_change() begin
declare currentdatabase varchar(100);
select database() into currentdatabase;
if not exists (select * from information_schema.columns where table_schema=currentdatabase and table_name = 'rtc_order' and column_name = 'ifupsend') then
alter table rtc_order
add column `ifupsend` bit not null default 0 comment '是否上傳 是否上傳';
end if;
end//
delimiter ;
call schema_change();
mysql 判斷字段否存在,如果存在就修改字段:drop procedure if exists proc_temppro;
if(@count>0) then
alter table 表名 change column `舊列名` `新列名` varchar(30) comment '字段說明';
end if;
end;
call proc_temppro;
drop procedure if exists proc_temppro;
通過儲存過程判斷字段是否存在,不存在則增加:drop procedure if exists pro_addcolumn;
create procedure pro_addcolumn() begin
if not exists(select 1 from information_schema.columns where table_name='component' and column_name='print_check_status') then
alter table component add print_check_status int(10) default 0;
end if;
if not exists(select 1 from information_schema.columns where table_name='component' and column_name='print_check_time') then
alter table component add print_check_time datetime null;
end if;
if not exists(select 1 from information_schema.columns where table_schema=podcloud and table_name='component' and column_name='print_check_back_reason') then
alter table component add print_check_back_reason varchar(500) default null;
end if;
end;
call pro_addcolumn;
drop procedure pro_addcolumn;
drop procedure if exists pro_addindex;
delimiter;
create procedure pro_addindex() begin if not exists (select * from information_schema.statistics where table_schema=currentdatabase and table_name = 'rtc_phototype' and index_name = 'index_name') then
alter table `rtc_phototype` add index index_name ( `imgtype` );
end if;
end;
delimiter;
call pro_addindex();
drop procedure pro_addindex;
mysql 字段值1 2 3 如何查詢3是否存在
我有乙個表 命名單位 結構如下 id type type id name parent hide 12 child 2 no1 r 36 0 32 child 2 no2 l 0 0 36 parent 1 no1 0 0 42 parent 1 no4 0 0 59 child 2 no5 t 0...
sql判斷表 字段是否存在
mysql 1 判斷乙個表是否存在 語法 select table name from information schema.tables where table name 表名 sql例子 select table name from information schema.tables where...
資料庫中是否存在某錶 表是否存在某欄位
判斷資料庫中是否存在某錶以及表書否存在某字段的sql語句 檢查資料庫是否存在表 1.0 select from sys.tables where name 流程例項表 2.0 select from dbo.sysobjects where id object id n 流程例項表 and obje...