Skip to content

Instantly share code, notes, and snippets.

@z1076
Last active August 9, 2022 12:00
Show Gist options
  • Save z1076/20cec3dc0e37c48342e77764ea13d0e0 to your computer and use it in GitHub Desktop.
Save z1076/20cec3dc0e37c48342e77764ea13d0e0 to your computer and use it in GitHub Desktop.
[RtpSystem Mysql] #Mysql
#批量修改表字段
SELECT CONCAT('alter table ',TABLE_NAME,' modify ',COLUMN_NAME,' varchar(500) ;') AS '修改语句'
FROM INFORMATION_SCHEMA.COLUMNS
WHERE TABLE_SCHEMA='scrm_wechat_1' AND COLUMN_NAME IN ('resource_url')
# 批量修改 rtpsystem_go中所有deleted_at字段默认值为null
SELECT
CONCAT( 'alter table ', TABLE_NAME, ' modify ', COLUMN_NAME, ' timestamp NULL DEFAULT NULL ;' ) AS '修改语句'
FROM
INFORMATION_SCHEMA.COLUMNS
WHERE
TABLE_SCHEMA = 'rtpsystem_go'
AND COLUMN_NAME IN ( 'deleted_at')
update customers set balance = 0,expense_count = 0;
update providers set balance = 0,expense_count = 0;
TRUNCATE TABLE provider_balance_changes;
TRUNCATE TABLE customer_balance_changes;
TRUNCATE TABLE channel_orders;
TRUNCATE TABLE channel_order_submit_records;
TRUNCATE TABLE sys_operation_records;
# 删除数据库字段注释
# table_schema为表名
SELECT
concat(
'alter table ',
table_schema, '.', table_name,
' modify column ', column_name, ' ', column_type, ' ',
if(is_nullable = 'YES', ' ', 'not null '),
if(column_default IS NULL, '',
if(
data_type IN ('char', 'varchar')
OR
data_type IN ('date', 'datetime', 'timestamp') AND column_default != 'CURRENT_TIMESTAMP',
concat(' default ''', column_default,''''),
concat(' default ', column_default)
)
),
if(extra is null or extra='','',concat(' ',extra)),
' comment ''', ''';'
) s
FROM information_schema.columns
WHERE table_schema = 'recharge'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment