在MySQL下運行完下面這個建表語句後。 如何從數據字典中,檢索出這個表的字段的相關信息?
DROP TABLE IF EXISTS test_table;
CREATE TABLE test_table(
Test_ID int NOT NULL AUTO_INCREMENT PRIMARY KEY COMMENT ‘主鍵(自增長)’,
Test_Key varchar(10) NOT NULL COMMENT ‘種類’,
Test_Value varchar(20) NOT NULL COMMENT ’數值’,
Test_Type int NOT NULL COMMENT ‘內部類型’,
Test_BelongTo int COMMENT ‘從屬關系’ ,
Test_Grade int DEFAULT 1 COMMENT ’等級’,
Test_Remark varchar(50) COMMENT ‘備注’,
Test_Visible bit DEFAULT 1 COMMENT ‘是否可見’
)
COMMENT = ‘測試表’;
答案是:
SELECT
column_name AS `列名`,
data_type AS `數據類型`,
character_maximum_length AS `字符長度`,
numeric_precision AS `數字長度`,
numeric_scale AS `小數位數`,
is_nullable AS `是否允許非空`,
CASE WHEN extra = ‘auto_increment’
THEN 1 ELSE 0 END AS `是否自增`,
column_default AS `默認值`,
column_comment AS `備注`
FROM
Information_schema.columns
WHERE
table_Name=’test_table’;