正如其他人已經提到,你可以很容易地在nvarchar(max)中存儲20000個字符。轉換這些類型時可能會出錯。
下面是一個從nvarchar(max)轉換爲nvarchar(max)的例子,它清楚地顯示瞭如何在那裏存儲20000個字符。
DECLARE @v1 nvarchar(max)
DECLARE @v2 nvarchar(max)
create table #textExample
(
id int,
t1 ntext
)
declare @count int
set @v1 = ''
SET @count = 0
while @count < 20000
begin
set @v1 = @v1 + '1'
set @count = @count + 1
end
--converting nvarchar(max) to ntext
insert into #textExample
values (1, CONVERT(ntext,@v1))
select * from #textExample
-- converting ntext back to nvarchar(max)
SET @v2 = CONVERT(nvarchar(max), (select t1 from #textExample where id = 1))
select @v2, LEN(@v2)
drop table #textExample
什麼版本的SQL Server?你爲什麼使用'ntext'而不是'nvarchar(max)'? –
'nvarchar(max)'可以存儲**高達2 GB **的數據 - 絕對**多於**多於8000個字符... –
可以讓我知道可以存儲的字符的確切數量爲nvarchar(最大)? –