Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to run multiple SQL queries?

Tags:

sql

plsql

I have a create table query, an update query ,and then drop table query. I need to run these three queries in one shot. What is the best way to do this?

Example
1st Query: Create table A.
2nd Query: Update value in table A
3rd Query: Drop table A.

Instead of running these three queries one by one, I want to run them in on go either by PLSQL or some other way. Please help.

like image 896
Vikram Singh Avatar asked Jun 02 '11 09:06

Vikram Singh


People also ask

Can I run multiple SQL queries at once?

You can include multiple SQL statements on the SQL query panel. The exceptions are CALL and CREATE PROCEDURE statements. These statements must be used alone in a query.

How do I run multiple SQL queries in MySQL?

How to run Multiple SQL Queries in MySQL Workbench explains how you can run multiple statements in single query window by separating them with semicolon ; You can have different types of statements such as delete, update or insert in single query window and all can be executed with single click.

How do you run two queries at the same time?

Simply put three queries one after the other in a . sql file, with semi-colons after each statement, then execute it as a script (either on a SQL*Plus prompt using @scriptname. sql or in TOAD/SQL Developer [or equivalent] using its script execution function).

How do I run multiple queries in SQL Developer?

In SqlDeveloper preferences: Tools > Preferences > Database > Worksheet check the option for New Worksheet to use unshared connction . This will allow you to execute multiple queries at the same time, each in each tab.


2 Answers

Put the 3 queries following each other separated by a semi-colon:

SELECT * 
FROM table_to_be_selected; 
DROP TABLE the table_to_be_dropped; 
TRUNCATE TABLE table_to_be_truncated;

You can concatenate these queries in a string and execute that string.

Another way is this solution.

like image 199
DaMainBoss Avatar answered Oct 13 '22 06:10

DaMainBoss


Simply put three queries one after the other in a .sql file, with semi-colons after each statement, then execute it as a script (either on a SQL*Plus prompt using @scriptname.sql or in TOAD/SQL Developer [or equivalent] using its script execution function).

like image 24
Datajam Avatar answered Oct 13 '22 07:10

Datajam