[英]Alter All TinyInt(1) Columns In Database to Not Null Default 0
I have a database, and I need to alter every single 我有一个数据库,我需要更改每个数据库
tinyint(1) default null
column (and incidentally, every value in those columns set to null) in every single table in that database to: 该数据库中每个表中的列(顺便说一下,这些列中的每个值都设置为null)为:
tinyint(1) not null default 0
as soon as possible. 尽快地。
What is the fastest / most efficient way to achieve this, (programmatically or otherwise)? (以编程方式或其他方式)最快/最有效的方法是什么?
Query information_schema.COLUMNS
view for a list of tables/columns, then use your programming language of choice to loop through the results and perform ALTER TABLE
queries. 在information_schema.COLUMNS
视图中查询表/列的列表,然后使用您选择的编程语言遍历结果并执行ALTER TABLE
查询。
SELECT TABLE_NAME, COLUMN_NAME
FROM information_schema.COLUMNS
WHERE TABLE_SCHEMA = 'yourDatabase'
AND COLUMN_TYPE = 'tinyint(1)'
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.