MYSQL查詢表的字段和表名

2021-08-07 13:28:17 字數 942 閱讀 2069

2、查詢mysql是否包含某張表:

1)、drop

table

ifexists

tablename;

2)、做乙個sql查詢,比如:select

*from tablename/

select

count(*) from

tablename,如果返回值為空,則表不存在。

3)、查詢:show tables like

table1,判斷返回值。如:

if(mysql_num_rows(mysql_query("show tables like

'".$table."

'")==

1)

else

注:個人覺得第三種方法最好。

3、查詢mysql某張表的字段屬性

select  column_name, column_comment  from information_schema.columns  where table_name =

'crm_table';

ci框架寫法:

$this

->db->

select('

column_name, column_comment')

->

where('

table_name

', $table_name)

->

from('

information_schema.columns');

$query

= $this->db->

get();

return $query->result_object();

根據字段內容查詢表名

儲存指定資料庫中的表名 create table t id int identity 1,1 t name varchar 100 null,rc int null 儲存指定表的所有列名 create table t c id int identity 1,1 t c varchar 100 nul...

MySQL中 如何查詢表名中包含某字段的表

select table name from information schema.tables where table schema tablename and table type base table and table name like copy information schema 是m...

MySQL中 如何查詢表名中包含某字段的表

select table name from information schema.tables where table schema tablename and table type base table and table name like copy information schema 是m...