Dynamically name indexes in SQL Server 2005?

后端 未结 2 876
攒了一身酷
攒了一身酷 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)
    
    0 讨论(0)
  • 2021-01-12 02:47

    Should be able to do:

    CREATE INDEX #foo1 ON #foo(bar);
    
    0 讨论(0)
提交回复
热议问题