-- 健康模块步骤二:老人社会属性采集。 -- 仅增加可空字段,既有步骤一档案可逐步补齐;不删除、不改写现有数据。 -- 需在 V000、V001、V002、V003 后执行,可重复执行。 SET NAMES utf8mb4; SET @health_step2_sql = IF((SELECT COUNT(*) FROM information_schema.columns WHERE table_schema = DATABASE() AND table_name = 'health_elderly_profile' AND column_name = 'marital_status') = 0, 'ALTER TABLE health_elderly_profile ADD COLUMN marital_status tinyint NULL COMMENT ''0 未婚、1 已婚、2 离异、3 丧偶、4 不方便说''', 'DO 0'); PREPARE health_step2_stmt FROM @health_step2_sql; EXECUTE health_step2_stmt; DEALLOCATE PREPARE health_step2_stmt; SET @health_step2_sql = IF((SELECT COUNT(*) FROM information_schema.columns WHERE table_schema = DATABASE() AND table_name = 'health_elderly_profile' AND column_name = 'native_place') = 0, 'ALTER TABLE health_elderly_profile ADD COLUMN native_place varchar(20) NULL COMMENT ''籍贯县级行政区划编码''', 'DO 0'); PREPARE health_step2_stmt FROM @health_step2_sql; EXECUTE health_step2_stmt; DEALLOCATE PREPARE health_step2_stmt; SET @health_step2_sql = IF((SELECT COUNT(*) FROM information_schema.columns WHERE table_schema = DATABASE() AND table_name = 'health_elderly_profile' AND column_name = 'residence_area') = 0, 'ALTER TABLE health_elderly_profile ADD COLUMN residence_area varchar(20) NULL COMMENT ''长期居住地县级行政区划编码''', 'DO 0'); PREPARE health_step2_stmt FROM @health_step2_sql; EXECUTE health_step2_stmt; DEALLOCATE PREPARE health_step2_stmt; SET @health_step2_sql = IF((SELECT COUNT(*) FROM information_schema.columns WHERE table_schema = DATABASE() AND table_name = 'health_elderly_profile' AND column_name = 'residence_address') = 0, 'ALTER TABLE health_elderly_profile ADD COLUMN residence_address varchar(500) NULL COMMENT ''长期居住地详细地址''', 'DO 0'); PREPARE health_step2_stmt FROM @health_step2_sql; EXECUTE health_step2_stmt; DEALLOCATE PREPARE health_step2_stmt; SET @health_step2_sql = IF((SELECT COUNT(*) FROM information_schema.columns WHERE table_schema = DATABASE() AND table_name = 'health_elderly_profile' AND column_name = 'residence_type') = 0, 'ALTER TABLE health_elderly_profile ADD COLUMN residence_type tinyint NULL COMMENT ''1 城市、2 农村、3 城镇、4 牧区、5 其他''', 'DO 0'); PREPARE health_step2_stmt FROM @health_step2_sql; EXECUTE health_step2_stmt; DEALLOCATE PREPARE health_step2_stmt; SET @health_step2_sql = IF((SELECT COUNT(*) FROM information_schema.columns WHERE table_schema = DATABASE() AND table_name = 'health_elderly_profile' AND column_name = 'living_status') = 0, 'ALTER TABLE health_elderly_profile ADD COLUMN living_status tinyint NULL COMMENT ''1 独居、2 与配偶、3 与子女、4 养老机构、5 其他''', 'DO 0'); PREPARE health_step2_stmt FROM @health_step2_sql; EXECUTE health_step2_stmt; DEALLOCATE PREPARE health_step2_stmt; SET @health_step2_sql = IF((SELECT COUNT(*) FROM information_schema.columns WHERE table_schema = DATABASE() AND table_name = 'health_elderly_profile' AND column_name = 'household_type') = 0, 'ALTER TABLE health_elderly_profile ADD COLUMN household_type tinyint NULL COMMENT ''1 城镇、2 农村''', 'DO 0'); PREPARE health_step2_stmt FROM @health_step2_sql; EXECUTE health_step2_stmt; DEALLOCATE PREPARE health_step2_stmt; SET @health_step2_sql = IF((SELECT COUNT(*) FROM information_schema.columns WHERE table_schema = DATABASE() AND table_name = 'health_elderly_profile' AND column_name = 'education_level') = 0, 'ALTER TABLE health_elderly_profile ADD COLUMN education_level tinyint NULL COMMENT ''1 文盲、2 小学、3 初中、4 高中、5 大专、6 本科及以上''', 'DO 0'); PREPARE health_step2_stmt FROM @health_step2_sql; EXECUTE health_step2_stmt; DEALLOCATE PREPARE health_step2_stmt; SET @health_step2_sql = IF((SELECT COUNT(*) FROM information_schema.columns WHERE table_schema = DATABASE() AND table_name = 'health_elderly_profile' AND column_name = 'occupation') = 0, 'ALTER TABLE health_elderly_profile ADD COLUMN occupation varchar(100) NULL COMMENT ''最近职业''', 'DO 0'); PREPARE health_step2_stmt FROM @health_step2_sql; EXECUTE health_step2_stmt; DEALLOCATE PREPARE health_step2_stmt; SET @health_step2_sql = IF((SELECT COUNT(*) FROM information_schema.columns WHERE table_schema = DATABASE() AND table_name = 'health_elderly_profile' AND column_name = 'elderly_university') = 0, 'ALTER TABLE health_elderly_profile ADD COLUMN elderly_university bit(1) NULL COMMENT ''是否参加过老年大学''', 'DO 0'); PREPARE health_step2_stmt FROM @health_step2_sql; EXECUTE health_step2_stmt; DEALLOCATE PREPARE health_step2_stmt;