Saturday, November 03, 2012

Differences between isql, osql, sqlcmd and Invoke-Sqlcmd

What's the difference between isql, osql, sqlcmd, and Invoke-SqlCmd?
My GreatGreatGrandFather, Elijah Fincher, playing the part of "isql"
All four of these tools let you interact with SqlServer via the command line.
I'm not a big database guy, so I thought I was cool a few years ago moving to osql from isql. Wrong. The cool kids are on Invoke-SqlCmd
What's the difference:
isql - the grandfather, last used in SQLServer 2000. You should only be using this if you are working for some government agency.
osql - the father, introduced in SqlServer 2000, will probably be phased out soon. Use this if you work for a large corporation like GM.
sqlcmd - new kid, introduced in SqlServer 2005, used in current SqlServer insta
lls. This is what everybody else should be using.
Invoke-SqlCmd - the new cool kid, used inside PowerShell. Use this if you are really cool and have installed linux on your old computers at home.


Example using sqlcmd:
sqlcmd -S MyServerName\SqlExpress -E -Q "CREATE DATABASE Movies"
sqlcmd -S MyServerName\SqlExpress -d Movies -E -i "C:\workfiles\Movies_CreateTables.sql"

The "-E" option says to use trusted identity;
"-Q" the query to execute
"-d" the database to access
"-i" the command input file

No comments: