'Difference between Sqlcmd and Invoke-Sqlcmd
I am trying to learn Sqlcmd utility in PowerShell to run SQL queries, specifically for database administration.
Using Version 15.0.1300.359 NT
But I got confused, what is the difference between Sqlcmd
and Invoke-Sqlcmd
?
Why is it this command works:
Invoke-Sqlcmd -ServerInstance myinstance -Database AdventureWorks2017 "select top 3 * from [Person].[BusinessEntity]"
And this one does not work:
Invoke-Sqlcmd -S myinstance -d AdventureWorks2017 "select top 3 * from [Person].[BusinessEntity]"
By querying help I can clearly see that I should be able using all those variables:
Solution 1:[1]
Invoke-SqlCmd
is one of the PowerShell cmdlets from theSqlServer
Modulesqlcmd
is a Microsoft Utility
If you're working on PowerShell scripting, I would recommend the use of the Module whenever possible. Invoke-SqlCmd
will output objects, which are definitely easier to manipulate.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 |