MySQL变量错误

MySQL变量错误,mysql,sql,variables,Mysql,Sql,Variables,以下是不起作用的代码: DECLARE @myTable TABLE (colName nvarchar(500), tableName nvarchar(500)) insert into @myTable SELECT c.COLUMN_NAME AS colName, c.TABLE_NAME AS tableName, TABLE_SCHEMA tableSchema FROM information_schema.COLUMNS as c WHERE c.COLUMN_NAME

以下是不起作用的代码:

DECLARE @myTable TABLE (colName nvarchar(500), tableName nvarchar(500))

insert into @myTable

SELECT c.COLUMN_NAME AS colName, c.TABLE_NAME AS tableName, TABLE_SCHEMA tableSchema 
FROM information_schema.COLUMNS as c 
WHERE c.COLUMN_NAME like '%password%'

select * from @myTable
我的错误是:

[错误]脚本行:1-7-------------------------- 您的SQL语法有错误;检查与您的MySQL服务器版本对应的手册,以了解在“DECLARE@myTable TABLE”(colName-nvarchar(500),tableName-nvarchar(500))附近使用的正确语法

有人有什么想法吗?

你可以试试这个

  insert into myTable  

 SELECT c.COLUMN_NAME AS colName, c.TABLE_NAME AS tableName 
 FROM information_schema.COLUMNS as c 
 WHERE c.COLUMN_NAME like '%password%'

Mysql有点不同:

create table myTable (colName nvarchar(500), tableName nvarchar(500));

insert into myTable (colName, tableName)
    SELECT COLUMN_NAME, TABLE_NAME
    FROM information_schema.COLUMNS
    WHERE COLUMN_NAME like '%password%';

select * from myTable;

在使用SQL Server或MySQL时,请尽量避免使用@或写“@myTable”?在MySQL中不能使用“@”声明临时表。它应该是
创建临时表..
查看
create table myTable (colName nvarchar(500), tableName nvarchar(500));

insert into myTable (colName, tableName)
    SELECT COLUMN_NAME, TABLE_NAME
    FROM information_schema.COLUMNS
    WHERE COLUMN_NAME like '%password%';

select * from myTable;