Dynamically name indexes in SQL Server 2005?

后端 未结 2 906
攒了一身酷
攒了一身酷 2021-01-12 02:14

As most people who work with Sql Server know, you can declare a temporary table like so:

create table #foo 
    (
    row_id int identity not null primary ke         


        
2条回答
  •  情歌与酒
    2021-01-12 02:46

    This is a non issue. Index names only have to be unique within a table scope, not globally across table scopes. Only constraint names have to be unique within an entire database schema.

    So, for example, you can run this in multiple concurrent connections with no problems

    CREATE TABLE #T
    (
    C INT
    )
    
    CREATE UNIQUE CLUSTERED INDEX ix on #T(C)
    

    But this would fail under concurrency

    ALTER TABLE #T
    ADD CONSTRAINT UQ UNIQUE NONCLUSTERED (C)
    

提交回复
热议问题