如何在 SQL Server 中一次 ALTER 多个列 [英] How to ALTER multiple columns at once in SQL Server
本文介绍了如何在 SQL Server 中一次 ALTER 多个列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要ALTER
一个表中几列的数据类型.
I need to ALTER
the data types of several columns in a table.
对于单列,以下工作正常:
For a single column, the following works fine:
ALTER TABLE tblcommodityOHLC
ALTER COLUMN
CC_CommodityContractID NUMERIC(18,0)
但是如何在一个语句中更改多个列?以下不起作用:
But how do I alter multiple columns in one statement? The following does not work:
ALTER TABLE tblcommodityOHLC
ALTER COLUMN
CC_CommodityContractID NUMERIC(18,0),
CM_CommodityID NUMERIC(18,0)
推荐答案
这不可能.您将需要一一执行此操作.你可以:
This is not possible. You will need to do this one by one. You could:
- 使用修改后的列创建临时表
- 复制数据
- 放下原来的桌子(之前要仔细检查!)
- 将临时表重命名为原始名称
这篇关于如何在 SQL Server 中一次 ALTER 多个列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文