SQLSERVER 过滤所有权的代码
--数据库的名字,建议加上[]做名字包含
USE [0379]
DECLARE tnames_cursor CURSOR
FOR
SELECT TABLE_NAME
FROM INFORMATION_SCHEMA.TABLES
OPEN tnames_cursor
DECLARE @tablename sysname
--SET @tablename = 'authors'
FETCH NEXT FROM tnames_cursor INTO @tablename
WHILE (@@FETCH_STATUS <> -1)
BEGIN
IF (@@FETCH_STATUS <> -2)
BEGIN
--'源对象名称.'
SELECT @tablename = '0379_f.'+RTRIM(@tablename)
-- EXEC ('SELECT '''+'0379_f.' +@tablename + ''' = count(*) FROM ' + @tablename )
-- PRINT ' '
exec sp_changeobjectowner @tablename ,'dbo'
print ' '+@tablename
END
FETCH NEXT FROM tnames_cursor INTO @tablename
END
CLOSE tnames_cursor
DEALLOCATE tnames_cursor