更改数据库中的所有表 [英] Alter all tables in database
本文介绍了更改数据库中的所有表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想在我的SQL数据库中的 ALL 表上运行更改表":
I would like to run a "Alter Table" on ALL the tables in my SQL databse:
ALTER TABLE test ADD CONSTRAINT [COLLUM_NAME] DEFAULT ((0)) FOR [COLLUM_NAME]
我知道如何从数据库中获取所有现有表:
I know how to get all of the existing tables from the database:
SELECT TABLE_NAME
FROM INFORMATION_SCHEMA.TABLES
WHERE TABLE_TYPE = 'BASE TABLE'
或
USE DATABASE_NAME
GO
SELECT name
FROM sys.Tables
GO
但是我不知道如何将两者结合起来.
But I don’t know how to combine these two.
在我的数据库(50多个表)中,所有表共有1行. 并且我想为所有这些行设置一个默认值.
In my database (50+ tables) all of the tables have 1 row in common. and I would like to set a default value to all of these rows.
推荐答案
您可以尝试生成命令并在之后执行它. 您可以执行以下操作:
You can try to generate a command and execute it after. You can do something like this:
SELECT CONCAT("Alter Table `", TABLE_SCHEMA,"`.`", TABLE_NAME, "` this is my default value change on the column") as MySQLCMD
FROM TABLES
并执行检索.
这篇关于更改数据库中的所有表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文