Sunday 23 February 2020

String or binary data would be truncated (VERBOSE_TRUNCATION_WARNINGS ON)


This error is usually encountered when inserting a record in a table where one of the columns is a VARCHAR or CHAR data type and the length of the value being inserted is longer than the length of the column. Before SQL 2019, it is really frustrated with this error message because you cannot find which column is the offending column. The error message is informative now in SQL Server 2019, which tells you which column is causing the issue.

We have a table before 2019 version of sql server

create table table_test
(Id int identity (1,1),
 Name varchar(10),
 Address varchar(10),
 Mobile varchar(10))
Now insert some records
Insert into table_test
(Name,Address,Mobile) values
('Bagesh Kumar Singh','Noida','888880XXXX')

Getting bellow error 

It is very default to find out in which column it throws this error.
In sql server 2019, this error message has been improved. Here we will get the column name with truncate value.

Let’s see this example in sql server 2019

Insert this record
    

Oooooo  again we are getting same error!
Don’t warry
We need to set the VERBOSE_TRUNCATION_WARNINGS ON.
Now I am altering this database and setting VERBOSE_TRUNCATION_WARNINGS on.
ALTER DATABASE SCOPED CONFIGURATION
  SET VERBOSE_TRUNCATION_WARNINGS = on;
   
Now I am inserting this record.
    


With the help of this error message, we can easily find out the truncated column and value. Now I am correcting it and inserting now.
  
Record inserted successfully.

1 comment:

  1. Do you understand there is a 12 word phrase you can communicate to your man... that will induce intense feelings of love and impulsive attractiveness to you buried within his chest?

    That's because deep inside these 12 words is a "secret signal" that fuels a man's impulse to love, cherish and guard you with all his heart...

    12 Words Will Trigger A Man's Desire Impulse

    This impulse is so hardwired into a man's mind that it will make him try harder than before to make your relationship the best part of both of your lives.

    In fact, fueling this all-powerful impulse is absolutely important to getting the best ever relationship with your man that as soon as you send your man one of the "Secret Signals"...

    ...You'll instantly find him open his mind and heart for you in such a way he's never expressed before and he'll distinguish you as the one and only woman in the galaxy who has ever truly appealed to him.

    ReplyDelete

If you have any doubt, please let me know.

Popular Posts