zoukankan      html  css  js  c++  java
  • 把数据库里的表转到另一个数据库中(带数据,无依赖)

    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

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


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

  • 相关阅读:
    1245. Tree Diameter
    771. Jewels and Stones
    830. Positions of Large Groups
    648. Replace Words
    647. Palindromic Substrings
    435. Non-overlapping Intervals
    646. Maximum Length of Pair Chain
    645. Set Mismatch
    242. Valid Anagram
    438. Find All Anagrams in a String
  • 原文地址:https://www.cnblogs.com/bdf216/p/2651288.html
Copyright © 2011-2022 走看看