把数据库里的表转到另一个数据库中(带数据,无依赖)

set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
go

-- =============================================
-- Author:        <Author,,YU>
-- Create date: <Create Date,,>
-- Description:    <Description,,> 将原数据库里的表转到现在的数据库中
-- =============================================
CREATE PROCEDURE  XXX
AS
BEGIN

DECLARE @TableCount int
DECLARE @TableName varchar(50)
DECLARE @TableID int

SET NOCOUNT ON; 
declare jcom_cursor cursor for

select [Name],[id] from [原数据库名称].[dbo].sysobjects where xtype='u' and status>=0  
and [Name] not in ( select [Name] from [现在的数据库名称].[dbo].sysobjects where xtype='u' and status>=0 ) 
order by id 

open jcom_cursor
fetch next from jcom_cursor into @TableName,@TableID
while(@@fetch_status=0)
begin
    
declare @selectsql varchar(200)

    set @selectsql = 'SELECT * into [现在的数据库名称].[dbo].['+@TableName+']  FROM [原数据库名称].[dbo].['+@TableName+']'
    exec (@selectsql) 
    --select @sql

fetch next from jcom_cursor into @TableName,@TableID
end
close jcom_cursor
deallocate jcom_cursor
END

表和数据都可以转过去,但是表之间的依赖关系带不过去


哪位朋友会‘把视图、存储过程、触发器传到另一个库’的方法,麻烦告知一下。

posted @ 2012-08-22 18:10  bdf216  阅读(318)  评论(0编辑  收藏  举报