Home All Groups Group Topic Archive Search About
Author
14 Jul 2005 11:21 PM
Mark
Hello,

Will SQL Server alert you to the fact that you are trying to put more
characters into a nvarchar column than is allowed or will it truncate the
data?

Thanks in advance.
Any help would be greatly appreciated!

Author
14 Jul 2005 11:33 PM
Steve Kass
Mark,

Books Online says:

<quote>
Converting Character Data
When character expressions are converted to a character data type of a
different size, values too long for the new data type are truncated.
</quote>

But if the ANSI_WARNINGS setting is ON, an error will be raised
and the data will not be inserted.  Below is a short repro.  Your mileage
may vary if you are inserting data in ways other than INSERT  statements
in a batch where you can set ANSI_WARNINGS.  Some connections
or applications may set this to OFF, and validating the data before
inserting
may be in order.

use tempdb
go

SET ANSI_WARNINGS OFF
go

create table T (
  i int primary key,
  s nvarchar(10)
)
go


SET ANSI_WARNINGS OFF
go

insert into T values (1, N'ABCDEFGHIJKLMNOP')
go

SET ANSI_WARNINGS ON
go

insert into T values (2, N'ABCDEFGHIJKLMNOP')
go

select * from T
go

drop table T

-- Steve Kass
-- Drew University

Mark wrote:

Show quote
>Hello,
>
>Will SQL Server alert you to the fact that you are trying to put more
>characters into a nvarchar column than is allowed or will it truncate the
>data?
>
>Thanks in advance.
>Any help would be greatly appreciated!

>

AddThis Social Bookmark Button