篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了powershell MS SQL Powershell使用SQLPS创建视图相关的知识,希望对你有一定的参考价值。
# Set the path context to the local, default instance
# of SQL Server and get a reference to AdventureWorks2014
CD \sql\localhost\default\databases
$db = get-item AdventureWorks2014
# Define a View object variable by supplying the parent database,
# view name and schema in the constructor.
$myview = New-Object -TypeName Microsoft.SqlServer.Management.SMO.View `
-argumentlist $db, "Test_View", "Sales"
# Set the TextHeader and TextBody property to define the view.
$myview.TextHeader = "CREATE VIEW [Sales].[Test_View] AS"
$myview.TextBody =
"
SELECT h.SalesOrderID, d.OrderQty
FROM Sales.SalesOrderHeader AS h
INNER JOIN Sales.SalesOrderDetail AS d
ON h.SalesOrderID = d.SalesOrderID
"
# Create the view on the instance of SQL Server.
$myview.Create()
# Remove the view.
$myview.Drop();
以上是关于powershell MS SQL Powershell使用SQLPS创建视图的主要内容,如果未能解决你的问题,请参考以下文章