sql server建立序列sequence

2022-06-08 16:21:11 字數 1033 閱讀 3747

1、建立乙個序列物件

1

create sequence [

schema_name .

]sequence_name

2as [ built_in_integer_type | user-defined_integer_type ]3

start with

4increment by 5 |

6|

7cycle | 8 |

;

sequence_name 指定資料庫中標識序列的唯一名稱。 型別為 sysname。

built_in_integer_type | user-defined_integer_type 序列可定義為任何整數型別。如果未提供任何資料型別,則預設 bigint型別。

start with 序列物件返回的第乙個值。 start 值必須小於或等於序列物件的最大值並大於或等於其最小值。

increment by 每次呼叫 next value for 函式時序列物件值遞增(如果為負數,則為遞減)的值。

min和max 分別設定最小和最大值

cycle 設定是否迴圈,預設迴圈選項是 no cycle

cache 通過最大限度地減少生成序列編號所需的磁碟 io 數,可以提高使用序列物件的應用程式的效能。 預設值為 cache。

2、查詢序列物件

select * from sys.sequences

3、重置序列號

alter sequence dbo.sequence_test restart with 1;

--將dbo.sequence_test重置為從1開始

select next value for dbo.sequence_test;

4、刪除序列物件

drop sequence dbo.sequence_test

SQLServer之建立事務序列化

語法 set transaction isolation level serialize 序列化會指定下列內容 語句不能讀取已由其他事務修改但尚未提交的資料。任何其他事務都不能在當前事務完成之前修改由當前事務讀取的資料。在當前事務完成之前,其他事務不能使用當前事務中任何語句讀取的鍵值插入新行。範圍鎖...

SQLServer之建立事務序列化

語法 set transaction isolation level serialize 序列化會指定下列內容 語句不能讀取已由其他事務修改但尚未提交的資料。任何其他事務都不能在當前事務完成之前修改由當前事務讀取的資料。在當前事務完成之前,其他事務不能使用當前事務中任何語句讀取的鍵值插入新行。範圍鎖...

執行緒 建立 J2SE

建立執行緒的兩種方法 第一種,定義執行緒,實現 runnable介面 public class testthread1 class runner1 implements runnable start runner1和main thread交替執行。run runner1先執行,main thread...