How to run a query in SSMS (F5, the selection, and the wrong database)
SSMS will run whatever is in the window, or whatever you highlighted. The other classic is running it against master because the dropdown was not on the company database.
Execute
- F5, or Ctrl+E, or the Execute button on the toolbar.
- Highlight a statement first if the file has more than one. SSMS runs the highlight, not the whole script.
- Results land in the grid. Messages is where row counts and errors go.
The database dropdown
Top left. If it says master and you query Orders, you get “Invalid object name”. Pick the database, or start the script with USE Harbour; (your real name, not ours).
USE Harbour;
GO
SELECT TOP (20) order_id, order_date, total_amount
FROM Orders
ORDER BY order_date DESC;
GO is an SSMS batch splitter. It is not a SQL Server keyword. Do not put it in a stored procedure or in an app. A blank line is enough between statements in a normal query.
Stop a runaway
The red square, or Alt+Break. If you forgot the WHERE on a big update, that is the button. We do not run updates on WorkSQL. At work, that is the one that matters.
Try it on Harbour & Co
Amy Nair (Finance Lead) needs this now: “Can I get a customer contact list? Just first name, last name and email.” Write the query, run it, send the results. Free.
Take the ticket →Learn it on a real ticket
Monday is free on WorkSQL. A colleague’s ticket lands, you write the T-SQL, we mark it. No videos. Five minutes.
Clock in free See Monday’s tickets