Allow SQL Server to Silently Truncate Data

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:


Pass through a variable

declare @testString varchar(5)    set @testString = 'This is a long string'    print @testString

About Our Editorial Process

At DevX, we’re dedicated to tech entrepreneurship. Our team closely follows industry shifts, new products, AI breakthroughs, technology trends, and funding announcements. Articles undergo thorough editing to ensure accuracy and clarity, reflecting DevX’s style and supporting entrepreneurs in the tech sphere.

See our full editorial policy.

About Our Journalist