<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://blogs.msdn.com/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>SQL Programmability &amp; API Development Team Blog : Native Types and Methods</title><link>http://blogs.msdn.com/sqlprogrammability/archive/tags/Native+Types+and+Methods/default.aspx</link><description>Tags: Native Types and Methods</description><dc:language>en-US</dc:language><generator>CommunityServer 2.1 SP1 (Build: 61025.2)</generator><item><title>How are GUIDs compared in SQL Server 2005?</title><link>http://blogs.msdn.com/sqlprogrammability/archive/2006/11/06/how-are-guids-compared-in-sql-server-2005.aspx</link><pubDate>Tue, 07 Nov 2006 01:20:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:1006101</guid><dc:creator>mathh</dc:creator><slash:comments>4</slash:comments><comments>http://blogs.msdn.com/sqlprogrammability/comments/1006101.aspx</comments><wfw:commentRss>http://blogs.msdn.com/sqlprogrammability/commentrss.aspx?PostID=1006101</wfw:commentRss><description>&lt;P&gt;In general, equality comparisons make a lot of sense with uniqueidentifier values. However, if you find yourself needing general ordering, then you might be looking at the wrong data type and should consider various integer types instead.&lt;/P&gt;
&lt;P mce_keep="true"&gt;If, after careful thought, you decide to order on a uniqueidentifier column, you might be surprised by what you get back.&lt;/P&gt;
&lt;P&gt;Given these two uniqueidentifier values:&lt;/P&gt;
&lt;P&gt;@g1=&amp;nbsp;'55666BEE-B3A0-4BF5-81A7-86FF976E763F'&lt;BR&gt;@g2 =&amp;nbsp; '8DD5BCA5-6ABE-4F73-B4B7-393AE6BBB849'&lt;/P&gt;
&lt;P&gt;Many people think that @g1 is less than @g2, since '55666BEE' is certainly smaller than '8DD5BCA5'. However, this is not how SQL Server 2005 compares uniqueidentifier values. &lt;/P&gt;
&lt;P&gt;The comparison is made by looking at byte "groups" right-to-left, and left-to-right within a byte "group". A byte group is what is delimited by the '-' character. More technically, we look at bytes {10 to 15} first, then {8-9}, then {6-7}, then {4-5}, and lastly {0 to 3}.&lt;/P&gt;
&lt;P&gt;In this specific example, we would start by comparing '86FF976E763F' with '393AE6BBB849'. Immediately we see that @g2 is indeed greater than @g1.&lt;/P&gt;
&lt;P&gt;Note that in .NET languages, &lt;A class="" href="http://msdn2.microsoft.com/en-us/library/system.guid(VS.80).aspx" mce_href="http://msdn2.microsoft.com/en-us/library/system.guid(VS.80).aspx"&gt;Guid&lt;/A&gt; values have a different default sort order than in SQL Server. If you find the need to order an array or list of Guid using SQL Server comparison semantics, you can use an array or list of &lt;A class="" href="http://msdn2.microsoft.com/en-us/library/system.data.sqltypes.sqlguid(VS.80).aspx" mce_href="http://msdn2.microsoft.com/en-us/library/system.data.sqltypes.sqlguid(VS.80).aspx"&gt;SqlGuid&lt;/A&gt;&amp;nbsp;instead, which implements IComparable in a way which is consistent with SQL Server semantics. &lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=1006101" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/sqlprogrammability/archive/tags/Sorting/default.aspx">Sorting</category><category domain="http://blogs.msdn.com/sqlprogrammability/archive/tags/Native+Types+and+Methods/default.aspx">Native Types and Methods</category></item><item><title>Sorting undefined characters in Unicode and/or Windows collation</title><link>http://blogs.msdn.com/sqlprogrammability/archive/2006/04/07/570397.aspx</link><pubDate>Fri, 07 Apr 2006 02:21:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:570397</guid><dc:creator>Jun Fang</dc:creator><slash:comments>1</slash:comments><comments>http://blogs.msdn.com/sqlprogrammability/comments/570397.aspx</comments><wfw:commentRss>http://blogs.msdn.com/sqlprogrammability/commentrss.aspx?PostID=570397</wfw:commentRss><description>&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;SPAN style="FONT-SIZE: 10pt"&gt;When comparing two Unicode strings in non-binary collations, SQL Server uses a library that is essentially same as the Windows API CompareStringW. It defines a weight for each recognized character, and then use the weights to compare characters. However, not all code points are defined in the sorting library. They may be undefined because:&lt;?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;SPAN style="FONT-SIZE: 10pt"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;SPAN style="FONT-SIZE: 10pt"&gt;1) The code point is not defined in Unicode standard.&lt;BR&gt;2) The code point is defined in Unicode standard, but not defined by Windows yet. It takes time and effort to define linguistic sorting semantics for new characters. Windows team typically needs to work with local standard body and/or regional PMs to define sorting rules for new characters. They add new character support in every release, and try to catch up. Some characters may have font defined, therefore could be correctly displayed, but still not defined in terms of comparison. For example, NCHAR(13144) - NCHAR(13174).&lt;BR&gt;3) The code point is defined in Windows, but not defined in SQL Server yet. &lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;SPAN style="FONT-SIZE: 10pt"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;SPAN style="FONT-SIZE: 10pt"&gt;Windows NLS team has decided that undefined characters are ignored during string comparison, partly because there is no real good way to compare them against other defined characters. SQL Server inherited this semantics. This does cause some confusing behavior.&amp;nbsp;See below examples.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;SPAN style="FONT-SIZE: 10pt"&gt;&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;SPAN style="FONT-SIZE: 10pt"&gt;declare @undefined_char1 nvarchar(10), @undefined_char2 nvarchar(10)&lt;BR&gt;set @undefined_char1 = nchar(0x0000)&lt;BR&gt;set @undefined_char2 = nchar(13144)&lt;BR&gt;select 'Undefine characters compare equal to empty string'&lt;BR&gt;where @undefined_char1 = ''&lt;BR&gt;select 'All undefine characters compare equal'&lt;BR&gt;where @undefined_char1 = @undefined_char2&lt;BR&gt;go&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;SPAN style="FONT-SIZE: 10pt"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;SPAN style="FONT-SIZE: 10pt"&gt;create table t (c nvarchar(10))&lt;BR&gt;go&lt;BR&gt;create unique index it on t(c)&lt;BR&gt;go&lt;BR&gt;-- first insert succeeds, but second insert fails with duplicate key error.&lt;BR&gt;insert t values (nchar(0x0000))&lt;BR&gt;insert t values (nchar(13144))&lt;BR&gt;go&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;SPAN style="FONT-SIZE: 10pt"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;SPAN style="FONT-SIZE: 10pt"&gt;As you can see, since all undefined characters compare equal, they could cause duplicate key errors. Similarly, if you create one table with name of an undefined character, and then try to create another table with another undefined character, the second table creation would fail due to duplicate names, even though the code points of the two undefined characters are different. This could also cause confusing results in string matching builtins such as CHARINDEX, PATINDEX, or LIKE.&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;SPAN style="FONT-SIZE: 10pt"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;SPAN style="FONT-SIZE: 10pt"&gt;While these results seem confusing, the basic rule is actually very simple, i.e., undefined characters are ignored during comparison and string matching. Once you understand and remember this rule, the behavior should be easy to understand. &lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;SPAN style="FONT-SIZE: 10pt"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;SPAN style="FONT-SIZE: 10pt"&gt;There have been arguments whether undefined characters should be ignored. Since this is the behavior on Windows platform, and there is not a definitely better way to sort them, and for backwards compatibility, we are going to maintain this behavior. &lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;SPAN style="FONT-SIZE: 10pt"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;SPAN style="FONT-SIZE: 10pt"&gt;If your app needs to work with these undefined characters and expect to treat them as regular characters, you can use binary collation. In binary collation, comparison is done purely based on code points, not linguistic rules, so there is no notion about defined vs. undefined.&lt;/SPAN&gt;&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=570397" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/sqlprogrammability/archive/tags/Sorting/default.aspx">Sorting</category><category domain="http://blogs.msdn.com/sqlprogrammability/archive/tags/SQL+Server+2005/default.aspx">SQL Server 2005</category><category domain="http://blogs.msdn.com/sqlprogrammability/archive/tags/SQL+Server+2000/default.aspx">SQL Server 2000</category><category domain="http://blogs.msdn.com/sqlprogrammability/archive/tags/Native+Types+and+Methods/default.aspx">Native Types and Methods</category></item><item><title>Multiplication and Division with Numerics</title><link>http://blogs.msdn.com/sqlprogrammability/archive/2006/03/29/564110.aspx</link><pubDate>Wed, 29 Mar 2006 20:21:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:564110</guid><dc:creator>mathh</dc:creator><slash:comments>1</slash:comments><comments>http://blogs.msdn.com/sqlprogrammability/comments/564110.aspx</comments><wfw:commentRss>http://blogs.msdn.com/sqlprogrammability/commentrss.aspx?PostID=564110</wfw:commentRss><description>&lt;FONT size=2&gt;
&lt;P&gt;It can be surprising to see certain results when doing numeric arithmetic:&lt;/P&gt;
&lt;P&gt;&lt;BR&gt;&lt;FONT face="Courier New"&gt;declare @num1 numeric(38,10)&lt;BR&gt;declare @num2 numeric(38,10)&lt;BR&gt;set @num1 = .0000006&lt;BR&gt;set @num2 = 1.0&lt;BR&gt;select cast( @num1 * @num2 as numeric(38,10))&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;BR&gt;Yields:&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;.0000010000&lt;/P&gt;
&lt;P&gt;Instead of:&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;.0000006000&lt;/P&gt;
&lt;P&gt;&lt;BR&gt;Why?&lt;/P&gt;&lt;/FONT&gt;&lt;FONT size=2&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;Well, Books Online (see Precision, Scale, and Length) dictates the following rule for numeric arithmetics:&lt;/P&gt;&lt;/FONT&gt;
&lt;TABLE cellSpacing=1 cellPadding=0 width=623 border=1&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD vAlign=center width="40%"&gt;&lt;B&gt;
&lt;P align=center&gt;Operation &lt;/B&gt;&lt;/P&gt;&lt;/TD&gt;
&lt;TD vAlign=center width="39%"&gt;&lt;B&gt;
&lt;P align=center&gt;Result precision &lt;/B&gt;&lt;/P&gt;&lt;/TD&gt;
&lt;TD vAlign=center width="21%"&gt;&lt;B&gt;
&lt;P align=center&gt;Result scale * &lt;/B&gt;&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;
&lt;TR&gt;
&lt;TD vAlign=center width="40%"&gt;
&lt;P&gt;e1 + e2&lt;/P&gt;&lt;/TD&gt;
&lt;TD vAlign=center width="39%"&gt;
&lt;P&gt;max(s1, s2) + max(p1-s1, p2-s2) + 1&lt;/P&gt;&lt;/TD&gt;
&lt;TD vAlign=center width="21%"&gt;
&lt;P&gt;max(s1, s2)&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;
&lt;TR&gt;
&lt;TD vAlign=center width="40%"&gt;
&lt;P&gt;e1 - e2&lt;/P&gt;&lt;/TD&gt;
&lt;TD vAlign=center width="39%"&gt;
&lt;P&gt;max(s1, s2) + max(p1-s1, p2-s2) + 1&lt;/P&gt;&lt;/TD&gt;
&lt;TD vAlign=center width="21%"&gt;
&lt;P&gt;max(s1, s2)&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;
&lt;TR&gt;
&lt;TD vAlign=center width="40%"&gt;
&lt;P&gt;e1 * e2&lt;/P&gt;&lt;/TD&gt;
&lt;TD vAlign=center width="39%"&gt;
&lt;P&gt;p1 + p2 + 1&lt;/P&gt;&lt;/TD&gt;
&lt;TD vAlign=center width="21%"&gt;
&lt;P&gt;s1 + s2&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;
&lt;TR&gt;
&lt;TD vAlign=center width="40%"&gt;
&lt;P&gt;e1 / e2&lt;/P&gt;&lt;/TD&gt;
&lt;TD vAlign=center width="39%"&gt;
&lt;P&gt;p1 - s1 + s2 + max(6, s1 + p2 + 1)&lt;/P&gt;&lt;/TD&gt;
&lt;TD vAlign=center width="21%"&gt;
&lt;P&gt;max(6, s1 + p2 + 1)&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;
&lt;TR&gt;
&lt;TD vAlign=center width="40%"&gt;
&lt;P&gt;e1 { UNION | EXCEPT | INTERSECT } e2&lt;/P&gt;&lt;/TD&gt;
&lt;TD vAlign=center width="39%"&gt;
&lt;P&gt;max(s1, s2) + max(p1-s1, p2-s2)&lt;/P&gt;&lt;/TD&gt;
&lt;TD vAlign=center width="21%"&gt;
&lt;P&gt;max(s1, s2)&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;FONT size=2&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;In this case, the multiplication result precision and scale are computed as follows:&lt;/P&gt;
&lt;P&gt;Precision = P1 + P2 + 1 = 38 + 38 + 1 = 77&lt;/P&gt;
&lt;P&gt;Scale = S1 + S2 = 10 + 10 = 20&lt;/P&gt;
&lt;P&gt;So conceptually, the result should be numeric(77, 20), which isn't allowed. This is where the fine prints come in:&lt;/P&gt;
&lt;P&gt;* The result precision and scale have an absolute maximum of 38. When a result precision is greater than 38, the corresponding scale is reduced to prevent the integral part of a result from being truncated.&lt;/P&gt;
&lt;P&gt;Books Online currently doesn't go into the specifics on how such truncation is performed. &lt;/P&gt;
&lt;P&gt;Since the precision is higher than 38, we try to avoid truncating the integral part of the value by reducing the scale (thus truncating the decimal part of the value instead). How much scale should be sacrificed? There is no right answer. If we preserve too much, and the result of the multiplication of large numbers will be way off. If we preserve too little, multiplication of small numbers becomes an issue.&lt;/P&gt;
&lt;P&gt;In SQL Server 2005 RTM (and previous versions), we decided preserve a minimum scale of 6 in both multiplication and division. So our numeric(77,20) is truncated as numeric(38,6), and then is then casted as numeric(38,10). However at this point it is too late, and some data has been lost. This explains the result you would see in the previous expression.&lt;/P&gt;
&lt;P&gt;Because of this, it is important to try to minimally quantify the precision and scale of the operands involved in multiplication and division. In this case:&lt;/P&gt;&lt;/FONT&gt;
&lt;P&gt;&lt;FONT face="Courier New" size=2&gt;declare @num1 numeric(18,10)&lt;BR&gt;declare @num2 numeric(18,10)&lt;BR&gt;set @num1 = .0000006&lt;BR&gt;set @num2 = 1.0&lt;BR&gt;select cast( @num1 * @num2 as numeric(38,10))&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;&lt;FONT size=2&gt;
&lt;P&gt;The resulting type would be numeric(37,20). Since this type's precision and scale does not exceed our current limits, no implicit truncation is performed. We then cast the result as numeric(38,10), which doesn't cause data loss in our case.&lt;/P&gt;
&lt;P&gt;If you cannot accurately type the values involved in multiplication and division, for example if they are procedure parameters that are called with wildly different values, you may want to look into approximate numeric types (float, real), or perhaps define your own very high capacity user defined exact numeric data type using the CLR.&lt;/P&gt;
&lt;P&gt;I hope this was useful. Let us know if there are particular topics you'd like to hear about!&lt;/P&gt;
&lt;P&gt;-Mat&lt;/P&gt;&lt;/FONT&gt;&lt;FONT size=2&gt;&lt;/FONT&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=564110" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/sqlprogrammability/archive/tags/SQL+Server+2005/default.aspx">SQL Server 2005</category><category domain="http://blogs.msdn.com/sqlprogrammability/archive/tags/SQL+Server+2000/default.aspx">SQL Server 2000</category><category domain="http://blogs.msdn.com/sqlprogrammability/archive/tags/Native+Types+and+Methods/default.aspx">Native Types and Methods</category></item><item><title>Newsequentialid (Histrory/Benefits and Implementation)</title><link>http://blogs.msdn.com/sqlprogrammability/archive/2006/03/23/559061.aspx</link><pubDate>Thu, 23 Mar 2006 19:41:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:559061</guid><dc:creator>dragant</dc:creator><slash:comments>15</slash:comments><comments>http://blogs.msdn.com/sqlprogrammability/comments/559061.aspx</comments><wfw:commentRss>http://blogs.msdn.com/sqlprogrammability/commentrss.aspx?PostID=559061</wfw:commentRss><description>&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;SPAN style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;In general, we made significant improvements in SQL Server scalability during &lt;?xml:namespace prefix = st1 ns = "urn:schemas-microsoft-com:office:smarttags" /&gt;&lt;st1:State w:st="on"&gt;&lt;st1:place w:st="on"&gt;Yukon&lt;/st1:place&gt;&lt;/st1:State&gt;.&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;One of the areas of improvement is replication scalability.&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;While doing merge replication testing we found out that scaling was severely affected by high number of I/O operations.&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;The cause of the problem was that new rows were inserted in random disk pages.&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;Guid generating function (newid) was returning non-sequential guids which resulted in random B-tree lookups.&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;After some investigation we figured out that we could use the new OS function UuidCreateSequential with some byte scrambling to convince the rest of SQL engine that guids are produced in sequential order.&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;Therefore, we implemented the new intrinsic function, Newsequentialid which is nothing more than a wrapper over the OS function UuidCreateSequential.&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;Therefore all of the semantics of UuidCreateSequential are present in newsequentialid intrinsic.&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;The official documentation for UuidCreateSequential is &lt;A href="http://msdn.microsoft.com/library/default.asp?url=/library/en-us/rpc/rpc/uuidcreatesequential.asp"&gt;here&lt;/A&gt;.&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;The conclusion:&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;If you are generating guids as your row identifiers, you may be interested in newsequentialid function.&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;For example, after replication folks started using this function they were able to completely fill their data and index pages.&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;Also, the row inserts did not require searches through the B-trees because the last modified page was already in memory.&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;SPAN style="mso-tab-count: 1"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;You should be aware of all of the limitations of UuidCreateSequential before you start using newsequentialid.&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;For example, computers without network card will return only locally unique values and the IDs returned can be used to discover some network properties of your server.&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;Additional notes:&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt 30pt; TEXT-INDENT: -0.25in; mso-list: l0 level1 lfo1; tab-stops: list 30.0pt"&gt;&lt;SPAN style="mso-list: Ignore"&gt;1)&lt;SPAN style="FONT: 7pt 'Times New Roman'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;/SPAN&gt;While testing newsequentialid in highly concurrent environments, we found that on AMD64 machines the OS function may return same values.&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;Therefore, we put the global mutex so that only one user can be going through newsequentialid at the time.&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt 30pt; TEXT-INDENT: -0.25in; mso-list: l0 level1 lfo1; tab-stops: list 30.0pt"&gt;&lt;SPAN style="mso-list: Ignore"&gt;2)&lt;SPAN style="FONT: 7pt 'Times New Roman'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;/SPAN&gt;The old guid generating function NewId is also a wrapper over an OS function CoCreateGuid, therefore all of the semantics of CoCreateGuid exist in NewId.&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt 30pt; TEXT-INDENT: -0.25in; mso-list: l0 level1 lfo1; tab-stops: list 30.0pt"&gt;&lt;SPAN style="mso-list: Ignore"&gt;3)&lt;SPAN style="FONT: 7pt 'Times New Roman'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;/SPAN&gt;The only additional work that we do in newsequentialid is that we take guids and arrange bytes such that values work well with existing engine guid compare algorithm.&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;Since input bits are unique and we only move the bytes returned by the OS, the output is also guaranteed to be unique.&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt 30pt; TEXT-INDENT: -0.25in; mso-list: l0 level1 lfo1; tab-stops: list 30.0pt"&gt;&lt;SPAN style="mso-list: Ignore"&gt;4)&lt;SPAN style="FONT: 7pt 'Times New Roman'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;/SPAN&gt;Because two consecutive calls to this function are guaranteed to return different results, the function is marked as non-deterministic.&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;Therefore, we opted to allow the use of this function only as default value.&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;The reason for this decision is because algebrizer and optimizer are limited in what they can do with non-deterministic functions.&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=559061" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/sqlprogrammability/archive/tags/SQL+Server+2005/default.aspx">SQL Server 2005</category><category domain="http://blogs.msdn.com/sqlprogrammability/archive/tags/Native+Types+and+Methods/default.aspx">Native Types and Methods</category></item></channel></rss>