select name as'table_name', create_date AS'create_time', modify_date AS'update_time' from sys.tables where type ='U'
SQL Server(version 2005)读取表中的列信息
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
SELECT a.name as'column_name', b.name as'data_type', COLUMNPROPERTY(a.id,a.name,'PRECISION') as'data_length', COLUMNPROPERTY(a.id,a.name,'Scale') as'data_scale', casewhenexists(SELECT1FROM sysobjects where xtype='PK'and parent_obj=a.id and name in ( SELECT name FROM sysindexes WHERE indid in( SELECT indid FROM sysindexkeys WHERE id = a.id AND colid=a.colid))) then1else0endas'primary_key', COLUMNPROPERTY(a.id,a.name,'IsIdentity') as'autoincrement', a.isnullable as'nullable', e.text as'column_default', g.value as'column_comment' FROM syscolumns a leftjoin systypes b on a.xusertype=b.xusertype leftjoin sysobjects d on a.id=d.id and d.xtype='U' leftjoin syscomments e on a.cdefault=e.id leftjoin sys.extended_properties g on a.id=g.major_id and a.colid=g.minor_id where d.name='Role' orderby a.id, a.colorder
查询结果示例如下:
column_name
data_type
data_length
data_scale
primary_key
autoincrement
nullable
column_default
column_comment
id
int
10
0
1
1
0
name
nvarchar
50
0
0
0
名称
description
nvarchar
300
0
0
1
描述
MySQL(version 5.7)读取数据库中的表信息
1 2 3 4 5 6 7 8
SELECT TABLE_NAME AS'table_name', TABLE_ROWS AS'table_rows', CREATE_TIME AS'create_time', UPDATE_TIME AS'update_time' FROM information_schema.TABLES WHERE TABLE_SCHEMA ='test'