Allow SQL Server to Silently Truncate Data

SQL Server usually presents an error on an attempt to insert more data into a field than it can hold. It typically throws an error message similar to the following:

Msg 8152, Level 16, State 14, Line 15 String or binary data would be truncated. The statement has been terminated.

To prevent this (when needed, of course), you have two options:

Turn ANSI_WARNINGS off    SET ANSI_WARNINGS {ON|OFF}

Pass through a variable

declare @testString varchar(5)    set @testString = 'This is a long string'    print @testString
Share the Post:
Share on facebook
Share on twitter
Share on linkedin

Overview

Recent Articles: