Tip of the Day : Similarities and Differences Between NEWID and NEWSEQUENTIALID System Functions

Welcome to SQL Server Helper !!!

This site is intended for those who are beginning to use SQL Server as part of their day-to-day activities.  You will find in this site a collection of useful functions, triggers, stored procedures and tips and tricks related to SQL Server.

Should you have any comments or questions regarding this site or if you want to ask SQL Server-related questions, e-mail us here.

We hope we are able to help and we are glad to help!!!

SQL Server Tip of the Day - June 25, 2016

Similarities and Differences Between NEWID and NEWSEQUENTIALID System Functions

System functions are functions that perform operations on and return information about values, objects, and settings in SQL Server.  Two of these system functions are the NEWID and the NEWSEQUENTIALID functions.  The NEWID() system function creates a unique value of type UNIQUEIDENTIFIER. On the other hand, the NEWSEQUENTIALID() system function creates a GUID that is greater than any GUID previously generated by this function on a specified computer since Windows was started.

The following article shows the similarities and differences between the NEWID function and the NEWSEQUENTIALID function.

Similarities

  • Both system functions do not accept parameters and both return a value of UNIQUEIDENTIFIER type.
  • Both system functions are nondeterministic, meaning they may return different results each time they are called.
  • Both system functions can be used with the DEFAULT constraint on table columns of type UNIQUEIDENTIFIER.
  • The GUID generated by both system functions is unique on that computer.

Differences

NEWID

NEWSEQUENTIALID

The use of the NEWID system function is not limited to the DEFAULT constraint. It can be assigned to local variables or inserted as a column value.

Can only be used with the DEFAULT constraints on table columns of type UNIQUEIDENTIFIER

Can be referenced in queries.

Cannot be referenced in queries.

GUID generated is totally random and sequence cannot be determined.

GUID created is always greater than any GUID previously generated by this function on a specified computer since Windows was started.

When used in DEFAULT expressions, it can be combined with other scalar operators such as passing it as a parameter to a scalar function.

When used in DEFAULT expressions, it cannot be combined with other scalar operators such as passing it as a parameter to a scalar function.

SQL Server 2012

SQL Server 2008

User-Defined Functions

Date Functions

A collection of useful user-defined functions that deal with dates.

String Functions

A collection of useful user-defined functions that deal with strings (varchar/char/nvarchar/nchar).

Tree Functions

A collection of useful user-defined functions that deal with tree or hierarchical design structures.

Table-Valued Functions

A collection of useful table-valued user-defined functions that can be used to join with other tables.

SQL Server Built-in Functions

A reference to all built-in functions available within SQL Server grouped into categories.

Tips and Tricks

A collection of useful SQL Server-related tips and tricks:

SQL Server Error Messages

A list of SQL Server error messages and for certain error messages, discusses ways on how to solve the error or work around them:

Frequently Asked Questions