从 MySQL 信息架构中的 table 选择列名时出错
Error when selecting colum names from table in MySQL information schema
我正在尝试从 MySQL 中的特定 table 获取列名列表。我是 运行:
SELECT column_name
FROM information_schema.columns
WHERE table_name = `test 2.2`
AND table_schema = test
数据库名为 test
,table 名称为 test 2.2
,其余语法看起来正确。但是我一直收到错误
Error Code: 1054. Unknown column 'test 2.2' in 'where clause'
有没有其他方法可以做我想做的事情and/or我该如何解决这个错误?
对字符串使用引号而不是反引号
SELECT column_name
FROM information_schema.columns
WHERE table_name = 'test 2.2'
AND table_schema = 'test'
SELECT column_name
FROM information_schema.columns
WHERE table_name = "test 2.2"
AND table_schema = "test"
或者,你为什么不直接描述 table。
desc `test 2.2`;
对象名称(在本例中为 table 名称)作为字符串文字存储在信息模式中,因此应使用单引号 ('
) 查询它们:
SELECT column_name
FROM information_schema.columns
WHERE table_name = 'test 2.2' AND table_schema = 'test'
-- Here -----------^--------^--------------------^----^
我正在尝试从 MySQL 中的特定 table 获取列名列表。我是 运行:
SELECT column_name
FROM information_schema.columns
WHERE table_name = `test 2.2`
AND table_schema = test
数据库名为 test
,table 名称为 test 2.2
,其余语法看起来正确。但是我一直收到错误
Error Code: 1054. Unknown column 'test 2.2' in 'where clause'
有没有其他方法可以做我想做的事情and/or我该如何解决这个错误?
对字符串使用引号而不是反引号
SELECT column_name
FROM information_schema.columns
WHERE table_name = 'test 2.2'
AND table_schema = 'test'
SELECT column_name
FROM information_schema.columns
WHERE table_name = "test 2.2"
AND table_schema = "test"
或者,你为什么不直接描述 table。
desc `test 2.2`;
对象名称(在本例中为 table 名称)作为字符串文字存储在信息模式中,因此应使用单引号 ('
) 查询它们:
SELECT column_name
FROM information_schema.columns
WHERE table_name = 'test 2.2' AND table_schema = 'test'
-- Here -----------^--------^--------------------^----^