标识列的数据类型必须为int,bigint,smallint,tinyint,十进制或数字 [英] The identity column must be of data type int, bigint, smallint, tinyint, decimal, or numeric
本文介绍了标识列的数据类型必须为int,bigint,smallint,tinyint,十进制或数字的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我已经在Visual Studio 2012中创建了一个数据库项目,目标平台设置为 Windows Azure SQL数据库。我添加了一个表,例如:
I have created a database project in Visual Studio 2012, with target platform set to 'Windows Azure SQL Database'. I added a table like:
CREATE TABLE [dbo].[Organization]
(
[Id] UNIQUEIDENTIFIER NOT NULL PRIMARY KEY NONCLUSTERED IDENTITY,
[Name] NVARCHAR(100) NOT NULL,
[CreationDate] DATETIME NOT NULL DEFAULT GetDate()
)
GO
CREATE CLUSTERED INDEX [IX_Organization_CreationDate] ON [dbo].[Organization] ([CreationDate])
但它一直在抱怨:
Error 1 SQL71518: The identity column '[dbo].[Organization].[Id]' must be of data type int, bigint, smallint, tinyint, decimal, or numeric with a scale of 0, and the column must not be nullable. C:\Projects\Gastrology\MGP\trunk\Sources\Cfg.Mgp.Infrastructure.Database\Organization.sql 3 2 Cfg.Mgp.Infrastructure.Database
谁知道我为什么不能创建guid类型的主键?
Anyone knows why I can't create a primary key of type guid? What Am I doing wrong?
谢谢!
推荐答案
IDENTITY
不能与 GUID
一起使用 NEWID
。
CREATE TABLE [dbo].[Organization]
(
[Id] UNIQUEIDENTIFIER NOT NULL PRIMARY KEY NONCLUSTERED DEFAULT NEWID(),
[Name] NVARCHAR(100) NOT NULL,
[CreationDate] DATETIME NOT NULL DEFAULT GetDate()
)
这篇关于标识列的数据类型必须为int,bigint,smallint,tinyint,十进制或数字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文