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!
Try something like this :-
Check out this link
From the source:-
**
The IDENTITY keyword is used to auto-increment a integer column that is usually used as a primary key. Because you are using a unique identifier, including this keyword makes no sense. (how do you increment a unique identifier?)
Just remove the "IDENTITY" keyword.
http://technet.microsoft.com/en-us/library/ms186775.aspx
IDENTITY
cannot be used withGUID
Use
NEWID
instead.