r/SQLServer • u/TravellingBeard 1 • Jun 19 '26
Discussion What's something you recently learned about SQL server you're embarrassed you didn't know, even though you are pretty experienced?
I did not know that if you:
Select multiple .SQL files and right click->copy as path
Open up a query window in SSMS and set it to SQLcmd mode
Copy the files from step 1 and preface each one with :r, for example: :r "C:\scripts\script1.sql"
And finally execute this query, you can run a bunch of scripts at once
I sometimes fiddle around with PowerShell and invoke-sqlcmd, but this method is useful. I don't often use the SQLCMD mode in SSMS, but I found this nice.
48
Upvotes
•
u/AutoModerator Jun 19 '26
After your question has been solved /u/TravellingBeard, please reply to the helpful user's comment with the phrase "Solution verified".
This will not only award a point to the contributor for their assistance but also update the post's flair to "Solved".
I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.
9
u/ipreferanothername Jun 19 '26
OP if you are fiddling in powershell get the dbatools module - it has a bazillion helpful things in it.
9
u/mgcox2 Jun 19 '26
That you can use ordinals instead of column names in the order by clause, e.g., "order by 1, 2".
13
u/kwellendorff Jun 19 '26
Holding ALT while dragging down with cursor to manage multiple rows.
Using object explorer details to sort by created date on SPs.
Making query shortcut CONTROL+3 = SELECT TOP 100* FROM. Then simply highlight a table name in a script and press CTL+3
Drag and drop column names from Object Explorer
Missing index reports from performance dashboard report
20
u/Northbank75 Jun 19 '26
I just watched some idiot at work copy a bunch of data in excel and then paste it into the table via the ‘edit top x rows’ view ….
13
u/agiamba Jun 19 '26
Not me, but I had several coworkers think you had to run ssms from the DB server for years. They thought ssms and SQL server were part of the same install
6
u/silmelumenn Jun 19 '26
I learned that using OPENQUERY solves just half of the problem with linked servers. It will execute on remote server, but local server still sees it as black box, so to have a performant query joining two tables from 2 servers it's best to first copy data from remote to local table, and then do the join.
5
u/gmen385 Jun 19 '26
You can update a view (automatically, without setting up an instead-of trigger) as long as it's a simple select from one table
4
u/imk Jun 19 '26
I have been working with MSSQL for about 25 years. The first time that I ever used dynamic SQL to create an insert statement was about 5 years ago. It had never come up.
4
u/PhaicGnus Jun 19 '26
Don’t mind me, just here taking notes…
3
u/CaromaPilot Jun 20 '26
Right click the tab of your working query and pin 📌 it to keep it as the left-most tab and prevents it from getting mixed up with the others
2
u/reggatta Jun 19 '26
I just learned from Claude about using synonyms for views that you might be naming with version numbers. So the synonym might be ‘trackingNumbers’ but the actual view is ‘TrackingNumbers_2_1’. You can then change the underlying view, update the synonym, and then other views or SQL can reference the synonym.
2
u/hello_josh Jun 20 '26
You can turn the scrollbar in SSMS editor into a minimap so you can easily scroll to different parts of large sql scripts visually.
https://blog.greglow.com/2025/06/16/ssms-tips-and-tricks-2-8-scroll-bar-map-mode/
2
u/denvergentleman2 Jun 22 '26
That count(*) has a row limit.
1
u/Mission_Pirate_4150 Jun 21 '26
How to join one row of a massive table. I can’t believe that had never come up before, but here I am. And it worked perfectly.
1
u/Stunning-Task1721 Jun 23 '26
Handy with Ctrl-T context format the output
1
u/Full_Marketing_4877 Jun 29 '26
I found out this one the hard way years back. Taking the database offline and deleting the database does not remove the files in that operation. You have to have it online to delete. You can run an "orphaned database files" script but that's extra work.
I thought I was dumb but a very well known consultant didn't know it at the time either. (2012 or so)
2
u/[deleted] Jun 19 '26
[removed] — view removed comment