Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in SQL by (20.3k points)

I'm reading a book about SQL. In that book there's the term Ad Hoc Query, which I don't understand.

What exactly is an ad hoc query?

1 Answer

0 votes
by (40.7k points)

Ad hoc is a Latin word which means "for this purpose". You can call it as "on the fly" query, or the "just so" query. 

It's one kind of SQL query, that you just loosely type out where you need it.

var newSqlQuery = "SELECT * FROM table WHERE id = " + myId;

The above query is an entirely different query that occurs each time the line of code is executed, depending on the value of myId. 

A predefined query such as a Stored Procedure is the antonym of an ad hoc query. Here, you have created the single query for the entire generalized purpose of selecting from that table (say), and pass the ID as a variable.

Related questions

0 votes
1 answer
0 votes
1 answer
asked Feb 3, 2020 in BI by Vaibhav Ameta (17.6k points)
0 votes
0 answers
asked Jun 24, 2021 in SQL by Harsh (1.5k points)
0 votes
1 answer
asked Dec 4, 2020 in SQL by Appu (6.1k points)
0 votes
1 answer
asked Oct 19, 2020 in SQL by dev_sk2311 (45k points)

Browse Categories

...