We have made updates to our Privacy Policy to reflect the implementation of the General Data Protection Regulation.
Allow SQL Server to Silently Truncate Data

Submitted by: Hannes du Preez(ojdupreez1978@gmail.com)

Thursday Feb 22nd 2018 by Hannes du Preez

Language: SQL, Expertise: Beginner - See two ways to prevent SQL from throwing this error.

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
Mobile Site | Full Site
Copyright 2018 © QuinStreet Inc. All Rights Reserved