2012-10-22 41 views
0

这里是不起作用的代码:的MySQL变量错误

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服务器版本正确的语法使用近“声明@myTable TABLE(COLNAME为nvarchar(500),表名为nvarchar(500))

insert ' at line 1 

任何人有任何想法的手册?

+0

尽量避免@或写\'@myTable \' –

+1

您正在使用SQL Server或MySQL? – Omesh

+0

@Omesh我正在使用MySQL。 – Alias

回答

1

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; 
0

你可以试试这个

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%'