String or binary data would be truncated. The statement has been terminated

后端 未结 5 1871
臣服心动
臣服心动 2020-12-29 01:51

I have met some problem with the SQL server, this is the function I created:

ALTER FUNCTION [dbo].[testing1](@price int)
RETURNS @trackingItems1 TABLE (
   i         


        
5条回答
  •  我在风中等你
    2020-12-29 02:39

    SQL Server 2016 SP2 CU6 and SQL Server 2017 CU12 introduced trace flag 460 in order to return the details of truncation warnings. You can enable it at the query level or at the server level.

    Query level

    INSERT INTO dbo.TEST (ColumnTest)
    VALUES (‘Test truncation warnings’)
    OPTION (QUERYTRACEON 460);
    GO
    

    Server Level

    DBCC TRACEON(460, -1);
    GO
    

    From SQL Server 2019 you can enable it at database level:

    ALTER DATABASE SCOPED CONFIGURATION 
    SET VERBOSE_TRUNCATION_WARNINGS = ON;
    

    The old output message is:

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

    The new output message is:

    Msg 2628, Level 16, State 1, Line 30
    String or binary data would be truncated in table 'DbTest.dbo.TEST', column 'ColumnTest'. Truncated value: ‘Test truncation warnings‘'.
    

    In a future SQL Server 2019 release, message 2628 will replace message 8152 by default.

提交回复
热议问题