I'm trying to change an existing SQL NText column to nvcharmax(max), and encountering an error on the size limit. There's a large amount of existing data, some of which is more than the 8k limit, I believe.
We're looking to convert this, so that the field is searchable in LINQ.
The 2x SQL statements I've tried are:
update Table
set dataNVarChar = convert(nvarchar(max), dataNtext)
where dataNtext is not null
update Table
set dataNVarChar = cast(dataNtext as nvarchar(max))
where dataNtext is not null
And the error I get is:
Cannot create a row of size 8086 which is greater than the allowable maximum row size of 8060.
This is using SQL Server 2008.
Any help appreciated, Thanks.
The marked answer below is correct, and SQL 2008 can change the column to the correct data type in my situation, and there are no dramas with the LINQ-utilising application we use on top of it:
alter table [TBL] alter column [COL] nvarchar(max)
I've also been advised to follow it up with:
update [TBL] set [COL] = [COL]
Which completes the conversion by moving the data from the lob structure to the table (if the length in less than 8k), which improves performance / keeps things proper.
nvarchar [ ( n | max ) ] n defines the string size in byte-pairs, and can be a value from 1 through 4,000. max indicates that the maximum storage size is 2^30-1 characters (2 GB).
ntext will always store its data in a separate database page, while nvarchar(max) will try to store the data within the database record itself. So nvarchar(max) is somewhat faster (if you have text that is smaller as 8 kB). I also noticed that the database size will grow slightly slower, this is also good.
Variable-length Unicode data with a maximum string length of 2^30 - 1 (1,073,741,823) bytes. Storage size, in bytes, is two times the string length that is entered.
Use Virtual View to load the data to Data Vault, and in Virtual View, use the CONVERT() function of SQL Server to extract NVARCHAR(MAX) data as VARCHAR.
That is most likely because the column dataNVarChar is not defined as NVARCHAR(max) To convert a column from NTEXT to NVARCHAR(MAX), use this
alter table TBL alter column COL nvarchar(max)
It will perform the conversion of the data in the column for you at the same time
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With