looking for a brokerage account or IRA... click here Add To Favorites
return to index 

Execute SQL From Command Line

You can execute SQL from the command line using SQLCMD. It will allow you to execute any command and interact with your database. If you wish to execute a command and automatically exit back to the prompt, simply supply a -Q in your statement. To see all command options, type sqlcmd /?.

e.g.
sqlcmd -S . -E -Q "DELETE FROM GlobalNode..DataSegment"

Bulk Command Processing can also be included in a batch file and can insert data.

e.g.
bcp GlobalNode..DataSegment in c:\ds.txt -S . -T -c

In the two example command lines, you can see that I delete all rows from my DataSegment and then repopulated them with data is ds.txt. The database is on my localhost (.).

Additional Interesting Articles

SQL Server Reporting Services- Custom Chart Colors
Looping Through a SQL Result in C#
AJAX Javascript Functions
C# DataSet v DataReader
SQL Server Database Recovery Mode
Block File Leechers Using PHP

©2008 AndrewKimball.com