Update docs (#200)

This is a documentation-only update so automerging.  Please review the commit if there are any follow-ups requested.

* Update .gitignore for docfx genertated files

* Update documenation (part 1)

* Update docs and add some samples

* More doc updates
This commit is contained in:
Karl Burtram
2016-12-20 15:52:46 -08:00
committed by GitHub
parent 1e59166147
commit 4184eae8a1
26 changed files with 2529 additions and 5 deletions

View File

@@ -0,0 +1,28 @@
<#
This code example shows how to create an XML schema by using the XmlSchemaCollection object.
#>
#DLL location needs to be specified
$pathtodll = ""
Add-Type -Path "$pathtodll\Microsoft.SqlServer.Smo.dll"
Add-Type -Path "$pathtodll\Microsoft.SqlServer.ConnectionInfo.dll"
#Connection context need to be specified
$srv = New-Object Microsoft.SqlServer.Management.Smo.Server()
$srv.ConnectionContext.LoginSecure = $false
$srv.ConnectionContext.ServerInstance = "instance_name"
$srv.ConnectionContext.Login = "user_id"
$srv.ConnectionContext.Password = "pwd"
#Reference the master database
$db = $srv.Databases["master"]
#Create a new schema collection
$xsc = New-Object -TypeName Microsoft.SqlServer.Management.SMO.XmlSchemaCollection -argumentlist $db,"SampleCollection"
#Add the xml
$dq = '"' # the double quote character
$xsc.Text = "<schema xmlns=" + $dq + "http://www.w3.org/2001/XMLSchema" + $dq + " xmlns:ns=" + $dq + "http://ns" + $dq + "><element name=" + $dq + "e" + $dq + " type=" + $dq + "dateTime" + $dq + "/></schema>"
#Create the XML schema collection on the instance of SQL Server.
$xsc.Create

View File

@@ -0,0 +1,27 @@
<#
This script demonstrates iterations through the rows and display collation details for a remote or local instance of SQL Server.
#>
#DLL location needs to be specified
$pathtodll = ""
Add-Type -Path "$pathtodll\Microsoft.SqlServer.Smo.dll"
Add-Type -Path "$pathtodll\Microsoft.SqlServer.ConnectionInfo.dll"
#Connection context need to be specified
$srv = New-Object Microsoft.SqlServer.Management.Smo.Server()
$srv.ConnectionContext.LoginSecure = $false
$srv.ConnectionContext.ServerInstance = "instance_name"
$srv.ConnectionContext.Login = "user_id"
$srv.ConnectionContext.Password = "pwd"
$datatable = $srv.EnumCollations()
Foreach ($row in $datatable.Rows)
{
Write-Host "============================================"
Foreach ($column in $row.Table.Columns)
{
Write-Host $column.ColumnName "=" $row[$column].ToString()
}
}

View File

@@ -0,0 +1,58 @@
<#
This code example creates a table that has several columns with different types and purposes. The code also provides examples of how to create an identity field, how to create a primary key, and how to alter table properties.
#>
#DLL location needs to be specified
$pathtodll = ""
Add-Type -Path "$pathtodll\Microsoft.SqlServer.Smo.dll"
Add-Type -Path "$pathtodll\Microsoft.SqlServer.ConnectionInfo.dll"
#Connection context need to be specified
$srv = New-Object Microsoft.SqlServer.Management.Smo.Server()
$srv.ConnectionContext.LoginSecure = $false
$srv.ConnectionContext.ServerInstance = "instance_name"
$srv.ConnectionContext.Login = "user_id"
$srv.ConnectionContext.Password = "pwd"
#And the database object corresponding to master.
$db = $srv.Databases["master"]
#Create a SMO Table
$tb = New-Object -TypeName Microsoft.SqlServer.Management.SMO.Table -argumentlist $db, "Test_Table"
#Add various columns to the table.
$Type = [Microsoft.SqlServer.Management.SMO.DataType]::NChar(50)
$col1 = New-Object -TypeName Microsoft.SqlServer.Management.SMO.Column -argumentlist $tb,"Name", $Type
$col1.Collation = "Latin1_General_CI_AS"
$col1.Nullable = $true
$tb.Columns.Add($col1)
$Type = [Microsoft.SqlServer.Management.SMO.DataType]::Int
$col2 = New-Object -TypeName Microsoft.SqlServer.Management.SMO.Column -argumentlist $tb,"ID", $Type
$col2.Identity = $true
$col2.IdentitySeed = 1
$col2.IdentityIncrement = 1
$tb.Columns.Add($col2)
$Type = [Microsoft.SqlServer.Management.SMO.DataType]::Real
$col3 = New-Object -TypeName Microsoft.SqlServer.Management.SMO.Column -argumentlist $tb,"Value", $Type
$tb.Columns.Add($col3)
$Type = [Microsoft.SqlServer.Management.SMO.DataType]::DateTime
$col4 = New-Object -TypeName Microsoft.SqlServer.Management.SMO.Column -argumentlist $tb,"Date", $Type
$col4.Nullable = $false
$tb.Columns.Add($col4)
#Create the table
$tb.Create()
$Type = [Microsoft.SqlServer.Management.SMO.DataType]::DateTime
$col5 = New-Object -TypeName Microsoft.SqlServer.Management.SMO.Column -argumentlist $tb,"ExpiryDate", $Type
$col5.Nullable = $false
$tb.Columns.Add($col5)
#Run the Alter method to make the change on the instance of SQL Server.
$tb.Alter()
#Remove the table from the database.
$tb.Drop()