0

我在数据库中建立了一堆与外键的关系。保存了关系和约束。但是当我将它们添加到图表时,我收到错误:“字符串或二进制数据将被截断”。我最初使用图表工具添加了关系。当我无法保存它时,我尝试重新打开图表并创建一个新图表。在这两种情况下,我都无法保存图表。

4

2 回答 2

3

删除所有图表,然后删除 sysdiagrams 表。下次您尝试添加图表时,它应该会提示您重新创建它。

我认为 SQL 2005 和 SQL 2008 之间存在不兼容,其中 2005 年的字段较小,因此如果您尝试添加 2008 年图表,您会遇到截断问题

于 2012-10-08T18:16:41.533 回答
1

我有同样的问题,上面的解决方案没有帮助。

为了解决这个问题,我使用 SQL Profiler 来捕获失败的语句。我手动运行以下语句(从 Profiler 获得)来获取错误:

--Note: I'm not including the full string of Definition here - it's 10200 characters long.  But, in my case, just a few characters was enough to reproduce the error.


exec dbo.[sp_creatediagram] @diagramname=N'Diagram_1'
                            ,@owner_id=1
                            ,@version=1
                            ,@definition=0xD0CF11E0A1B11AE1

/*Returned:
    Msg 8152, Level 16, State 10, Procedure sysdiagrams_InsertAudit, Line 5
    String or binary data would be truncated.
    The statement has been terminated.
*/

--我打开了以下跟踪选项。

DBCC TRACEON(460, -1);
GO

--Note, after turning on the above TRACE option, the sp_creatediagram statement will tell you where the issue occurred.

exec dbo.[sp_creatediagram] @diagramname=N'Diagram_2'
                            ,@owner_id=1
                            ,@version=1
                            ,@definition=0xD0CF11E0A1B11AE1

/*Returned:
    Msg 8152, Level 16, State 10, Procedure sysdiagrams_InsertAudit, Line 5
    String or binary data would be truncated.
    The statement has been terminated.
*/

就我而言,问题出在 sysdiagrams_InsertAudit 中,它将对图表的更改插入到 sysdiagrams_log 表中。要查看失败的语句,我运行:

exec sp_helptext sysdiagrams_InsertAudit

有问题的语句是“插入到 sysdiagrams_Log”。我将表 sysdiagrams_log 中定义列的类型/长度(该表在与图表相关的数据库中,它不是系统表,就像 sysdiagrams 一样)从 varbinary(1) 更改为 varbinary(max)。(这与 sysdiagrams 表中的类型/长度匹配)。

alter table sysdiagrams_log
    alter column definition varbinary(max)

After this change, the sp_creatediagram statement worked. Note: If you use the SSMS designer to make the change, you may have to Disable the option in SSMS, "Prevent Saving Changes that require table recreate". This is found under, Tools, Options, Designers, Table and Database Designers.

Turn trace back off.

DBCC TRACEOFF(460, -1);
GO
于 2022-02-01T18:12:26.517 回答