将现有 SQL Server 2005 数据库中的数据类型 varchar 更改为 nvarchar.有什么问题吗? [英] Change datatype varchar to nvarchar in existing SQL Server 2005 database. Any issues?

查看:65
本文介绍了将现有 SQL Server 2005 数据库中的数据类型 varchar 更改为 nvarchar.有什么问题吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要将数据库表中的列数据类型从 varchar 更改为 nvarchar 以支持中文字符(目前,varchar 字段具有这些字符的仅显示问号).

I need to change column datatypes in a database table from varchar to nvarchar in order to support Chinese characters (currently, the varchar fields that have these characters are only showing question marks).

我知道如何更改这些值,但我想看看这样做是否安全.换衣服之前有什么需要注意的吗?谢谢!

I know how to change the values, but I want to see if it's safe to do so. Is there anything to look out for before I do the changing? Thanks!

推荐答案

请注意,此更改是数据大小更新,请参阅 后台的 SQL Server 表列.更改将添加一个新的 NVARCHAR 列,它将更新每一行,将 dta 从旧的 VARCHAR 复制到新的 NVARCHAR 列,然后将旧的 VARCHAR 列标记为已删除.如果表很大,这会产生一个很大的日志,所以要做好准备.更新后,运行 DBCC CLEANTABLE 来回收由以前的 VARCHAR 列.如果你负担得起,最好运行 ALTER TABLE ... REBUILD,这不仅会回收空间,还会完全删除物理删除的 VARCHAR 列.开头的链接文章有更多详细信息.

Note that this change is a size-of-data update, see SQL Server table columns under the hood. The change will add a new NVARCHAR column, it will update each row copying the dta from the old VARCHAR to the new NVARCHAR column, and then it will mark the old VARCHAR column as dropped. IF the table is large, this will generate a large log, so be prepared for it. After the update, run DBCC CLEANTABLE to reclaim the space used by the former VARCHAR column. If you can afford it , better run ALTER TABLE ... REBUILD, which will not only reclaim the space it will also completely remove physical deleted VARCHAR column. The linked article at the beginning has more details.

您可能也有兴趣为您的表启用 Unicode 压缩.

You may also be interested in enabling Unicode Compression for your table.

这篇关于将现有 SQL Server 2005 数据库中的数据类型 varchar 更改为 nvarchar.有什么问题吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