MSSQL 2012 修改所有表的架構Schame

jackchain發表於2014-05-03
ALTER SCHEMA [dbo] TRANSFER [sq_szswdjd].COM_Category


DECLARE @name VARCHAR(30);
declare csr1 cursor
      for 
      select 'Name' = name 
      from sysobjects 
      where USER_NAME(uid)='sq_szswdjd'
      order by name;

      open csr1       --迴圈讀取遊標記錄,執行系統儲存過程SP_ChangeObjectOwner修改物件所有者
      FETCH NEXT FROM csr1 INTO @name
      while (@@FETCH_STATUS=0)
      BEGIN
      SET @name='sq_szswdjd.'+@name
      PRINT 'ALTER SCHEMA [dbo] TRANSFER '+@name+';';
      fetch next from csr1 into @name
      END
      CLOSE csr1; 

 

相關文章