A Problem with Boolean Logic

Your requirement: to find the things where either A or B is true and C is true. Your first draft might be this:


(field, table, function, logic all anonymised to protect the perpetrator)

What’s the problem? Operator Precedence, that’s the problem.

Operator Precedence?

The order in which calculations are done – not just reading from left to right, but remembering that things like multiplication and division happen before addition and subtraction. My son tells me that kids nowadays are being taught something called “BIDMAS” – which stands for “Brackets, Indices, Division, Multiplication, Addition, Subtraction”. Or it can be BODMAS – Brackets, Operations, Division… (Operation is a fancy new way of describing indices – ie xy)

Unsurprisingly, there are similar rules for Boolean operators. (Boolean Operators LogicaL Order of CalculationS? BOLLOCS? So close…) And these all mix in together, with AND being at the same level as multiplication, and OR being at the same as addition. Microsoft has kindly provided a list of the operator precedence rules it uses in SQL Server.

So What? I hear you cry

Well, we had a malfunctioning server. Running sp_WhoIsActive against the server showed 400-odd queries blocked by five instances of a malformed bit of code like the statement at the top of this post.

We, like many places, have a variety of third-party applications that allow users to write their own queries at a high level, and then the applications fill in the blanks, and add all the close brackets and things, to make the query actually parse… What these apps don’t do, of course, is fix the broken logic for you. Anyway, our Joe Punter had been asked to run a query to find customer results (or something) where condition A or condition B were true, and condition C was also true. And he had come up with the A OR B AND C logic above, and was puzzled when he fired off the report that it didn’t come back instantly, so he fired it off again. And again. And a couple more times for good luck.

Reproducing the Problem For Fun & Blogging Purposes

We are using the AdventureWorks Database, as that’s easy to get hold of. (NB: MS has moved all this stuff to github – you may need to update your bookmarks accordingly.)

This query below is a cut-down hack that illustrates the problem. In the data sense, it’s garbage, but it illustrates the problem albeit with several orders of magnitude less data.

       Sales.SalesOrderDetail AS sod,
       Sales.SalesOrderHeader AS soh
       soh.OnlineOrderFlag = 1
    OR soh.BillToAddressID = soh.ShipToAddressID
   AND soh.SalesOrderID = sod.SalesOrderID;

The query plan generated is…unpleasant


As you can see, the query plan is dominated by that Nested Loop operator. Let’s have a look what’s going on there:



Let’s rewrite the query properly (ie add a bracket or two):

       Sales.SalesOrderDetail AS sod,
       Sales.SalesOrderHeader AS soh
       (soh.OnlineOrderFlag = 1 OR soh.BillToAddressID = soh.ShipToAddressID)
   AND soh.SalesOrderID = sod.SalesOrderID;

And the query plan:

Spot the difference.

Yes, the query returns different answers – that’s kinda the point inasmuch as the original query would not have returned what the user wanted… But we can now see a more appropriate join operator, and one that’s not taking all the query time.

The moral of the story? Get your logic right, and your server won’t fall around your ears.

Posted in SQLServerPedia Syndication | Tagged , , , , | 2 Comments

T-SQL Tuesday – Bad Habits – Fixed by SQLPrompt

TSQL2sDay150x150T-SQL Tuesday again. And it’s been a few months since I last blogged, let alone for this blog-party, but, hey, I’m here now. This time, Aaron Bertrand (blog|@aaronbertrand) has given two options – and, given the amount time I’ve been spending lately talking about, seeing and performing in operas, I thought I would talk about T-SQL. And, yeah it’s another redgate-related SQLPrompt Post. <disclaimer/disclosure>They don’t pay me, they’ve not asked me to write this, but they do provide me with software, and I would buy this tool myself if I wasn’t on the FoRG programme…

Bad Habits

Aaron has been busy collecting a list of many many bad T-SQL / SQL Server habits, and some of them are scary.

The one I’m writing about – Using AS instead of = for Column Aliases – is the subject of a holy war, despite being mostly seen as stylistic.

Some of you DBA weirdos insist on writing code like

SELECT x = col1...

rather than the proper, ANSI-standard form of

SELECT col1 AS x...

Even though using “AS” conforms with the ANSI standard, Aaron is against it. He’s wrong, and I guess there are plenty of other deviants out there, but there are plenty of us right-minded people who prefer the proper version.

If you’re working in a big team, though, you can run into real problems where there’s a mix of styles in use.

