CREATE TABLE #local temp table (
User_id int,
User_name varchar (50),
User_address varchar (150)
) ;
ER_PARSE_ERROR: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'INT, User_name VARCHAR (50), User_address VARCHAR (150) )' at line 2
CREATE TABLE ##new global temp table (
User_id int,
User_name varchar (50),
User_address varchar (150)
);
ER_PARSE_ERROR: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'INT, User_name VARCHAR (50), User_address VARCHAR (150) )' at line 2
SELECT* INTO newtable FROM employee;
ER_SP_UNDECLARED_VAR: Undeclared variable: newtable
最佳答案
要在 MySQL 中创建临时表,您可以使用:
CREATE TEMPORARY TABLE local (
User_id int,
User_name varchar(50),
User_address varchar(150)
) ;
临时表以“#”开头的约定是特定于 SQL Server(和 Sybase)的。在大多数数据库中,您可以使用 temporary
关键字来实现此目的。
要从现有表创建另一个表,请使用CRAETE TABLE AS
。这是 SQL 的重要组成部分,因此该操作有时被称为 CTAS。 SQL Server(和 Sybase)再次使用 INTO
语法。在许多数据库中,INTO
用于变量赋值。
关于mysql - 我是 sql 新手,我正在使用 mysql,我不能使用复制表并创建本地临时表和全局临时表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58233476/