Filter DBO schema/owner only - dont show SYS Stored Procedures

244 views Asked by At

I am scripting all the Stored Procedures in a Database, via SMO. It is now returning Stored Procedures from both DBO and SYS owner/schema's

How do I filter it to only show SP's from DBO please:

            StringCollection spScripts = AdventureWorks.Script(scriptOptions);
            foreach (StoredProcedure mySP in AdventureWorks.StoredProcedures)
            {
                foreach (string script in spScripts)
                    sw.WriteLine(script);

                /* Generating CREATE TABLE command */
                spScripts = mySP.Script();
                foreach (string script in spScripts)
                    sw.WriteLine(script);
            }
1

There are 1 answers

1
LInsoDeTeh On BEST ANSWER

The StoredProcedure class has a Schema property, you could use this to filter.

if (mySP.Schema == "dbo")

Not sure right now, if StoredProcedures collection implements the right interfaces, but maybe you can even filter it directly on the StoredProcedures object via LINQ

AdventureWorks.StoredProcedures.Where(p => p.Schema == "dbo")