mysql批量修改表字段的屬性

2021-07-23 18:46:17 字數 349 閱讀 1720

目的:將所有表中的'created_by'欄位和'changed_by'欄位的長度改為varchar(255)

第一步:查出所有表中需要同時修改的字段,並且拼接出修改的sql

select concat('alter table ',table_name,' modify ',column_name,' varchar(255) ;')

from information_schema.columns

where table_schema='db1' and column_name in ('created_by','changed_by')

其他:各種對錶的操作可以根據information_schema來

增加 修改表字段屬性

資料庫 mydb 表名 company 字段 id int 4 not null name varchar 30 not null 如何寫sql,將這2個字段的not null屬性設定為null 允許空 修改字段屬性 alter table 表名 modify 欄位名 型別屬性 not null 預...

修改表字段mysql語句

修改表字段 create table register id int primary key auto increment,name varchar 10 default null unique key,age tinyint unsigned default 18,registime timest...

Mysql批量修改表欄位名稱為小寫

mysql批量修改表欄位名稱為小寫 有時候表字段windows下不區分大小寫,linux區分 為了避免不必要的麻煩我們統一改為小寫。匯出sql 例如 table structure for t user role drop table if exists t user role create tab...