0

Is there a possibility to run many queries, that are not next to each other in the text editor in SSMS, at one time?

Assuming we have:

select * from tab1
select * from tab2
select * from tab3

the aim is to somehow mark only first and last selects and run them at the same time.

jarlh
  • 42,561
  • 8
  • 45
  • 63
I.P.
  • 300
  • 2
  • 16
  • comment off the unwanted query and execute – Squirrel Sep 27 '21 at 06:25
  • in this simple example that would work, but in more complex cases commenting out would be a pain.. – I.P. Sep 27 '21 at 06:30
  • I don't know how much pain it is to you to comments off a query hopefully [this](https://learn.microsoft.com/en-us/sql/ssms/tutorials/ssms-tricks?view=sql-server-ver15) will help you – Squirrel Sep 27 '21 at 06:55

2 Answers2

4

In SQL Server management you can just select the query you want to execute and press F5

EDIT: YOu can even select a part of a query to execute only that part. Example: SELECT * FROM <table> WHERE <your where> And you select just after the <table> then your query will be executed without the WHERE

enter image description here

EDIT: ctrl + alt + your select enter image description here

Niels Lucas
  • 739
  • 1
  • 12
  • 31
0

You can comment / uncomment a query easily by [un]commenting multiline comment start line. The second query is commented

select * from tab1;
/*
select * from tab2;
--*/
select * from tab3;

now it's uncommented

select * from tab1;
--/*
select * from tab2;
--*/
select * from tab3;
Serg
  • 22,285
  • 5
  • 21
  • 48
  • But if I have like 15 selects and want to run let's say every second one then it is inefficient. – I.P. Sep 27 '21 at 07:24
  • @I.P. .. My guess navigating over 7+ result sets in the Result pane is much more difficult problem. Can you explain why you want some 10+ queries in the same file? – Serg Sep 27 '21 at 07:36