Category: Cloud & Virtualization

Identity cache in sql server 2012 to 2016

Problem :

 From SQL Server 2012 to 2016 version, when SQL Server instance is restarted, then table’s Identity value is jumped and the actual jumped value depends on identity column data type. If it is integer (int) data type, then jump value is 1000 and if big integer (bigint), then jump value is 10000.

Highlighted Points :

Microsoft declares it is a feature rather than a bug and in many scenarios it would be helpful.

  • Microsoft states this is not a bug and does not intend to provide a fix it. It will not be corrected in Patch fixes or service packs.
  • If too many tables contain identity column to your database and all contain existing values, then it is better to go for solution 2. Because it is a very simple solution and its scope is server wise.
  • If you want to create a new database and you need auto generated number field, then you can use solution 1, that means use sequence value to a column instead of auto Identity value.

·         Trace Flag: 272

Function: Disabling the identity cache. It prevents identity gap after restarting SQL Server instance, critical for columns with identity and tinyint and smallint data types.





  • Using Sequence
  • Register -t272
  • Upgrade to Sql server 2017


1.Using Sequence


First, we need to remove Identity column from tables. Then create a sequence without cache feature and insert number from that sequence.


The following is the code sample:











insert into MyTestTable values(NEXT VALUE FOR Id_Sequence, ‘Mr.ravi’);

insert into MyTestTable values(NEXT VALUE FOR Id_Sequence, ‘Mr.suresh’);







Perfmon logman export and import

  1. logman export -n "Server Manager Performance Monitor" -xml SMPM.xml
    1. Open up the generated XML file and remove the entire section List of IDs then save the file.
    2.  Open an elevated command prompt where the data collector set is missing and import the XML file:
  2. logman import -n "Server Manager Performance Monitor" -xml SMPM.xml
  3. logman start "Server Manager Performance Monitor"

What gets backed up in a System State Backup?

This article will help you understand the detail information of each component when we backup under System State:

· Active Directory DC Database file (ntds.dit)
· Boot and System protected files
· COM+ Class registration database
· Registry info
· SYSVOL folder and its files
· IIS metabase
· Cluster service info (on cluster node only)








How to open the firewall port for SQL Server on Windows Server 2008

The script that is discussed in this section opens the firewall ports for SQL Server.

To create the script, follow these steps:

  1. Start Notepad.
  2. Copy and paste the following code into Notepad:
    netsh advfirewall firewall add rule name="Open Port 80" dir=in action=allow protocol=TCP localport=80
    @echo =========  SQL Server Ports  ===================
    @echo Enabling SQLServer default instance port 1433
    netsh advfirewall firewall add rule name="SQL Server" dir=in action=allow protocol=TCP localport=1433
    @echo Enabling Dedicated Admin Connection port 1434
    netsh advfirewall firewall add rule name="SQL Admin Connection" dir=in action=allow protocol=TCP localport=1434
    @echo Enabling Conventional SQL Server Service Broker port 4022
    netsh advfirewall firewall add rule name="SQL Service Broker" dir=in action=allow protocol=TCP localport=4022
    @echo Enabling Transact SQL/RPC port 135
    netsh advfirewall firewall add rule name="SQL Debugger/RPC" dir=in action=allow protocol=TCP localport=135
    @echo =========  Analysis Services Ports  ==============
    @echo Enabling SSAS Default Instance port 2383
    netsh advfirewall firewall add rule name="Analysis Services" dir=in action=allow protocol=TCP localport=2383
    @echo Enabling SQL Server Browser Service port 2382
    netsh advfirewall firewall add rule name="SQL Browser" dir=in action=allow protocol=TCP localport=2382
    @echo =========  Misc Applications  ==============
    @echo Enabling HTTP port 80
    netsh advfirewall firewall add rule name="HTTP" dir=in action=allow protocol=TCP localport=80
    @echo Enabling SSL port 443
    netsh advfirewall firewall add rule name="SSL" dir=in action=allow protocol=TCP localport=443
    @echo Enabling port for SQL Server Browser Service's 'Browse' Button
    netsh advfirewall firewall add rule name="SQL Browser" dir=in action=allow protocol=UDP localport=1434
    @echo Allowing multicast broadcast response on UDP (Browser Service Enumerations OK)
    netsh firewall set multicastbroadcastresponse ENABLE
  3. Save the file as a .txt file by using the following name: OpenSqlServerPort.txt
  4. Rename the OpenSqlServerPort.txt file to the following: OpenSqlServerPort.bat

Before you run the OpenSqlServerPort.bat script, you must copy the script to the computer that has the firewall and then run the script on that computer. To run the script, follow these steps:

  1. Click Start, click Run, type cmd, and then click OK.
  2. At the command prompt, use the cd command to move to the folder in which you saved the OpenSqlServerPort.bat file.
  3. To run the OpenSqlServerPort.bat script, type OpenSqlServerPort.bat at the command prompt, and then press Enter.



Restoring 1000’s of SQL Server Databases Using PowerShell

Excellent job

Simon Osborne's SQL Blog

Recently I have been working with a client who has a production SQL Server instance that has ~2.5k databases on it. They are in the process of moving to a new SQL Serve cluster and are reviewing their other non-production environments too.

One of their major pain points at the is their pre-production refresh process, this involves restoring all 2.5k databases to a pre-production SQL Server instance. The current process involves retrieving backups from Iron Mountain and performing file system restores. They are looking to streamline this process and automate it as much as possible. Most of the process could be achieved using T-SQL, but there are extra file system tasks that need to be performed which are more easily achieved using PowerShell. PowerShell 4.0 brought us the Restore-SQLDatabase cmdlet and so it was worth evaluating this to see if I could encapsulate the entire thing in one script. It’s…

View original post 382 more words