1. If the statement cannot be executed in this way, you need
If not exists (select * From information_schema. columns where table_schema = 'thc _ RCM 'and table_name = 'cs _ accountbilldetail' and column_name = 'shotitemid') Then alter table 'thc _ RCM '. 'cs _ accountbilldetail 'add column 'show.titemid' varchar (64) default null comment 'order details id' after 'itemid'; end if;
2. This statement cannot be written because it must be executed in the stored procedure.
Delimiter // if not exists (select * From information_schema. columns where table_schema = 'thc _ RCM 'and table_name = 'cs _ accountbilldetail' and column_name = 'shotitemid') Then alter table 'thc _ RCM '. 'cs _ accountbilldetail 'add column 'show.titemid' varchar (64) default null comment 'order details id' after 'itemid'; end if; end // delimiter;
3. OK
Delimiter // create procedure thc_rcm_change () begin if not exists (select * From information_schema. columns where table_schema = 'thc _ RCM 'and table_name = 'cs _ accountbilldetail' and column_name = 'shotitemid') Then alter table 'thc _ RCM '. 'cs _ accountbilldetail 'add column 'show.titemid' varchar (64) default null comment 'order details id' after 'itemid'; end if; end // delimiter; call thc_rcm_change (); drop procedureif exists thc_rcm_change;
4. If the field to be added is changed to the Deleted field, the operation fails ???????????
DELIMITER //CREATE PROCEDURE thc_rcm_change () BEGIN IF not EXISTS ( SELECT * FROM information_schema. COLUMNS WHERE table_schema = ‘thc_rcm‘ AND table_name = ‘Cs_AccountBillDetail‘ AND column_name = ‘shopSetItemId‘ ) THEN ALTER TABLE `thc_rcm`.`Cs_AccountBillDetail` drop COLUMN shopSetItemId; END IF; END//DELIMITER ;CALL thc_rcm_change ();DROP PROCEDUREIF EXISTS thc_rcm_change;
Error Message
Query execution failed
Cause:
SQL error [1064] [42000]: You have an error in your SQL syntax; check the manual that corresponds to your MySQL Server version for the right syntax to use near ') then
Alter table 'thc _ RCM '. 'cs _ accountbilldetail' Drop column setmealdetai 'at line 1
Query execution failed
Delimiter and stored procedure