Getting Started with Adobe After Effects - Part 6: Motion Blur


Upload Image Close it
Select File

My experiences and references in SQL server
Browse by Tags · View All
SQL Server 14
#SQLServer 14
SQL Scripts 13
#TSQL 6
TSQL 6
SQL Serevr - Issues and Resolutions 3
SQL Server - Best Practises 3
SQL server - Misconceptions 3
SQL server - Statistics 2
SQL Server - Wait stats and Queues 2

Archive · View All
October 2011 8
March 2011 7
April 2011 4
May 2011 3
November 2011 3
December 2010 3
December 2011 2
June 2008 2
February 2011 2
February 2012 1

SQLZealot's Blog

Find out the referenced tables of a table that to be added as articles in replication

Dec 8 2011 12:48AM by Latheesh NK   

In replication, we need to add objects as articles to replicate the data to different server.The important point is here that if we have any reference(foreign keys) associated with the articles(tables choosen to be replicated), then we need to consider the parant table also to add as article, Or the replication might fail due to the foreign key enforcement at subscriber.

Few days back, one of my collegue DBA asked me to script out to find the related tables of a table that to be added as article as part of replication set up. So that he can add those tables as articles to prevent the breaking of foreign key enforcement in replication.

Here, I would like to share the script that I used.

Declare @Table_Name Varchar(50)
Set @Table_Name = 'table_name'
Create Table #Temp_Tables (Row int identity(1,1),To_Referenced Varchar(100), TableName Varchar(100),Evaluated Int)

Insert Into #Temp_Tables Select @Table_Name,NULL,0

Declare @TName Varchar(100),@RCount int,@Inc Int
Set @Inc  = 0
Select @RCount= COUNT(1) From #Temp_Tables Where Evaluated =0
While @RCount>0
Begin
    Set @TName =  (Select  Top 1 To_Referenced From #Temp_Tables Where Evaluated = 0)
	      
	Insert Into #Temp_Tables
	Select OBJECT_NAME(referenced_object_id),OBJECT_NAME(Parent_Object_Id),0 From sys.foreign_key_columns Where OBJECT_NAME(Parent_Object_Id)=@TName

	Update #Temp_Tables Set Evaluated=1 Where To_Referenced = @TNAme 

	Select @RCount= COUNT(1) From #Temp_Tables Where Evaluated =0

End


Select * From #Temp_Tables Order by Row asc


Drop Table #Temp_Tables

As always, if you have any better idea/method or nay comments, I request you to share.


Republished from SQL - My Best Friend [58 clicks].  Read the original version here [32134 clicks].

Latheesh NK
55 · 3% · 1115
1
 
0
Lifesaver
 
0
Refreshed
 
0
Learned
 
0
Incorrect



Submit

Your Comment


Sign Up or Login to post a comment.

"Find out the referenced tables of a table that to be added as articles in replication" rated 5 out of 5 by 1 readers
Find out the referenced tables of a table that to be added as articles in replication , 5.0 out of 5 based on 1 ratings
    Copyright © Rivera Informatic Private Ltd Contact us      Privacy Policy      Terms of use      Report Abuse      Advertising      [ZULU1097]