if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[copyallwaterdata]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[copyallwaterdata]
GO

SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO

CREATE proc copyallwaterdata
as

DECLARE @SQLString VARCHAR(3000)
DECLARE @TABLENAME VARCHAR(80)

if not exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[needsynctablelist]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
begin

CREATE TABLE [dbo].[needsynctablelist] (
 [tablename] [varchar] (100) COLLATE Chinese_PRC_CI_AS NOT NULL ,
 [sync] [bit] NULL
) ON [PRIMARY]

ALTER TABLE [dbo].[needsynctablelist] ADD
 CONSTRAINT [DF_needsynctablelist_sync] DEFAULT (1) FOR [sync],
 CONSTRAINT [PK_needsynctablelist] PRIMARY KEY  CLUSTERED
 (
  [tablename]
 )  ON [PRIMARY]
end

insert into needsynctablelist
select *,1 from openquery(water,'select name from dbo.sysobjects where OBJECTPROPERTY(id, ''IsUserTable'') = 1 and name !=''needsynctablelist''' )
where not exists(select 1 from needsynctablelist where name=tablename)

DECLARE water_Cursor CURSOR FOR
select tablename from needsynctablelist where sync=1

OPEN water_Cursor

FETCH NEXT FROM water_Cursor into @TABLENAME
WHILE @@FETCH_STATUS = 0
BEGIN
    SET @SQLString =N' if exists (select 1 from dbo.sysobjects  where name='''+@TABLENAME+''')  drop table  '+@TABLENAME+' select *  into '+@TABLENAME+' from  openquery(water,''select * from dbo.'+@TABLENAME+''')'

exec (@SQLString)

FETCH NEXT FROM water_Cursor  into @TABLENAME
END

CLOSE water_Cursor
DEALLOCATE water_Cursor

GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[queryBasecodes]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[queryBasecodes]
GO

SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO

CREATE proc   queryBasecodes
AS
begin
select * from dbo.COLLDT

end
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO

copyallwaterdata的更多相关文章

随机推荐

  1. SQLSERVER 表名数据库名作为变量 必须使用动态SQL(源自网络)

    动态语句基本语法: 1 :普通SQL语句可以用exec执行 Select * from tableName exec('select * from tableName') exec sp_execut ...

  2. block 反向传值回调

    /** *  block 反向传值回调 */ //在第二个控制器中 //   (1)声明block,在基类中已写好 //   (2)写好传值方法 //(1) typedef void (^Return ...

  3. 细聊分布式ID生成方法

    细聊分布式ID生成方法 https://mp.weixin.qq.com/s?__biz=MjM5ODYxMDA5OQ==&mid=403837240&idx=1&sn=ae9 ...

  4. Sublime插件库新成员基于APICloud快速开发跨平台App

    互联网时代强调用户体验,那什么是HTML5跨平台App开发者的编程体验?“不剥夺.不替换开发者喜欢的开发工具,就是人性化的用户体验”,APICloud给出了这样的答案! 重磅发布“多开发工具支持策略” ...

  5. [BS-09] UITabBarController简单介绍

    iOS开发UI篇—UITabBarController简单介绍 一.简单介绍 UITabBarController和UINavigationController类似,UITabBarControlle ...

  6. PHP PSR-1 基本代码规范(中文版)

    基本代码规范 本篇规范制定了代码基本元素的相关标准,以确保共享的PHP代码间具有较高程度的技术互通性. 关键词 “必须”("MUST").“一定不可/一定不能”("MUS ...

  7. C#实现根据IP 查找真实地址

    IPScanner.cs public class IPScanner { private byte[] data; Regex regex = new Regex(@"(((\d{1,2} ...

  8. 关于 0xCCCCCCCC

    http://xingyunbaijunwei.blog.163.com/blog/static/76538067201281793111474/ http://stackoverflow.com/q ...

  9. linux:lnmp环境搭建

    一.准备工作(把安装环境需要使用到的包都下载好) mysql(官网):http://dev.mysql.com/downloads/ php(官网):http://php.net/downloads. ...

  10. JAVA的String 类

    String类 1.String对象的初始化 由于String对象特别常用,所以在对String对象进行初始化时,Java提供了一种简化的特殊语法,格式如下: String s = “abc”; s ...