SQLPrompt’s “Code Smells”

Redgate’s SQLPrompt has new functionality to identify what it calls “code smells” – bits of non-standard functionality, or deprecated usages. It highlights these smelly lines of code with a green wavy line, like you see under dodgy grammar in Word.

If you put your cursor into the green wavy line, the smelly bit is highlighted and a new blue icon appears in the left hand gutter. Click on that, or press CTRL, and up comes a window that describes the problem, and gives you a link to redgate’s documentation about it. OK, it’s a bit sparse, but that’s not the point of this post.

De-stinking code

If you’ve got a lot of code to review, and want to fix this easily, fortunately you can apply this fix automatically using SQLPrompt as part of its reformat sweep.

You’ll need to check the “Apply column alias style” box, and then pick the right style (above), but that’s all you need to do. (OK, if you’re a deviant like the guy I work with, you can set it to use one of the other WRONG formats, but don’t do that because it’s WRONG…)

A quick CTRL+K, CTRL+Y later, and you get properly formatted code:

And as for my strange friend, if he wants to see it in the wrong format, he can set up his own preferences. Or he could, if he had a licence for SQLPrompt, which he doesn’t… Yet…

Posted in T-SQL Tuesday | Tagged , , , | Leave a comment

SQL Server Installation Failed Due to Pending Restart of Server?

Incidentally, the sort of problem I’m discussing here is why I (almost) always copy the patch/servicepack/media to somewhere local – each time you run a servicepack or cumulative update, the whole package decompresses to your hard drive, runs, and then deletes itself afterwards – not something that you want to wait for several times…

Patching some SQL Servers today, I had a couple of failures because there was a reboot pending (presumably a hangover from the Windows patching that had gone before).

Reboot the server, restart the installation, and get the message again. Swear. Remember there’s a registry key value you can rename to bypass these checks. (It’s “HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\Session Manager\PendingFileRenameOperations” – rename it to, say, PendingFileRenameOperationsBackup and have another go. Remember to change it back when you’re done.)

Except in this case, there was nothing there… The key value didn’t exist. Or if it did, I couldn’t see it, which is a bit awkward as I’m supposed to be administering these servers. muttermutter Anyway.

If you’re running a normal SQL Server setup, you can do a lot from the command line – and this is all documented elsewhere, and I’m not going to rehash it.

However, as mentioned at the top (you did read the small print, yes?), the typical service pack / cumulative update / hotfix is distributed as a self-extracting executable, called something like SQLServer2014-KB4032541-x64.exe that launches something else.

Fortunately, if you run your executable with the /? parameter, you’ll get a helpful list of what parameters you can pass into the service pack:

C:\<<somepath>>\ >SQLServer2014-KB4032541-x64.exe /?
Microsoft (R) SQL Server 2014 12.00.5000.00
Copyright (c) Microsoft Corporation.  All rights reserved.
setup.exe /[option]={value} /[option]={value} ...
ACTION                       Specifies a Setup work flow, like INSTALL,
                              UNINSTALL, or UPGRADE. This is a required
ALLINSTANCES                 Specifies that all instances are to be included
                              in the Setup operation. This parameter is
                              supported only when applying a patch.
CLUSTERPASSIVE               Specifies that SQL Server Setup should not manage
                              the SQL Server services. This option should be
                              used only in a non-Microsoft cluster environment.
ENU                          Use the /ENU parameter to install the English
                              version of SQL Server on your localized Windows
                              operating system.
ERRORREPORTING               Specify if errors can be reported to Microsoft to
                              improve future SQL Server releases. Specify 1 or
                              True to enable and 0 or False to disable this
HELP                         Displays the command line parameters usage
IACCEPTSQLSERVERLICENSETERMS By specifying this parameter and accepting the
                              SQL Server license terms, you acknowledge that
                              you have read and understood the terms of use.
INDICATEPROGRESS             Specifies that the detailed Setup log should be
                              piped to the console.
INSTANCEID                   Specify the Instance ID for the SQL Server
                              features you have specified. SQL Server directory
                              structure, registry structure, and service names
                              will incorporate the instance ID of the SQL
                              Server instance.
INSTANCENAME                 Specify a default or named instance. MSSQLSERVER
                              is the default instance for non-Express editions
                              and SQLExpress for Express editions. This
                              parameter is required when installing the SQL
                              Server Database Engine (SQL), Analysis Services
                              (AS), or Reporting Services (RS).
