What it does: This script polls multiple databases to find gaps in a Primary Key ID in a table common to multiple databases. It is useful not only for finding gaps in PK's, but also for finding a single PK or group of PK's that are available in all databases. This is handy for being able to create a single script for adding new records that can run on multiple databases that have a common purpose and help maintain standardization between them. It is very convenient that it can be run from a local server and pull and gather data from remote servers, including linked servers to other database types.
Use: The script is parameterized so it can be easily edited to run against different tables and PK's. Edit the variables at the top to specify the table and primary key id names. There is also a variable for defining the minimum gap size to look for. This script is designed for four databases: 2 running separate SQL Servers and two running on separate Sybase servers (accessed via a linked server). Note, that for the SQL Server instances, I found that I neeed to re-declare the variables inside the dynamic SQL query. This section should be edited to fit your situation. I suppose the next best thing would be to install as a parameterized stored procedure.
Kudos: With the help that I gleaned from Alexander Kozak's analysis of finding "islands and gaps in sequential numbers" (ref: http://msdn.microsoft.com/en-us/library/aa175780(v=sql.80).aspx), I am able to greatly simplify the task of finding gaps and groups of available PK's in tables across multiple systems allowing me to write "one-size-fits-all" scripts.