SQL Server creating table with clustered index without a primary key

前端 未结 3 1414
时光说笑
时光说笑 2021-02-04 02:58

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,

3条回答
  •  囚心锁ツ
    2021-02-04 03:21

    Yes, it is possible to create a clustered index that is not the primary key. Just use a CREATE CLUSTERED INDEX statement.

    CREATE TABLE dbo.myTable (
        myTableId int PRIMARY KEY NONCLUSTERED
        myColumn int NOT NULL
    )
    
    CREATE CLUSTERED INDEX myIndex ON dbo.myTable(myColumn)
    

    Prior to version Azure SQL Database v12, you had to have a clustered index before you could insert any data to a table. As of Azure SQL Database v12, heaps (tables without a clustered index) are now supported.

    If your database was created prior to June 2016, here are the instructions for upgrading to version 12.

提交回复
热议问题