各種數據庫經過sql查詢表字段的註釋

若是要寫代碼生成器,確定會須要查詢表字段與字段的 註釋。否則生成的代碼還須要不少手動的操做。但因爲各種 數據庫的系統表結構不同,所以針對不一樣類型的查詢sql也是不同的。

oracle:
SELECT A.TABLE_NAME,A.COMMENTS,B.COLUMN_NAME,B.COMMENTS FROM USER_TAB_COMMENTS A,USER_COL_COMMENTS B WHERE A.TABLE_NAME=B.TABLE_NAME and a.table_name=' SYS_TIME' sqlserver2000: select sc.name as columnName,sp.value as remarks from sysobjects so left outer join syscolumns sc on so.id = sc.id left outer join sysproperties sp on sc.id = sp.id and sc.colid = sp.smallid where so.type = 'u' and so.name='$tableName$' order by so.id, sc.colorder sqlserver2005: SELECT columnName=A.NAME, remarks=ISNULL(G.[VALUE], ' ') FROM SYSCOLUMNS A LEFT JOIN SYSTYPES B ON A.XUSERTYPE=B.XUSERTYPE INNER JOIN SYSOBJECTS D ON A.ID=D.ID AND D.XTYPE= 'U ' AND D.NAME <> 'DTPROPERTIES ' LEFT JOIN SYSCOMMENTS E ON A.CDEFAULT=E.ID LEFT JOIN sys.extended_properties G ON A.ID=G.major_id AND A.COLID=G.minor_id LEFT JOIN sys.extended_properties F ON D.ID=F.major_id AND F.minor_id=0 where D.NAME='$tableName$' ORDER BY A.ID,A.COLORDER sqlserver2008: SELECT a.name columnName, ISNULL(g.value,'') AS remarks FROM syscolumns a LEFT JOIN systypes b ON a.xtype=b.xusertype INNER JOIN sysobjects d ON a.id=d.id AND d.xtype='U' AND d.name <>'dtproperties' LEFT JOIN syscomments e ON a.cdefault=e.id LEFT JOIN dbo.sysproperties g ON d.id=g.id AND a.colid = g.smallid WHERE d.name='$tableName$' ORDER BY a.id,a.colorder mysql: select table_name,table_comment from information_schema.tables where table_schema = 'db' and table_name ='tablename'
相關文章
相關標籤/搜索