QUIET                        Setup will not display any user interface.
QUIETSIMPLE                  Setup will display progress only, without any
                              user interaction.
SQMREPORTING                 Specify that SQL Server feature usage data can be
                              collected and sent to Microsoft. Specify 1 or
                              True to enable and 0 or False to disable this
UIMODE                       Parameter that controls the user interface
                              behavior. Valid values are Normal for the full
                              UI,AutoAdvance for a simplied UI, and
                              EnableUIOnServerCore for bypassing Server Core
                              setup GUI block.
X86                          Specifies that Setup should install into WOW64.
                              This command line argument is not supported on an
                              IA64 or a 32-bit system.
Press any key to exit...

However, nothing here is immediately helpful. But then there’s this post that talks about the repeated-reboot-pending-failure for a standard SQL Server setup, and I found myself wondering if you could use the same undocumented /SkipRules parameter with a value of “RebootRequiredCheck”.

C:\<<somepath>>\ >SQLServer2014-KB4032541-x64.exe /action=Patch /SkipRules=RebootRequiredCheck

You can. No reboot check performed. Patching can continue. Hurrah.


Undocumented parameters are undocumented. Which means they’re not supported. You have been warned.

Posted in SQLServerPedia Syndication | Tagged , , , | Leave a comment

Skype for Business – SQL Server Frustrations


The environment is new and secure.

Assumptions: You are a DBA who knows how to build WSFCs and AGs. If you need help with that, then you’re in the wrong place for this post.

The Windows 2016 / SQL Server 2016 environment has been built, SQL Server 2016 Enterprise Edition installed, the Windows Failover Cluster configured, HA has been enabled on the SQL Servers, the Skype for Business server software has been installed (but not configured) and all is well.

Now to configure / create the Skype For Business topology. How hard can it be?


This is being done from memory, so the actual implementation detail may be a little bit hazy, and I haven’t got any screenshots or actual error messages as this was done on someone else’s computer.

What went wrong, though – that’s real. And the reasoning is also as near as I can remember.

Creating the Topology

Configuring for Availability Groups

Launch the Topology Configuration wizard/app. By default it wants to go with mirroring, so you tell it to use Availability Groups. This causes the app to ask up front for the availability group name, which doesn’t exist, and then ask for a server name.

Don’t assume that this is a mistake and give it the server name. Alternatively, don’t get confused and give it a server name. You’ve got to get this right up front. If you don’t, you’ll have to strip out the whole thing and start over.

Use PowerShell rather than the GUI

The GUI feels nicer (barring obvious confusion above), but doesn’t adequately report error / warning / problems. We were experiencing problems with the installation, and all the messages that the skype engineers were seeing led them to view it as a “problem with the database server”.

Using the Install-CsDatabase command gives a whole heap of more useful information, including showing that a connection was made to the server and configuration settings (for database file paths) were read correctly. It’s not a problem with the server.

Oh, and use the -UseDefaultSQLPaths parameter, assuming you’ve configured your server up correctly, as it’s easier than trying to figure out the various other path options.

What $ share?

The output from Install-CsDatabase showed that the installer was attempting to copy database files to the appropriate locations, but had translated the value retrieved from SQL Server, say, E:\MSSQL\SQLData to \\SkypeServer1\E$\MSSQL\SQLData – the transaction log path had suffered similar indignities. Yes, that’s using the $ / “admin” shares. The problem is that, for various security reasons, these shares have been removed.

If you try creating the blank databases, the installer complains that the database is there, but it’s version 0, and that the installer can’t upgrade from version 0 to version 12. So drop those databases as they’re not doing any good.

The only way forward on this appeared to be to get an exemption logged and create those shares. Installation can (finally) proceed. Hurrah.

When the databases have all been created, create AG, failover, rerun topology-push to create users & jobs on the secondary, and failback.

That was a painful afternoon.

Still, all is not entirely well.

The Next Day

The following day, you’ll notice that various SQLAgent jobs have failed. Checking the server, you will notice that there are the following jobs:

  • LcsCDR_Purge
  • LcsCDR_UsageSummary
  • LcsLog_Purge
  • QoEMetrics_Purge
  • QoEMetrics_UsageSummary

These jobs have been set up in a sensible way – step 1 is a check to see if the database / server is the primary or the secondary, and step 2 actually does the work (if this is the primary). Here’s that step 1 in full:

