如何在MySQL Workbench中执行多个SQL查询?

时间:2021-10-21 23:11:09

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查询。但是,我只能执行SQL查询,首先执行CREATE TABLE查询,然后执行INSERT INTO查询,然后执行SELECT查询。

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?

那么我如何执行创建表、插入和选择查询呢?

2 个解决方案

#1


20  

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;

#2


20  

You could use Ctrl+Shift+Enter to run everything with semicolon end.

您可以使用Ctrl+Shift+Enter以分号结尾运行所有内容。

For Mac +shift+return

对于Mac⌘+ shift +回报

#1


20  

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;

#2


20  

You could use Ctrl+Shift+Enter to run everything with semicolon end.

您可以使用Ctrl+Shift+Enter以分号结尾运行所有内容。

For Mac +shift+return

对于Mac⌘+ shift +回报