SQLServer:
[sql] view plain copy
-- get all non-system databases
select name from master..sysdatabases where name not in('master', 'model', 'msdb', 'tempdb', 'northwind', 'pubs' , 'ReportServer', 'ReportServerTempDB')
-- get the detailed field information of a table
select c.name,t.name,c.prec,p.value from syscolumns c
inner join systypes t on c.xtype= t.xtype
inner join sysobjects o on c.id= o.id
inner join sys.extended_properties p on c.id = p.major_id and c.colid = p.minor_id
where o.xtype='u'and t.status=0 and o .name='table name'
-- get all table information
select * from sysobjects where XType='U'
-- field information, associated table id=syscolumns. id
select * from syscolumns
-- comment information, associated field information major_id=syscolumns.id
select * from sys.extended_properties
-- primary key auto-increment information, associated id = syscolumns.id
select * from sysindexkeys
select * from sysindexes
-- table details (field name, type, length, whether it is a primary key, whether it is an identifier, allowing null , comment)
select a.name N'field name', b.name N'type',
COLUMNPROPERTY(a.id,a.name,'PRECISION') as N'length',
(case when (select count(*) from sysobjects
where (name in (select name from sysindexes
where (id = a.id) AND (indid in (select indid from sysindexkeys
where (id = a.id) AND (colid in (select colid from syscolumns
where (id = a .id) AND (name = a.name))))))) AND (xtype = 'PK'))>0 then 'PK' else '' end) N'primary key',
(case when COLUMNPROPERTY( a.id ,a.name,'IsIdentity' )=1 then 'identity'else '' end) N'identity',
(case when a.isnullable=1 then 'true'else 'false' end) N'允许空',
isnull(g.[value],'') AS N'注释'
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 sys.extended_properties g
on a.id=g.major_id AND a.colid = g.minor_id
where d.name='表名'
order by a.colorder -- the table information of the current user is stored in the two views respectively SELECT * FROM user_tab_columns -- get all the columns, column information SELECT * FROM user_tables -- get all the tables of the current user [sql] view plain copy
oracle:
--user_tab_columns: Details of the columns in the table, but there is no identification of whether it is the primary key
--user_cons_columns: Constraint view.
SELECT utc.COLUMN_NAME as column name, ucc.COLUMN_NAME AS primary key, utc.DATA_TYPE as column type, utc.DATA_LENGTH as type length, utc.NULLABLE as nullable or not FROM user_tab_columns utc
left join user_cons_columns ucc on utc.TABLE_NAME = ucc. TABLE_NAME
where POSITION=1 AND ucc.TABLE_NAME = 'your table name'
ORDER by utc.COLUMN_ID
--user_col_comments:comments
SQLServer, Oracle get database, table, field in table, type, comment
Guess you like
Origin http://43.154.161.224:23101/article/api/json?id=326221024&siteId=291194637
Recommended
Ranking