将数据库中的所有 TinyInt(1) 列更改为非空默认值 0 [英] Alter All TinyInt(1) Columns In Database to Not Null Default 0
本文介绍了将数据库中的所有 TinyInt(1) 列更改为非空默认值 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:
tinyint(1) not null default 0
尽快.
实现这一目标的最快/最有效方法是什么(以编程方式或其他方式)?
What is the fastest / most efficient way to achieve this, (programmatically or otherwise)?
推荐答案
查询 information_schema.COLUMNS
视图以获取表/列列表,然后使用您选择的编程语言循环查看结果并执行 ALTER TABLE
查询.
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.
SELECT TABLE_NAME, COLUMN_NAME
FROM information_schema.COLUMNS
WHERE TABLE_SCHEMA = 'yourDatabase'
AND COLUMN_TYPE = 'tinyint(1)'
这篇关于将数据库中的所有 TinyInt(1) 列更改为非空默认值 0的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文