How to create sequence in SQL Server 2008

后端 未结 6 1440
执笔经年
执笔经年 2021-01-02 23:37

I am creating sequence in SQL Server with the following code. But it displays error as unknown object type. Please give a solution

Here\'s my code :

         


        
6条回答
  •  [愿得一人]
    2021-01-03 00:05

    We can't use Sequence easily in SQL Server 2008.

    You can use CTE(Common Table Expressions) for Sequence Generation in SQL Server 2008

    WITH NUM_GEN (n) AS
         ( 
                SELECT 1 
                UNION 
                      ALLSELECT n+1 
                FROM  NUM_GEN 
                WHERE n+1< MAX_VALUE 
         ) 
    SELECT n 
    FROM   NUM_GEN
    

提交回复
热议问题