Posts

Showing posts with the label identity

Choosing SEQUENCE instead of IDENTITY? Watch your step.

Image
On the nice sunny day getting this error message can be really frustrating. In fact, it is frustrating on any day. Especially if you are doing something really simple. Most of you at this moment yell at your monitor “DDL Trigger!!!!” . Yes. I have a simple DDL trigger for auditing purposes. If you use the script below for the auditing table, any DDL statement will get pretty red notification to discard the results. CREATE DATABASE  TestDB ; USE  TestDB ; CREATE  SEQUENCE  GetNextNumber  AS  int  START  WITH  1 INCREMENT  BY  1 ; CREATE  TABLE  dbo . TestAuditTable (         ID             int  NOT  NULL  DEFAULT  NEXT  VALUE  FOR  GetNextNumber  PRIMARY  KEY ,         ChangeDate     datetime ,  ...

Replication fun: setting NFR on all objects

If you ever tried to set up replication on the large environment with numerous servers, hundreds of databases then you, for sure, spend some time searching/writing scripts to set flag NOT FOR REPLICATION on thousands of identities, constraints and triggers. I want to share here my scripts and I hope it will save some readers hours of headache. Feel free to use them, just add comments below - there is nothing better than feedback. Here we go. ******************************************************************************** 1. Identities. The resutset is a list of identity columns on all tables in all databases where NOT FOR REPLICATION option is not set and fixing script: DROP TABLE #IdentityNFR CREATE TABLE #IdentityNFR (ServerName varchar(250), Dbname varchar(250),TableName varchar(250), IdentityColName varchar(250), IsNFR varchar(10),FixingScript varchar(4000)) exec sp_MSforeachdb ' IF ''?'' NOT IN (''tempdb'',''master'',''mo...