sql语句中的information_schema.COLUMNS 是啥意思呢

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了sql语句中的information_schema.COLUMNS 是啥意思呢相关的知识,希望对你有一定的参考价值。

select count(*) from information_schema.COLUMNS where table_name='student_info'

information_schema 是mysql数据库中的系统库,里面存放了,用户所创建的数据库和表的信息
这条sql是用来查询student_info 有多少列

mysql> use information_schema;
mysql> show tables;
可以看到下面有很多表,分别用来存放各种用户创建的信息
CHARACTER_SETS
COLLATIONS
COLLATION_CHARACTER_SET_APPLICABILITY
COLUMNS
COLUMN_PRIVILEGES
ENGINES
EVENTS
FILES
GLOBAL_STATUS
GLOBAL_VARIABLES
KEY_COLUMN_USAGE
PARTITIONS
PLUGINS
PROCESSLIST
REFERENTIAL_CONSTRAINTS
ROUTINES
SCHEMATA
SCHEMA_PRIVILEGES
SESSION_STATUS
SESSION_VARIABLES
STATISTICS
TABLES
TABLE_CONSTRAINTS
TABLE_PRIVILEGES
TRIGGERS
USER_PRIVILEGES
VIEWS
FALCON_RECORD_CACHE_SUMMARY
FALCON_SYSTEM_MEMORY_DETAIL
FALCON_SYSTEM_MEMORY_SUMMARY
FALCON_SYNCOBJECTS
FALCON_RECORD_CACHE_DETAIL
FALCON_TRANSACTION_SUMMARY
FALCON_DATABASE_IO
FALCON_TRANSACTIONS
FALCON_SERIAL_LOG
参考技术A

“列”信息啊。

select count(*) from information_schema.COLUMNS where table_name='student_info'

意思就是计算表student_info的列数

本回答被提问者和网友采纳
参考技术B information_schema.COLUMNS

数据库名称information_schema
表名称COLUMNS
参考技术C information_schema.COLUMNS 这东西的意思是 information_schema库的cloumns表
where后面是该表的过滤信息,用来具体定位的。

查看Greenplum集群中的创建的类型

查看Greenplum集群中的创建的类型

SELECT (current_database())::information_schema.sql_identifier AS udt_catalog, (nc.nspname)::information_schema.sql_identifier AS udt_schema, (c.relname)::information_schema.sql_identifier AS udt_name, (a.attname)::information_schema.sql_identifier AS attribute_name, (a.attnum)::information_schema.cardinal_number AS ordinal_position, (pg_get_expr(ad.adbin, ad.adrelid))::information_schema.character_data AS attribute_default, (CASE WHEN (a.attnotnull OR ((t.typtype = 'd'::"char") AND t.typnotnull)) THEN 'NO'::text ELSE 'YES'::text END)::information_schema.character_data AS is_nullable, (CASE WHEN ((t.typelem <> (0)::oid) AND (t.typlen = (-1))) THEN 'ARRAY'::text WHEN (nt.nspname = 'pg_catalog'::name) THEN format_type(a.atttypid, NULL::integer) ELSE 'USER-DEFINED'::text END)::information_schema.character_data AS data_type, (information_schema._pg_char_max_length(information_schema._pg_truetypid(a.*, t.*), information_schema._pg_truetypmod(a.*, t.*)))::information_schema.cardinal_number AS character_maximum_length, (information_schema._pg_char_octet_length(information_schema._pg_truetypid(a.*, t.*), information_schema._pg_truetypmod(a.*, t.*)))::information_schema.cardinal_number AS character_octet_length, (NULL::character varying)::information_schema.sql_identifier AS character_set_catalog, (NULL::character varying)::information_schema.sql_identifier AS character_set_schema, (NULL::character varying)::information_schema.sql_identifier AS character_set_name, (NULL::character varying)::information_schema.sql_identifier AS collation_catalog, (NULL::character varying)::information_schema.sql_identifier AS collation_schema, (NULL::character varying)::information_schema.sql_identifier AS collation_name, (information_schema._pg_numeric_precision(information_schema._pg_truetypid(a.*, t.*), information_schema._pg_truetypmod(a.*, t.*)))::information_schema.cardinal_number AS numeric_precision, (information_schema._pg_numeric_precision_radix(information_schema._pg_truetypid(a.*, t.*), information_schema._pg_truetypmod(a.*, t.*)))::information_schema.cardinal_number AS numeric_precision_radix, (information_schema._pg_numeric_scale(information_schema._pg_truetypid(a.*, t.*), information_schema._pg_truetypmod(a.*, t.*)))::information_schema.cardinal_number AS numeric_scale, (information_schema._pg_datetime_precision(information_schema._pg_truetypid(a.*, t.*), information_schema._pg_truetypmod(a.*, t.*)))::information_schema.cardinal_number AS datetime_precision, (NULL::character varying)::information_schema.character_data AS interval_type, (NULL::character varying)::information_schema.character_data AS interval_precision, (current_database())::information_schema.sql_identifier AS attribute_udt_catalog, (nt.nspname)::information_schema.sql_identifier AS attribute_udt_schema, (t.typname)::information_schema.sql_identifier AS attribute_udt_name, (NULL::character varying)::information_schema.sql_identifier AS scope_catalog, (NULL::character varying)::information_schema.sql_identifier AS scope_schema, (NULL::character varying)::information_schema.sql_identifier AS scope_name, (NULL::integer)::information_schema.cardinal_number AS maximum_cardinality, (a.attnum)::information_schema.sql_identifier AS dtd_identifier, ('NO'::character varying)::information_schema.character_data AS is_derived_reference_attribute FROM (pg_attribute a LEFT JOIN pg_attrdef ad ON (((a.attrelid = ad.adrelid) AND (a.attnum = ad.adnum)))), pg_class c, pg_namespace nc, (pg_type t JOIN pg_namespace nt ON ((t.typnamespace = nt.oid))) WHERE ((((((a.attrelid = c.oid) AND (a.atttypid = t.oid)) AND (nc.oid = c.relnamespace)) AND (a.attnum > 0)) AND (NOT a.attisdropped)) AND (c.relkind = 'c'::"char"));

以上是关于sql语句中的information_schema.COLUMNS 是啥意思呢的主要内容,如果未能解决你的问题,请参考以下文章

转:怎么用Sql语句获取一个数据库中的所有表的名字

SQL语句

研究旧项目, 常用 sql 语句

拒绝访问 MariaDB 中的 information_schema

关于mysql中information_schema.tables

查看Greenplum集群中的创建的类型