Back

Explore Courses Blog Tutorials Interview Questions
0 votes
6 views
in Azure by (45.3k points)

Is it possible to create a clustered index from a create table statement in SQL Server 2008 that is not a primary key?

The purpose of this is for a table in SQL Azure, so it is not an option for me to first create the table, and then create the clustered index on the table.

Edit: Apparently it was FluentMigrator that was causing my problems, it's version table does not have a clustered index so it was erroring trying to create the versioning table, not my table.

1 Answer

0 votes
by (16.8k points)

CREATE TABLE dbo.Table_1

    (

    Id int NOT NULL IDENTITY (1, 1) PRIMARY KEY NONCLUSTERED,

    SomeOtherUniqueColumn int NOT NULL CONSTRAINT Item4 UNIQUE CLUSTERED

)  ON [PRIMARY]

note the specification of nonclustered on the primary key

This will still work.

CREATE TABLE dbo.Table_1

    (

    SomeOtherUniqueColumn int NOT NULL CONSTRAINT Item4 UNIQUE CLUSTERED

)  ON [PRIMARY]

Browse Categories

...