October 7, 2015 at 7:47 am
I'm trying to list everything (tables, view, procedures, functions, etc.) that was created by users in a database.
The query which seems to eliminate the most SQL system type objects is shown below.
SELECT *
FROM sys.all_objects SAO
WHERE SAO.is_ms_shipped = 0
order by SAO.type, SAO.name
This still includes some non-user created objects, like the below. See the attachment for details.
fn_diagramobjects
sp_alterdiagram
sp_creatediagram
How can I get rid of these type of objects without filtering on SAO.name LIKE...
October 7, 2015 at 7:58 am
tnpich (10/7/2015)
I'm trying to list everything (tables, view, procedures, functions, etc.) that was created by users in a database.The query which seems to eliminate the most SQL system type objects is shown below.
SELECT *
FROM sys.all_objects SAO
WHERE SAO.is_ms_shipped = 0
order by SAO.type, SAO.name
This still includes some non-user created objects, like the below. See the attachment for details.
fn_diagramobjects
sp_alterdiagram
sp_creatediagram
How can I get rid of these type of objects without filtering on
SAO.name LIKE...
I don't believe you can just based on the data in the table. You'll need to either do a NOT LIKE or you'll need to take the list of items that you've already identified and store them in an "exclusion" table or temporary table and use something like a WHERE NOT IN or an exclusive outer join.
--Jeff Moden
Change is inevitable... Change for the better is not.
October 7, 2015 at 8:02 am
nm, ignore
Gail Shaw
Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability
October 7, 2015 at 8:17 am
Thanks.
Examining the object names that were included, they all contain diagram so a NOT LIKE '%diagram%' seems to work.
October 7, 2015 at 8:29 am
tnpich (10/7/2015)
This still includes some non-user created objects, like the below. See the attachment for details.
fn_diagramobjects
sp_alterdiagram
sp_creatediagram
How can I get rid of these type of objects without filtering on
SAO.name LIKE...
These objects are not part of the SQL Server ship catalog. These are created the first time a user creates a database diagram (a pop up menu advises that extra items are required before a diagram may be created 😉 )
By querying for is_ms_shipped you are pulling objects that were not present in the default deployment of the product, not necessarily user created objects
-----------------------------------------------------------------------------------------------------------
"Ya can't make an omelette without breaking just a few eggs" 😉
Viewing 5 posts - 1 through 4 (of 4 total)
You must be logged in to reply to this topic. Login to reply