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

SET ANSI_WARNINGS (Transact-SQL)

https://docs.microsoft.com/en-us/sql/t-sql/statements/set-ansi-warnings-transact-sql

The SQL Server Native Client ODBC driver and SQL Server Native Client OLE DB Provider for SQL Server automatically set ANSI_WARNINGS to ON when connecting. This can be configured in ODBC data sources, in ODBC connection attributes, set in the application before connecting. The default for SET ANSI_WARNINGS is OFF for connections from DB-Library applications.

 

 

ODBC

https://support.office.com/en-us/article/Administer-ODBC-data-sources-b19f856b-5b9b-48c9-8b93-07484bfab5a7

Add an ODBC data source

Before proceeding, obtain and install the appropriate ODBC driver for the data source to which you want to connect.

NOTE:  You must be a member of the Administrators group on your local machine in order to add or configure an ODBC data source.

  1. Click Start, and then click Control Panel.

  2. In the Control Panel, double-click Administrative Tools.

  3. In the Administrative Tools dialog box, double-click Data Sources (ODBC).

    The ODBC Data Source Administrator dialog box appears.

  4. Click User DSN, System DSN, or File DSN, depending on the type of data source you want to add. For more information, see the section About ODBC data sources.

  5. Click Add.

  6. Select the driver that you want to use, and then click Finish or Next.

    If the driver you want is not listed, contact the administrator of the database you are connecting to for information about how to obtain the correct driver.

  7. Follow the instructions and enter the required connection information in any dialog boxes that follow.

Click Help in the ODBC dialog boxes for more information about the individual settings.

 

 

复制代码
DECLARE @MyTable TABLE
    (
        RowNumber INT NOT NULL ,
        DatabaseName NVARCHAR(50) NOT NULL ,
        DBOwner NVARCHAR(10) NOT NULL
    );
INSERT INTO @MyTable ( RowNumber ,
                       DatabaseName ,
                       DBOwner )
            SELECT ROW_NUMBER() OVER ( ORDER BY name )  ,
                   name  ,
                   SUSER_SNAME(owner_sid) 
            FROM   sys.databases
            WHERE  SUSER_SNAME(owner_sid) <> 'sa'
复制代码

原因:因为有一部分DBOwner的字符串长度超过10了,所以,可以考虑使用nvarchar(max)

 

 

 

 

作者:Chuck Lu    GitHub    
posted @   ChuckLu  阅读(1291)  评论(0编辑  收藏  举报
编辑推荐:
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
· 没有源码,如何修改代码逻辑?
阅读排行:
· 全程不用写代码,我用AI程序员写了一个飞机大战
· DeepSeek 开源周回顾「GitHub 热点速览」
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 记一次.NET内存居高不下排查解决与启示
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了
历史上的今天:
2016-09-06 PowerShell 4 on win7 sp1
2016-09-06 about_Execution_Policies
2016-09-06 PowerShell常用命令
2016-09-06 Installing Chocolatey
2016-09-06 将NuGet配置到环境变量中
2015-09-06 XtraForm中OfficeSkins以及BonusSkin皮肤的设置
2015-09-06 XtraForm中更换皮肤
点击右上角即可分享
微信分享提示