55 lines
2.2 KiB
SQL
55 lines
2.2 KiB
SQL
-- 先检查 `email` 列是否存在,再删除
|
|
SELECT COUNT(*) INTO @col_exists FROM information_schema.columns
|
|
WHERE table_schema = DATABASE() AND table_name = 'user' AND column_name = 'email';
|
|
|
|
SET @sql = IF(@col_exists > 0, 'ALTER TABLE `user` DROP COLUMN `email`', 'SELECT 1');
|
|
PREPARE stmt FROM @sql;
|
|
EXECUTE stmt;
|
|
DEALLOCATE PREPARE stmt;
|
|
|
|
-- 先检查 `telephone` 列是否存在,再删除
|
|
SELECT COUNT(*) INTO @col_exists FROM information_schema.columns
|
|
WHERE table_schema = DATABASE() AND table_name = 'user' AND column_name = 'telephone';
|
|
|
|
SET @sql = IF(@col_exists > 0, 'ALTER TABLE `user` DROP COLUMN `telephone`', 'SELECT 1');
|
|
PREPARE stmt FROM @sql;
|
|
EXECUTE stmt;
|
|
DEALLOCATE PREPARE stmt;
|
|
|
|
-- 先检查 `telephone_area_code` 列是否存在,再删除
|
|
SELECT COUNT(*) INTO @col_exists FROM information_schema.columns
|
|
WHERE table_schema = DATABASE() AND table_name = 'user' AND column_name = 'telephone_area_code';
|
|
|
|
SET @sql = IF(@col_exists > 0, 'ALTER TABLE `user` DROP COLUMN `telephone_area_code`', 'SELECT 1');
|
|
PREPARE stmt FROM @sql;
|
|
EXECUTE stmt;
|
|
DEALLOCATE PREPARE stmt;
|
|
|
|
|
|
-- 先检查 `idx_email` 索引是否存在,再删除
|
|
SELECT COUNT(*) INTO @idx_exists FROM information_schema.statistics
|
|
WHERE table_schema = DATABASE() AND table_name = 'user' AND index_name = 'idx_email';
|
|
|
|
SET @sql = IF(@idx_exists > 0, 'ALTER TABLE `user` DROP INDEX `idx_email`', 'SELECT 1');
|
|
PREPARE stmt FROM @sql;
|
|
EXECUTE stmt;
|
|
DEALLOCATE PREPARE stmt;
|
|
|
|
-- 先检查 `idx_telephone` 索引是否存在,再删除
|
|
SELECT COUNT(*) INTO @idx_exists FROM information_schema.statistics
|
|
WHERE table_schema = DATABASE() AND table_name = 'user' AND index_name = 'idx_telephone';
|
|
|
|
SET @sql = IF(@idx_exists > 0, 'ALTER TABLE `user` DROP INDEX `idx_telephone`', 'SELECT 1');
|
|
PREPARE stmt FROM @sql;
|
|
EXECUTE stmt;
|
|
DEALLOCATE PREPARE stmt;
|
|
|
|
-- 先检查 `idx_telephone_area_code` 索引是否存在,再删除
|
|
SELECT COUNT(*) INTO @idx_exists FROM information_schema.statistics
|
|
WHERE table_schema = DATABASE() AND table_name = 'user' AND index_name = 'idx_telephone_area_code';
|
|
|
|
SET @sql = IF(@idx_exists > 0, 'ALTER TABLE `user` DROP INDEX `idx_telephone_area_code`', 'SELECT 1');
|
|
PREPARE stmt FROM @sql;
|
|
EXECUTE stmt;
|
|
DEALLOCATE PREPARE stmt;
|