Sp将表从一个数据库移动到另一个存档数据库 [英] Sp which moves tables from one database to another archive database

查看:78
本文介绍了Sp将表从一个数据库移动到另一个存档数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要sp,它将表从一个数据库移动到另一个存档数据库,每3个月在T-sql中移动其记录或事务。请它非常紧急。谢谢你提前。



我尝试过的事情:



我有尝试各种方式bt没有帮助

I need sp which moves tables from one database to another archive database for every 3 months moving its records or transactions in T-sql. Please its very urgent. thanks ins advance.

What I have tried:

I have tried in all ways bt doesn't helpfull

推荐答案

This code copies all stored procedures in the Master database to the target database, you can copy just the procedures you like by filtering the query on procedure name.



@sql定义为nvarchar (max),@ Name是目标数据库




@sql is defined as nvarchar(max), @Name is the target database

DECLARE c CURSOR FOR 
   SELECT Definition
   FROM [ResiDazeMaster].[sys].[procedures] p
   INNER JOIN [ResiDazeMaster].sys.sql_modules m ON p.object_id = m.object_id

OPEN c

FETCH NEXT FROM c INTO @sql

WHILE @@FETCH_STATUS = 0 
BEGIN
   SET @sql = REPLACE(@sql,'''','''''')
   SET @sql = 'USE [' + @Name + ']; EXEC(''' + @sql + ''')'

   EXEC(@sql)

   FETCH NEXT FROM c INTO @sql
END             

CLOSE c
DEALLOCATE c


这篇关于Sp将表从一个数据库移动到另一个存档数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