简体   繁体   English

将nvarchar(4000)转换为nvarchar(max)

[英]Converting nvarchar(4000) to nvarchar(max)

We have a few tables in our SQL Server (2005 & 2008) database with columns defined as nvarchar(4000). 我们的SQL Server(2005和2008)数据库中有几个表,其列定义为nvarchar(4000)。 We sometimes need to be able to store more data than that and consider to use nvarchar(max) instead. 我们有时需要能够存储更多的数据,并考虑使用nvarchar(max)。 Now to the questions. 现在回答问题。

  1. Are there any performance implications we should know of? 我们应该知道有任何性能影响吗?
  2. Is it safe to use "alter table" to do the actual migration or is there another way? 使用“alter table”进行实际迁移是否安全?还是有另一种方法吗?
  3. Anything else we should know before we convert? 在转换之前我们应该知道的其他事情吗?

Regards Johan 关心约翰

We've had to do this as well in a few spots 我们不得不在几个地方做到这一点

  1. We didn't see any performance hits, its been 5 weeks since the change 我们没有看到任何表现点击,自改变以来已经过了5周
  2. 'Alter table' is fine as long as the table is not getting written to during the conversion 只要在转换过程中没有写入表,“更改表”就可以了
  3. Be sure to have a backup just in case and depending on the amount data in the table it could take a while 请确保备份以防万一,根据表中的数据量,可能需要一段时间

If the text does not fit on the page with the rest of the data, the text will be stored in another page. 如果文本不适合包含其余数据的页面,则文本将存储在另一页中。 This causes an extra database page read. 这会导致额外的数据库页面读取。 So performance can/will be slower. 因此性能可以/将会更慢。 On systems with a heavy load, and a very restricted response time, maybe. 在负载较重的系统上,响应时间非常有限。

The SQL Server Management studio will probably rename the current table, create a new one with the new layout, copy data, remove old table. SQL Server Management工作室可能会重命名当前表,使用新布局创建一个新表,复制数据,删除旧表。 This can be slow. 这可能很慢。

I don't know if the alter table will work. 我不知道alter table是否有效。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM