Is there a .NET equivalent to SQL Server's newsequentialid()

前端 未结 10 2176
孤城傲影
孤城傲影 2020-12-02 10:47

We use GUIDs for primary key, which you know is clustered by default.

When inserting a new row into a table it is inserted at a random page in the table (because GUID

10条回答
  •  北海茫月
    2020-12-02 11:20

    About the selected answer. The docs says... The generated Guid will not give you uniqueId between computers if they don't have ehternet access.

    If you must know the guid when inserting, couldn't you let Sql-server return a block of sequential guids that you assign to your data before you insert them?

    declare @ids table(id uniqueidentifier default NEWSEQUENTIALID(), dummy char(1))
    
    declare @c int
    set @c = 0;
    while (@c < 100)
    begin
        insert into @ids (dummy) values ('a');
        set @c += 1;
    end
    
    select id from @ids
    

提交回复
热议问题