Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

The identity column must be of data type int, bigint, smallint, tinyint, decimal, or numeric

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])

But it keeps complaining about:

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

Anyone knows why I can't create a primary key of type guid? What Am I doing wrong?

Thanks!

like image 753
L-Four Avatar asked Jan 12 '23 16:01

L-Four


1 Answers

IDENTITY cannot be used with GUID

Use NEWID instead.

CREATE TABLE [dbo].[Organization]
(
    [Id] UNIQUEIDENTIFIER NOT NULL PRIMARY KEY NONCLUSTERED DEFAULT NEWID(), 
    [Name] NVARCHAR(100) NOT NULL, 
    [CreationDate] DATETIME NOT NULL DEFAULT GetDate()
)
like image 127
Dustin Kingen Avatar answered Jan 21 '23 03:01

Dustin Kingen