简体   繁体   English

在MySQL中显示列别名

[英]SHOW COLUMNS alias in MySQL

I want to make an alias(as in bash) for the following MySQL query: 我想为以下MySQL查询创建一个别名(如在bash中):

SHOW COLUMNS FROM table WHERE Field != 'col_name' AND Field != 'col_name';

I read something about views but it seems that I need a SELECT query to use them. 我读了一些关于视图的内容,但似乎我需要一个SELECT查询才能使用它们。

I want to type only something like: showcols in the MySQL prompt and in the background the above query to be executed, is that possible? 我想在MySQL提示符中只输入类似: showcols ,并在后台执行上面要执行的查询,这可能吗?

PS: I cannot use DESCRIBE because of the length of some enum fields in the table. PS:由于表中某些枚举字段的长度,我无法使用DESCRIBE

You can replace the show columns with a select from the information_schema database. 您可以使用information_schema数据库中的select替换show columns

SELECT column_name FROM INFORMATION_SCHEMA.`columns` 
WHERE column_name not IN ('col1','col2');

Now you can create a view based on this select: 现在,您可以根据此选择创建view

CREATE VIEW as SELECT ......

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM