简体   繁体   中英

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:

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.

SELECT TABLE_NAME, COLUMN_NAME 
FROM information_schema.COLUMNS
WHERE TABLE_SCHEMA = 'yourDatabase'
AND COLUMN_TYPE = 'tinyint(1)'

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM