Unexpected behavior from Get-SqlTable

Aug 31, 2010 at 9:33 PM

Hello,

Currently Get-SqlTable does this:

        foreach ($table in $database.Tables)
        {
            if ($table.IsSystemObject -eq $false -and ($table.name -like "*$name*" -or $name.Contains($table.name)))
            {
            #Return Table Object

...and will return an array of tables (if more than one exists).

This seems to me to run contrary to what one would expect in Powershell for a parameter called -name. Instead of this, how about adding a -pattern parameter that lets you get an arbitrary number of tables back, and changing the -name parameter to give you the one table you specify (or $null, or toss an exception or whatever, if it doesn't exist)? It seems to me that this would be more consistent with how powershell parameters usually work.

Performance-wise, looping through all the tables is expensive if you don't need to do it (especially on pathologically large databases...like PeopleSoft ones with tens of thousands of tables).

Also, how about adding a -Schema parameter?

Thoughts?

I can work around the current implementation by using Database.Tables.Item("name", "schema"), but I like to use SQLPSX :-)

Thanks for your consideration!

Coordinator
Sep 1, 2010 at 1:48 AM

@FNoltie You make several ery good points and thanks for posting feedback. I'll add this to work item for a future release. One thing I would change is use the standard parameters name, include, exclude. Name would use the syntax you've listed above and exclude and include could take a pattern and be modeled after the same parameters in get-childitem.

 

Coordinator
Sep 1, 2010 at 1:51 AM
This discussion has been copied to a work item. Click here to go to the work item and continue the discussion.
Coordinator
Sep 1, 2010 at 1:51 AM
This discussion has been copied to a work item. Click here to go to the work item and continue the discussion.
Sep 1, 2010 at 2:34 PM

Sounds great. Thank you Chad. :-)

Coordinator
Nov 6, 2010 at 8:27 PM

This has been fixed in the 2.3 release