適用於: 是SQL Server 是Azure SQL Database 否Azure Synapse Analytics (SQL DW) 否平行處理資料倉儲 APPLIES TO: yesSQL Server yesAzure SQL Database noAzure Synapse Analytics (SQL DW) noParallel Data Warehouse

建立一個 GUID,該 GUID 會大於這個函數先前在指定的電腦啟動 Windows 後所產生的任何 GUID。Creates a GUID that is greater than any GUID previously generated by this function on a specified computer since Windows was started. 重新啟動 Windows 後,GUID 可以從較低的範圍再次啟動,但仍是全域唯一的。After restarting Windows, the GUID can start again from a lower range, but is still globally unique. 將 GUID 資料行當做資料列識別碼使用時,使用 NEWSEQUENTIALID 可能比使用 NEWID 函數更快。When a GUID column is used as a row identifier, using NEWSEQUENTIALID can be faster than using the NEWID function. 這是因為 NEWID 函數會造成隨機活動,因此會使用較少的快取資料頁面。This is because the NEWID function causes random activity and uses fewer cached data pages. 使用 NEWSEQUENTIALID 也有助於完全填滿資料與索引頁面。Using NEWSEQUENTIALID also helps to completely fill the data and index pages.


如果您有隱私權顧慮,請勿使用這個函數。If privacy is a concern, do not use this function. 因為使用者不難猜出下一個產生的 GUID 值,進而存取與該 GUID 相關聯的資料。It is possible to guess the value of the next generated GUID and, therefore, access data associated with that GUID.

NEWSEQUENTIALID 是 Windows UuidCreateSequential 函式上的一個包裝函式,其套用了一些隨機位元組NEWSEQUENTIALID is a wrapper over the Windows UuidCreateSequential function, with some byte shuffling applied.


UuidCreateSequential 函式有硬體相依性。The UuidCreateSequential function has hardware dependencies. SQL ServerSQL Server 上,當資料庫 (例如自主資料庫) 移動到另一部電腦時,順序值的叢集便可進行開發。On SQL ServerSQL Server, clusters of sequential values can develop when databases (such as contained databases) are moved to other computers. 使用 Always On 和在 SQL DatabaseSQL Database 上時,若資料庫容錯移轉至不同的電腦,順序值的叢集便可進行開發。When using Always On and on SQL DatabaseSQL Database, clusters of sequential values can develop if the database fails over to a different computer.

主題連結圖示 Transact-SQL 語法慣例Topic link icon Transact-SQL Syntax Conventions



傳回類型Return Type



NEWSEQUENTIALID() 只能搭配使用 uniqueidentifier 類型之資料表資料行的 DEFAULT 條件約束。NEWSEQUENTIALID() can only be used with DEFAULT constraints on table columns of type uniqueidentifier. 例如:For example:

CREATE TABLE myTable (ColumnA uniqueidentifier DEFAULT NEWSEQUENTIALID());   

當 NEWSEQUENTIALID() 用於 DEFAULT 運算式時,不能與其他純量運算子結合。When NEWSEQUENTIALID() is used in DEFAULT expressions, it cannot be combined with other scalar operators. 例如,您不可以執行下列作業:For example, you cannot execute the following:

CREATE TABLE myTable (ColumnA uniqueidentifier DEFAULT dbo.myfunction(NEWSEQUENTIALID()));  

在上一個範例中,myfunction() 是一個純量使用者自訂的純量函數,可以接受和傳回 uniqueidentifier 值。In the previous example, myfunction() is a scalar user-defined scalar function that accepts and returns a uniqueidentifier value.

NEWSEQUENTIALID 無法於查詢中參考。NEWSEQUENTIALID cannot be referenced in queries.

您可以使用 NEWSEQUENTIALID 來產生 GUID,以減少在索引分葉層級的網頁競爭。You can use NEWSEQUENTIALID to generate GUIDs to reduce page splits and random IO at the leaf level of indexes.

使用 NEWSEQUENTIALID 所產生的 GUID 在該電腦上都是唯一的。Each GUID generated by using NEWSEQUENTIALID is unique on that computer. 唯有在來源電腦具有網路卡時,使用 NEWSEQUENTIALID 所產生的 GUID 在多部電腦上才是唯一的。GUIDs generated by using NEWSEQUENTIALID are unique across multiple computers only if the source computer has a network card.

另請參閱See Also

NEWID (Transact-SQL) NEWID (Transact-SQL)
比較運算子 (Transact-SQL)Comparison Operators (Transact-SQL)