/*==============================================================*/
/* Table: T_EB_BGCONTROLRECORD                                    */
/*==============================================================*/
/* 处理表结构变更 */
/*  创建备份字段 */
if not exists (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_EB_BGCONTROLRECORD' AND KSQL_COL_NAME IN ('FBIZID_BAK')) 
alter table T_EB_BGCONTROLRECORD add (FBIZID_BAK NVARCHAR(80) DEFAULT ' ' NOT NULL);

/* 备份数据 */
if exists (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_EB_BGCONTROLRECORD' AND KSQL_COL_NAME IN ('FBIZID_BAK'))
update T_EB_BGCONTROLRECORD set FBIZID_BAK = FBIZID;


/* 删除索引 */
IF EXISTS (SELECT 1 FROM KSQL_INDEXES WHERE KSQL_INDNAME = 'IDX_EB_BGCONTROLRECORD_BIZID')
drop index T_EB_BGCONTROLRECORD.IDX_EB_BGCONTROLRECORD_BIZID;


/* 重建字段及数据 */
 --- drop column --------- 请认真检查该脚本 ------------------- 
 EXEC p_AlterColumn 'T_EB_BGCONTROLRECORD', 'FBIZID', 'NULL', 'NULL', '1001', 'NULL';

if not exists (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_EB_BGCONTROLRECORD' AND KSQL_COL_NAME IN ('FBIZID'))
alter table T_EB_BGCONTROLRECORD add (FBIZID NVARCHAR(80) DEFAULT ' ' NOT NULL);

if exists (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_EB_BGCONTROLRECORD' AND KSQL_COL_NAME IN ('FBIZID'))
update T_EB_BGCONTROLRECORD set FBIZID = FBIZID_BAK;

/* 删除备份字段 */
 --- drop column --------- 请认真检查该脚本 ------------------- 
 EXEC p_AlterColumn 'T_EB_BGCONTROLRECORD', 'FBIZID_BAK', 'NULL', 'NULL', '1001', 'NULL';


/* 重建索引 */
IF NOT EXISTS (SELECT 1 FROM KSQL_INDEXES WHERE KSQL_INDNAME = 'IDX_EB_BGCONTROLRECORD_BIZID')
CREATE INDEX IDX_EB_BGCONTROLRECORD_BIZID ON T_EB_BGCONTROLRECORD (FBIZID ASC);
