Read our blogs, tips and tutorials
Try our exercises or test your skills
Watch our tutorial videos or shorts
Take a self-paced course
Read our recent newsletters
License our courseware
Book expert consultancy
Buy our publications
Get help in using our site
538 attributed reviews in the last 3 years
Refreshingly small course sizes
Outstandingly good courseware
Whizzy online classrooms
Wise Owl trainers only (no freelancers)
Almost no cancellations
We have genuine integrity
We invoice after training
Review 30+ years of Wise Owl
View our top 100 clients
Search our website
We also send out useful tips in a monthly email newsletter ...
What is SQLCMD mode, and how can you use it? Part three of a three-part series of blogs |
---|
You can use SQLCMD mode to parameterise the connection, database name, table name and select columns for a query - and much more besides, as this blog explains.
|
In this blog
This page is intended to give you ideas!
You can temporarily connect to a database to run commands within it:
The output shows that SSMS automatically disconnects from the database when the script finishes.
If you want to run the same script in different databases, you can now do this easily:
Here I've gone a bit mad, and have parameterised my connection, schema, database and stored procedure name!
You could change the values assigned to the variables below to get different results from your query:
This query will show the title and release year of each film, sorted by descending order of the release year.
You can run operating system commands by preceding them with !!. For example:
This command lists out the files in a folder.
Use the :out command to send the results from your query to a file:
A simple query which will send its output to the given text file.
It's a good idea to switch from grid to text format first, to make the output easier to read:
Click on this tool to switch from grid to text output.
For the query above, here's what you might get:
I should probably have included the command SET NOCOUNT ON to suppress the message showing the number of rows affected.
There are (inevitably) lots of sites which go into much more detail about things which you can do in SQLCMD mode, but most of them are more geared towards SQL Server administrators.
Parts of this blog |
---|
|
Some other pages relevant to the above blogs include:
Kingsmoor House
Railway Street
GLOSSOP
SK13 2AA
Landmark Offices
99 Bishopsgate
LONDON
EC2M 3XD
Holiday Inn
25 Aytoun Street
MANCHESTER
M1 3AE
© Wise Owl Business Solutions Ltd 2024. All Rights Reserved.