Showing posts with label Aruba. Show all posts
Showing posts with label Aruba. Show all posts

31 August 2011

Cambiare lo schema di tutte le tabelle

1) Lanciare questo script:
DECLARE @schemaFROM AS nvarchar(200); SET @schemaFROM = 'MSSql49479'
DECLARE @schemaTO AS nvarchar(200); SET @schemaTO = 'dbo'
 
DECLARE tabcurs CURSOR FOR
SELECT @schemaFROM + '.' + '[' +  [name] + ']'
FROM sysobjects
WHERE xtype IN ('u', 'p', 'fn', 'fs', 'ft', 'tf', 'v', 'if')
 
OPEN tabcurs
DECLARE @tname NVARCHAR(517)
FETCH NEXT FROM tabcurs INTO @tname
 
WHILE @@fetch_status = 0
    BEGIN
        PRINT ''
        PRINT 'Changing ' + @tname
        EXEC sp_changeobjectowner @tname, @schemaTO

        FETCH NEXT FROM tabcurs INTO @tname
    END
 
CLOSE tabcurs
DEALLOCATE tabcurs
 
PRINT '
Done.'

2) Rifare gli script per View, Stored Procedure, Funzioni, ecc: al loro interno potrebbe essere presente il vecchio schema!!

Utile per i db ripristinati da aruba...


Testato su Sql2005, Sql2008 Express, Sql2008R2
Trovato qui.