declare @_MirroringRole int
set @_MirroringRole = (
    select mirroring_role
      from sys.database_mirroring
     where database_id = DB_ID('LcsCDR')
if (@_MirroringRole is not NULL and @_MirroringRole = 2) begin
    raiserror('Database is mirrored', 16, 1)
else begin
    print ('Database is not mirrored')

That’s great, if you’re using mirroring. But we’re not. And Skype-for-Business *knows* that we’re not, as we told it that right up front. What this check should be looking at is the sys.dm_hadr_database_replica_state DMV and working against that. This code seems to work:

declare @_AGPrimary bit
if exists (select * from sys.dm_hadr_database_replica_states where database_id = DB_ID('LcsCDR'))
    set @_AGPrimary = (SELECT is_primary_replica FROM sys.dm_hadr_database_replica_states WHERE database_id = DB_ID('LcsCDR') and is_local = 1)
    IF (@_AGPrimary = 0)
        RAISERROR('Database is AG secondary',16,1);
        print ('Database is AG primary');

Your choice – either replace the existing step 1, or add this code to it, and the jobs now work. Depending on how nit-picky you are about these things, you might want to change the two references to ‘LcsCDR’ to match the database mentioned in the job… Given that the databases are / should be in the same AG, though, this might be overkill/paranoia. I’m paranoid. It goes with the territory.

Creating the Listener – Active Directory Permissions

Stepping back a bit, one other thing that bit us was that we had problems creating the availability group listener – the cluster didn’t have the rights to do this. This is fixed by either:

  1. (Preferred) granting the failover cluster virtual server object permission to create objects in the OU in which it lives.
  2. (alternatively, should work, untested by me) create the listener computer object first, and grant the failover cluster virtual server CNO rights to control / edit that object.

All done

The engineers can now carry on with configuring / building out the skype-for-business environment. Rather them than me. I need a beer after all that!

Posted in SQLServerPedia Syndication | Tagged , , , , | Leave a comment

What A Difference An Index Makes

M’colleagues over the way were having problems with an upgrade / feature installation of McAfee EPO UDLP (no, I have no idea what that means). Looking at what was happening on the SQL Server that’s at the back of that system, with the aid of SolarWinds and the excellent (and free) sp_WhoIsActive, we quickly found a possible culprit query:

    UserId = @UserID
    AND GroupId = @GroupID ;

As many as 70 simultaneous occurrences of that query, according to sp_WhoIsActive. Here’s what SolarWinds says for that query:

100k runs of the query in a ten minute interval? yeowch. Yeah, this should be optimised if possible. The primary wait type was CPU – indicating that the data was all in RAM, but the CPU was having to schlep through the entire table to find what it needed. Or to find that it didn’t need anything. Or something.

The Table

The table itself is very simple – just three integer fields. However, the indexing was purely a clustered index on the primary key (an ID). The full schema of the table is:

CREATE TABLE [dbo].UDLP_EventUserGroups
    [AutoId]  [INT] IDENTITY(1, 1) NOT NULL ,
    [UserId]  [INT] NOT NULL ,
    [GroupId] [INT] NOT NULL ,
    CONSTRAINT [PK_UDLP_EventUserGroups]

(As generated by SSMS…)

SQL Server wasn’t providing any index recommendations on this 250k row table. But I wondered if we could speed things up a little…

I took a copy of the table onto a development instance of SQL Server:

CREATE TABLE [dbo].UDLP_EventUserGroups_Indexed
    [AutoId]  [INT] IDENTITY(1, 1) NOT NULL ,
    [UserId]  [INT] NOT NULL ,
    [GroupId] [INT] NOT NULL ,
    CONSTRAINT [PK_UDLP_EventUserGroups_Indexed]
SET IDENTITY_INSERT dbo.UDLP_EventUserGroups_Indexed ON ;
INSERT INTO dbo.UDLP_EventUserGroups_Indexed
    AutoId ,
    UserId ,
    AutoId ,
    UserId ,
    <LinkedServer>.<EPODatabase>.dbo.UDLP_EventUserGroups AS ueug ;
SET IDENTITY_INSERT dbo.UDLP_EventUserGroups_Indexed OFF ;

Let’s build an index on the UserID and include the GroupID.

CREATE NONCLUSTERED INDEX ncidx_EUG_UserPlusGroup ON dbo.UDLP_EventUserGroups_Indexed(UserId) INCLUDE (GroupId);

That didn’t take long…

…and onto the testing:

DECLARE @GroupID INT = 1 ;
DECLARE @UserID INT = 2937 ;
    UserId = @UserID
    AND GroupId = @GroupID ;
    UserId = @UserID
    AND GroupId = @GroupID ;

The output:

Logical reads down from 719 to 3. Win!


McAfee’s guidance for creating indexes on their databases amounts to “go ahead, but you’ll have to delete them before we’ll support you.” I can live with that. After all, the create & drop index commands aren’t exactly complicated…

We’re leaving the index in place for the moment – the guys say that it’s improved the general performance as well as just during the upgrade…


Going back to SolarWinds. The index was cleared for creation in production, and implemented, as near as makes no odds, at 2:50 that afternoon, so we have some nice before & after pictures.

Remember that summary shot from earlier? Here’s the post-index-creation version:

So we’ve gone from 100k runs of the query each taking 0.286s to 1.25M runs of the query, each taking something under 0.002s. Just one little index did that.

Reminder: That last ten minute window has 12x the number of runs of that query, but uses way less server resources.

Here’s the CPU usage graphs from SolarWinds.

Again, remember that the index was created at 2:50, and there were significantly more queries run after that time than before – you can see that on the log flushes / transaction log throughput:

Posted in SQLServerPedia Syndication | Tagged , , , | Leave a comment

Database Migration / Upgrade problem – Fulltext Wordbreaker, filter, or protocol handler does not exist

Long title. Sorry about that.


I was migrating a few databases to a slightly upgraded server – new hardware, same OS/SQL main version, but the new one was fully service packed / updated etc. The environment dictated that I was doing this by the backup-restore method.

Restoring 27 databases; they all restored properly, but 15 of them gave a warning along these lines:

Warning: Wordbreaker, filter, or protocol handler used by catalog ‘FOOBARBAZ’ does not exist on this instance. Use sp_help_fulltext_catalog_components and sp_help_fulltext_system_components check for mismatching components. Rebuild catalog is recommended.

NB: the name displayed doesn’t necessarily match the name of any of the databases in use, just to annoy – they were (in this case) close, which is why I thought they might be…

What to do?

Firstly, check there’s really a problem by doing what the error message says – use sp_help_fulltext_catalog_components and sp_help_fulltext_system_components to check the versions of libraries that are expected by your database, and those installed on your system, respectively.

In the database that’s complaining, run the following:

EXEC sp_help_fulltext_catalog_components;

The versions the database is expecting are that the Wordbreaker is v12.0.6828.0, and the profile handler v2005.90.3042.0 (ie, the version of SQL that the server was running…)

Now, run the following to check which components / versions are actually installed on your server:

EXEC sys.sp_help_fulltext_system_components @component_type='all';

(Edited / abbreviated results):

As you can see, the versions don’t match – the installed versions of those components are v12.0.9736.0 for the wordbreaker, and v2005.90.5324.0 for the protocol handler. And, yes, I know it’s an old version of SQL Server…

How do we fix this?

(The version mis-match, thing, that is – upgrading SQL Server isn’t in scope for this project, unfortunately…)

Read the error message again. It tells you what to do.

Rebuild catalog is recommended.

Rebuild the catalog. OK.

Picking one of the databases at random, run:

SELECT * FROM sys.fulltext_catalogs AS fc

In this particular situation, I had about 15 to do, and going through each one of those 25 similarly-named databases looking for each of the fifteen full-text catalogs that may (or may not) have the same name as the database struck me as being not much fun. So, let SQL Server do the heavy lifting by generating the ALTER FULLTEXT CATALOG statements for you.

The query that needs to be executed in each database is relatively simple:

FROM sys.fulltext_catalogs AS fc2;
PRINT @sql;
--EXEC (@sql); -- yes, I'm paranoid, and want to see what query is going to be run before I actually run it.

This can be wrapped up in a call to the undocumented sp_MSforeachdb to go through and generate that query on every database with fulltext catalog(s):

EXEC sp_MSforeachdb
USE [?];
IF EXISTS (SELECT * FROM sys.fulltext_catalogs AS fc)
    FROM sys.fulltext_catalogs AS fc2;
       PRINT @sql
       --EXEC (@sql) -- Uncomment this EXEC when happy
' ;

NB: The last line in the command being processed is commented out, to make sure you’re happy with what’s going on before you actually do anything you might regret. Such as running code you don’t understand against your production environments. Because you would never do that, would you?

When you’re happy with the query you’re seeing, uncomment the EXEC (@sql) line.

The Results

Check your work by running the original query again:

EXEC sp_help_fulltext_catalog_components;

Success! The versions now match what we see in the results from sp_help_fulltext_system_components.

Job done. I hope. But, y’know, backup those databases before doing anything else…

Posted in SQLServerPedia Syndication | Tagged , | 1 Comment

SQL Server Non-Unique Clustered Indexes Are Evil!

Non-Unique Clustered Indexes Are Evil And We Have The Proof.

You won’t believe it when you see it.

Face it – I can’t write click-bait…

I was reading Grant Fritchey’s (Blog|@gfritchey) comments in the SQL Server Central forum thread “Advice on Creating Unique Clustered Index“, and was reminded of something I saw in Kalen Delaney’s Precon at SQLBits 11 (Nottingham).

Here’s how to prove the evil-ness of nonunique clustered indexes.

Preparing for the evil

Quick! Grab a SQL Server instance, and create a new table. Don’t worry, it’s tiny. At least, to start off…

CREATE TABLE ClusteredIndexCrash ( i TINYINT NOT NULL ) ;
CREATE CLUSTERED INDEX ClusteredIndexCrashIdx ON dbo.ClusteredIndexCrash( i ) ;

The theory behind clustered indexes is that they are (usually) unique – after all, they define the logical layout of your table on disk. And if you have multiple records with the same clustering index key, then which order would they be in? If you don’t define the CI as unique, then SQL Server will add (behind the scenes) a so-called “Uniqueifier” (or maybe “uniquifier”) to fix that. Grant’s first post in the thread referenced above gives some information about how to see this Uniqu[e]ifier in the table structure itself.

Add data

INSERT INTO dbo.ClusteredIndexCrash
SELECT TOP 1000000
    syscolumns c1 ,
    syscolumns c2 ,
    syscolumns c3 ;

1 million rows – that’s not going to be enough. Let’s add a few more, in batches.

INSERT INTO dbo.ClusteredIndexCrash
SELECT TOP 1000000
    syscolumns c1 ,
    syscolumns c2 ,
    syscolumns c3 ;
GO 2146

That is going to take a while. Fire up another window so you can run a different query to keep an eye on how far it has got.

    OBJECT_NAME(i.object_id) ,
    p.rows / 1000000 ,
    p.rows ,
    POWER(CONVERT(BIGINT, 2), 31) / 1000000
    sys.partitions p
    sys.indexes i ON i.index_id = p.index_id
                      AND i.object_id = p.object_id
    i.object_id = OBJECT_ID('dbo.ClusteredIndexCrash')
    AND i.index_id IN ( 0, 1 ) ;

Got to love the confusion caused by columns being named with function names…

When that query above has finished, assuming SSMS hasn’t crashed from the effort of displaying “1000000 rows affected” (or whatever) 2k+ times…

Generating The Evil

Try running the insert one more time.

INSERT INTO dbo.ClusteredIndexCrash
SELECT TOP 1000000
    syscolumns c1 ,
    syscolumns c2 ,
    syscolumns c3 ;

And now (finally) we get the error of the beast:

Msg 666, Level 16, State 2, Line 21
The maximum system-generated unique value for a duplicate group was exceeded for index with partition ID <foo>Dropping and re-creating the index may resolve this; otherwise, use another clustering key.

What have we learned?

Apart from a table containing 2 billion tinyints takes up a lot of time and disk space?

Internally, the implementation of the uniquifier appears to be equivalent to an IDENTITY(1,1), just like your average DB designer would use to create an internal ID. However, because the range starts at 1, you lose half the range of numbers available to fit into this, limiting your uniquifier to 2.14-something billion rows. Again, just like an IDENTITY field, if you’ve deleted records from the middle of the table, you don’t automatically get to reuse those identities. Hence the suggestion that dropping and recreating the index may resolve this – by effectively removing the gaps and shoving everything back up again.

Rebuilding the index probably won’t have much effect, is just delaying the inevitable, and you should be rethinking your clustering strategy for this table.

Oh, and don’t do this on a production server. I mean, what were you thinking? Really? Intentionally generating massive tables with big errors in? Tsk.

Posted in SQLServerPedia Syndication | Tagged , , | 2 Comments