显示 table 中不包含主键的所有列
Display ALL the columns from table that doesn`t contain the Primary Keys
我有这个查询要做。
显示 table 中名为 'somehow' 的所有非主键的列。
这就是我尝试获取与主键 ID 列不同的列 headers 的方式:
SELECT cols.column_name
FROM information_schema.table_constraints t
JOIN information_schema.key_column_usage k
USING(constraint_name,table_schema,table_name)
WHERE t.constraint_type <> 'PRIMARY KEY'
AND t.table_schema='mydb'
AND t.table_name='somehow'
我收到 SQL 错误后出现问题。我做错了什么?
更新:
SELECT k.column_name
FROM information_schema.table_constraints t
JOIN information_schema.key_column_usage k
USING(constraint_name,table_schema,table_name)
WHERE t.constraint_type <> 'PRIMARY'
AND t.table_schema='mydb'
AND t.table_name='somehow'
这准确地显示了我不想得到的结果(主键)我需要显示其他所有内容:(
所有 table 列都可以在 MySQL 的系统 table columns
中找到。它的 column_key
字段包含 'PRI' 以防列是主键的一部分。因此:
select column_name
from information_schema.columns
where table_schema = 'mydb'
and table_name = 'somehow'
and column_key <> 'PRI';
我有这个查询要做。 显示 table 中名为 'somehow' 的所有非主键的列。
这就是我尝试获取与主键 ID 列不同的列 headers 的方式:
SELECT cols.column_name
FROM information_schema.table_constraints t
JOIN information_schema.key_column_usage k
USING(constraint_name,table_schema,table_name)
WHERE t.constraint_type <> 'PRIMARY KEY'
AND t.table_schema='mydb'
AND t.table_name='somehow'
我收到 SQL 错误后出现问题。我做错了什么?
更新:
SELECT k.column_name
FROM information_schema.table_constraints t
JOIN information_schema.key_column_usage k
USING(constraint_name,table_schema,table_name)
WHERE t.constraint_type <> 'PRIMARY'
AND t.table_schema='mydb'
AND t.table_name='somehow'
这准确地显示了我不想得到的结果(主键)我需要显示其他所有内容:(
所有 table 列都可以在 MySQL 的系统 table columns
中找到。它的 column_key
字段包含 'PRI' 以防列是主键的一部分。因此:
select column_name
from information_schema.columns
where table_schema = 'mydb'
and table_name = 'somehow'
and column_key <> 'PRI';