Monday, September 23, 2013

Getting Started with SQL Server SMO (Server Management Objects)

A few commands to get you started exploring SQL Server SMO:
#load SMO into your Powershell session
[reflection.assembly]::LoadWithPartialName("Microsoft.SqlServer.Smo")
#instantiate the server object against the instance of your choice
$sqlServer = new-object ("Microsoft.SqlServer.Management.Smo.Server") "(local)"
#see what the object can do
$sqlServer | get-member
#get a list of linked server entries on the server
$sqlServer.LinkedServers | format-table

Sunday, September 22, 2013

Bulk importing CSV to SQL Server on a remote command line

Simple bulk insert from the command line to import a csv
SQLCMD -E -S myserver\myinstance -Q "BULK INSERT myDatabase.dbo.myTable FROM 'C:\rdbms_local_path\myFile.csv' WITH(FIELDTERMINATOR=',', ROWTERMINATOR='\n')"