mirror of
https://github.com/ckaczor/sqltoolsservice.git
synced 2026-01-14 09:59:48 -05:00
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:
28
docs/samples/smo/PowerShellScript/createxmlshema.ps1
Normal file
28
docs/samples/smo/PowerShellScript/createxmlshema.ps1
Normal 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
|
||||
27
docs/samples/smo/PowerShellScript/dbiteration.ps1
Normal file
27
docs/samples/smo/PowerShellScript/dbiteration.ps1
Normal 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()
|
||||
}
|
||||
}
|
||||
58
docs/samples/smo/PowerShellScript/managetable.ps1
Normal file
58
docs/samples/smo/PowerShellScript/managetable.ps1
Normal 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()
|
||||
Reference in New Issue
Block a user