1. <i id='pwyHn'><tr id='pwyHn'><dt id='pwyHn'><q id='pwyHn'><span id='pwyHn'><b id='pwyHn'><form id='pwyHn'><ins id='pwyHn'></ins><ul id='pwyHn'></ul><sub id='pwyHn'></sub></form><legend id='pwyHn'></legend><bdo id='pwyHn'><pre id='pwyHn'><center id='pwyHn'></center></pre></bdo></b><th id='pwyHn'></th></span></q></dt></tr></i><div id='pwyHn'><tfoot id='pwyHn'></tfoot><dl id='pwyHn'><fieldset id='pwyHn'></fieldset></dl></div>
      <bdo id='pwyHn'></bdo><ul id='pwyHn'></ul>

    <small id='pwyHn'></small><noframes id='pwyHn'>

    <legend id='pwyHn'><style id='pwyHn'><dir id='pwyHn'><q id='pwyHn'></q></dir></style></legend>
    <tfoot id='pwyHn'></tfoot>
    1. 您将如何在 Microsoft SQL Server 中实现序列?

      时间:2023-09-20
        • <legend id='vjedj'><style id='vjedj'><dir id='vjedj'><q id='vjedj'></q></dir></style></legend>

          <tfoot id='vjedj'></tfoot>

          1. <small id='vjedj'></small><noframes id='vjedj'>

                <tbody id='vjedj'></tbody>
                <bdo id='vjedj'></bdo><ul id='vjedj'></ul>

                <i id='vjedj'><tr id='vjedj'><dt id='vjedj'><q id='vjedj'><span id='vjedj'><b id='vjedj'><form id='vjedj'><ins id='vjedj'></ins><ul id='vjedj'></ul><sub id='vjedj'></sub></form><legend id='vjedj'></legend><bdo id='vjedj'><pre id='vjedj'><center id='vjedj'></center></pre></bdo></b><th id='vjedj'></th></span></q></dt></tr></i><div id='vjedj'><tfoot id='vjedj'></tfoot><dl id='vjedj'><fieldset id='vjedj'></fieldset></dl></div>
                本文介绍了您将如何在 Microsoft SQL Server 中实现序列?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                有没有人有在 SQL Server 中实现类似序列的好方法?

                Does anyone have a good way of implementing something like a sequence in SQL server?

                有时你只是不想使用 GUID,除了它们很丑的事实.也许您想要的序列不是数字?此外,插入一行然后询问数据库数字是什么似乎太hackish了.

                Sometimes you just don't want to use a GUID, besides the fact that they are ugly as heck. Maybe the sequence you want isn't numeric? Besides, inserting a row and then asking the DB what the number is just seems so hackish.

                推荐答案

                Sql Server 2012 引入了 SEQUENCE 对象,它允许您生成与任何表无关的连续数值.

                Sql Server 2012 has introduced SEQUENCE objects, which allow you to generate sequential numeric values not associated with any table.

                创建它们很容易:

                CREATE SEQUENCE Schema.SequenceName
                AS int
                INCREMENT BY 1 ;
                

                插入前使用它们的示例:

                An example of using them before insertion:

                DECLARE @NextID int ;
                SET @NextID = NEXT VALUE FOR Schema.SequenceName;
                -- Some work happens
                INSERT Schema.Orders (OrderID, Name, Qty)
                  VALUES (@NextID, 'Rim', 2) ;
                

                请参阅我的博客以深入了解如何使用序列:

                See my blog for an in-depth look at how to use sequences:

                http://sqljunkieshare.com/2011/12/11/sequences-in-sql-server-2012-implementingmanaging-performance/

                这篇关于您将如何在 Microsoft SQL Server 中实现序列?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                上一篇:如何恢复损坏的 SQLite3 数据库? 下一篇:SQL 服务器查询以获取表中的列列表以及数据类型、NOT NULL 和 PRIMARY KEY 约束

                相关文章

                  <i id='PWZqd'><tr id='PWZqd'><dt id='PWZqd'><q id='PWZqd'><span id='PWZqd'><b id='PWZqd'><form id='PWZqd'><ins id='PWZqd'></ins><ul id='PWZqd'></ul><sub id='PWZqd'></sub></form><legend id='PWZqd'></legend><bdo id='PWZqd'><pre id='PWZqd'><center id='PWZqd'></center></pre></bdo></b><th id='PWZqd'></th></span></q></dt></tr></i><div id='PWZqd'><tfoot id='PWZqd'></tfoot><dl id='PWZqd'><fieldset id='PWZqd'></fieldset></dl></div>

                1. <tfoot id='PWZqd'></tfoot>

                  <small id='PWZqd'></small><noframes id='PWZqd'>

                  1. <legend id='PWZqd'><style id='PWZqd'><dir id='PWZqd'><q id='PWZqd'></q></dir></style></legend>
                      <bdo id='PWZqd'></bdo><ul id='PWZqd'></ul>