---
title: "T-SQL - Sync Table"
author: "xxd"
date: "2009-03-03T00:23:33Z"
tags: []
slug: "t-sql-sync-table"
draft: false
lastmod: "2009-03-03T00:23:33Z"
id: 460597
url: "https://xxd.iteye.com/blog/460597"
---

/* --1---Create table---- \*/

> create table Sync\_Table  
> (\[id] \[int] IDENTITY(1,1) NOT FOR REPLICATION NOT NULL,  
> \[Table\_Name] \[varchar](100) COLLATE Chinese\_PRC\_CI\_AS NULL,  
> CONSTRAINT \[PK\_Sync\_Table] PRIMARY KEY CLUSTERED  
> (  
> \[id] ASC  
> )WITH (IGNORE\_DUP\_KEY = OFF) ON \[PRIMARY]  
> ) ON \[PRIMARY]

/* --2---Insert data---- \*/

> insert into Sync\_Table (\[Table\_Name]) values ('CMS\_Member')  
> select * from Sync\_Table

/* --3---SP---- \*/

> --exec sp\_Sync\_Table  
> create proc sp\_Sync\_Table  
> as  
> begin  
> declare @number\_of\_table int  
> select @number\_of\_table = count(\*) from Sync\_Table  
> print @number\_of\_table  
> declare @table\_name \[varchar](100)  
> declare @sql nvarchar (max)  
> declare @n int  
> set @n = 1  
> while @n
> 
> ![](https://blogger.googleusercontent.com/tracker/4722768579593920709-1282636057757797321?l=xxd79.blogspot.com)