Quantcast
Channel: CodeSection,代码区,SQL Server(mssql)数据库 技术分享 - CodeSec
Viewing all articles
Browse latest Browse all 3160

Querying My Named Instance in PoSh #SQLNewBlogger

$
0
0

A nother post for me that is simple and hopefully serves as an example for people trying to get blogging as #SQLNewBlogger s.

I was looking at some sample code the other day and it looked like this.

cd sqlserver:\sql\localhost\default\databases

This allows you to browse the list of databases on your local instance. However, this is for a default instance, which I don’t have on this host. How can I get to a named instance? Usually I connect as .\SQL2016, so where does that fit in PowerShell?

The format you see above is for the SQLServer provider, which is provided as part of the SQLServer PoSh module (or SQLPS if you haven’t adopted the new cmdlets).

If I start at the SQLServer:\ node, I see this:


Querying My Named Instance in PoSh #SQLNewBlogger

Let’s drop into the SQL node and see that.


Querying My Named Instance in PoSh #SQLNewBlogger

At this point, I see my localhost and my local computer name. These are really the same thing. We can see that by querying each of them.


Querying My Named Instance in PoSh #SQLNewBlogger

In my case, I like to type fewer characters, so I’ll look at the Plato node. If I change here, I can also change to an instance, as shown here.


Querying My Named Instance in PoSh #SQLNewBlogger

Now I can see the databases by changing to that path and getting the directory.


Querying My Named Instance in PoSh #SQLNewBlogger

Thus, we can see that to query an instance, we use this path:

SQLServer:\SQL\Host\instance

If you want to use the default instance, then use “default”.

A simple query path, but one that some people might wonder about, substituting the named instance for localhost, and not realizing that “Default” means just the default instance.


Viewing all articles
Browse latest Browse all 3160

Trending Articles