2012-10-22 55 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%'