如何在 MySQL Workbench 中执行多个 SQL 查询?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/11617209/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to execute multiple SQL queries in MySQL Workbench?
提问by user921020
I am using MySQL Workbench CE for Windows version 5.2.40.
我在 Windows 版本 5.2.40 上使用 MySQL Workbench CE。
I want to execute the following SQL queries together. However I can only execute the SQL queries by first executing the CREATE TABLE
query, and then executing the INSERT INTO
query and after that executing the SELECT
query.
我想一起执行以下 SQL 查询。但是,我只能通过先执行CREATE TABLE
查询,然后执行查询,然后再执行INSERT INTO
查询来执行SELECT
SQL 查询。
CREATE TABLE testTable(
Name VARCHAR(20),
Address VARCHAR(50),
Gender VARCHAR(10)
)
INSERT INTO testTable
VALUES
('Derp', 'ForeverAlone Street', 'Male'),
('Derpina', 'Whiterun Breezehome', 'Female')
Select * FROM testTable
So how do I execute the CREATE TABLE
, INSERT INTO
and the SELECT
queries by one click?
那么如何通过单击执行CREATE TABLE
,INSERT INTO
和SELECT
查询?
回答by Weijing Jay Lin
You could use Ctrl+Shift+Enterto run everything with semicolon end.
你可以使用Ctrl+ Shift+Enter运行与分号结束一切。
For Mac ?+shift+return
对于 Mac ?+ shift+return
回答by bfavaretto
Add a semicolon after each statement:
在每条语句后添加分号:
CREATE TABLE testTable(
Name VARCHAR(20),
Address VARCHAR(50),
Gender VARCHAR(10)
);
INSERT INTO testTable
VALUES
('Derp', 'ForeverAlone Street', 'Male'),
('Derpina', 'Whiterun Breezehome', 'Female');
SELECT * FROM testTable;