更改表的每个双字段
我需要将表的每个双精度字段更改为 numeric(15,3) 类型, 我如何使用迭代给定表的字段的存储过程快速完成这项工作,如果类型是双精度,则将列更改为数字?
I need to change every double precision field of a table to numeric(15,3) type,
how can i do this job quickly with a stored procedure that iterate through the field of a given table and if the type is double precision alter column to numeric ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
以下查询应返回更新这些表的查询...如果需要,您可以添加表过滤器。复制结果并运行。
在运行之前对其进行测试。我还没有测试过。
following query should return query to update these tables... you can add table filter if you want. Copy the result and run it.
TEST IT BEFORE RUN IT. I DID NOT TEST THIS YET.
而另一个问题将为所有列执行此操作;一个简单的“alter table [tablename] alter columns [columnToAlter] type numeric(15,3)。您不需要通过游标运行它们;任何不受此影响的值都应该保持不受影响。
如果可以的话不要通过更改数据类型本身来做到这一点,简单的 update [tablename] set [columnname] = cast(columnname as numeric(15,3) 也应该有效。
希望有帮助!
While another question will do it for all columns; a simple "alter table [tablename] alter column [columnToAlter] type numeric(15,3). You shouldn't need to run them through a cursor; any value that's not going to be affected by this should remain unaffected.
If you can't do it by changing the datatype itself, a simple update [tablename] set [columnname] = cast(columnname as numeric(15,3) should also work.
Hope that helps!