SQL将列数据类型从nvarchar更改为int [英] SQL alter column datatype from nvarchar to int
本文介绍了SQL将列数据类型从nvarchar更改为int的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
可以将字段的数据类型从nvarchar更改为int吗?
Can the datatype of a field be changed to int from nvarchar??
alter table employee alter column designation int
这有效吗?
PS:我正在使用 MS SQL Server
推荐答案
您可以尝试做一个alter table。如果失败,请执行以下操作:
You can try doing an alter table. If it fails do this:
- 创建一个新的整数列:
ALTER TABLE tableName添加newCol int;
- 从旧列中选择数据进入新列:
UPDATE tableName SET newCol = CAST(oldCol AS int)
;
- 删除旧列
这篇关于SQL将列数据类型从nvarchar更改为int的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文