繁体   English   中英

在 SSMS 2012 中创建数据库图表时出错

[英]Error Creating Database Diagram in SSMS 2012

当我尝试创建数据库图表时,出现以下错误:

Cannot insert the value NULL into column 'diagram_id', table 'MyDB.dbo.sysdiagrams'; column does 
not allow nulls. INSERT fails.
The statement has been terminated.
The 'sp_creatediagram' procedure attempted to return a status of NULL, which is not allowed. A status of
0 will be returned instead. (.Net SqlClient Data Provider)

我正在使用 SSMS 2012。

数据库设置为 SQL Server 2012 (110) 兼容级别

@@Version 是 Microsoft SQL Server 2012 - 11.0.5343.0 (X64)

您的问题是创建表时的 diagram_ID 可能看起来像这样

CREATE TABLE <table_name>
( diagram_ID INT NOT NULL PRIMARY KEY,
  n...,
)

这基本上意味着由于 NOT NULL 条件,无法将 NULL 值插入到该列中。 所以插入语句如下:

INSERT INTO <table_name>
(Diagram_ID, n...,)
VALUES
(NULL, n...,)

会因为 NULL 而失败,你需要在那里有一个值(因为我称之为整数):

INSERT INTO <table_name>
(Diagram_ID, n...,)
VALUES
(23, n...,)

该列也可能是一个缩进列,在这种情况下,您无法控制可以插入到表中的内容。

转到系统表并查找 systemdiagrams 表,然后将字段 diagram_id 的“indentity Specification”属性设置为 YES

希望这会帮助你,这个脚本解决了我的问题

DROP TABLE dbo.sysdiagrams;
GO
CREATE TABLE [dbo].[sysdiagrams]
(
    [name] [sysname] NOT NULL,
    [principal_id] [int] NOT NULL,
    [diagram_id] [int] IDENTITY(1,1) PRIMARY KEY,
    [version] [int] NULL,
    [definition] [varbinary](max) NULL,
    CONSTRAINT [UK_principal_name] UNIQUE ([principal_id],[name])
);

GO
EXEC sys.sp_addextendedproperty 
  @name=N'microsoft_database_tools_support', 
  @value=1 , 
  @level0type=N'SCHEMA',
  @level0name=N'dbo', 
  @level1type=N'TABLE',
  @level1name=N'sysdiagrams';
GO

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM