開發日誌:mySQL建立表時添加表和列的注釋,以及查看錶和列的注釋

來源:互聯網
上載者:User

1建立表時候添加預設注釋

CREATE TABLE groups(   gid INT PRIMARY KEY AUTO_INCREMENT COMMENT '設定主鍵自增',  gname VARCHAR(200) COMMENT '列注釋',) COMMENT='表注釋'

2修改已建立了的表注釋

ALTER TABLE groups COMMENT '修改表注釋'ALTER TABLE groups MODIFY COLUMN gname VARCHAR(100) COMMENT '修改列注釋'

 

3查看錶注釋 ( 我喜歡用第二個 )

SHOW  CREATE TABLE communication_group

SELECT table_name,table_comment FROM information_schema.tables  WHERE table_schema = '所在的db' AND table_name ='表名groups'

 

4查看列注釋 ( 我喜歡用第一個 )

SHOW FULL COLUMNS FROM groups-- 這個可以按條件的去搜尋某名字或某資料類型的列的資訊:例如SHOW FULL COLUMNS FROM tableName WHERE FIELD = 'add_time' OR TYPE LIKE '%date%' -- 查看tableName表中列名是add_time的或類型是date的列

SELECT  column_name, column_comment FROM information_schema.columns WHERE table_schema ='db'  AND table_name = 'groups' 



 

 

 

 

相關文章

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.