-
-
Save zommarin/1236809 to your computer and use it in GitHub Desktop.
Find non-dbo tables, views and procedures [SQL Server]
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- | |
-- Select the tables, views and stored procedures that are not in the [dbo] schema | |
-- | |
-- Useful when double checking that prople has not run scripts with the wrong user | |
-- for databases that have everything in the [dbo] schema. | |
-- | |
SELECT 'Table' AS [Type] , | |
'[' + s.name + '].[' + t.name + ']' AS [Name] | |
FROM sys.tables AS t | |
INNER JOIN sys.schemas AS s ON t.schema_id = s.schema_id | |
WHERE s.name <> 'dbo' | |
UNION ALL | |
SELECT 'SProc' , | |
'[' + s.name + '].[' + p.name + ']' | |
FROM sys.procedures AS p | |
INNER JOIN sys.schemas AS s ON p.schema_id = s.schema_id | |
WHERE s.name <> 'dbo' | |
UNION ALL | |
SELECT 'View' , | |
'[' + s.name + '].[' + v.name + ']' | |
FROM sys.views AS v | |
INNER JOIN sys.schemas AS s ON v.schema_id = s.schema_id | |
WHERE s.name <> 'dbo' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment