since.2006  

JDBC里提供的DatabaseMetaData类提供的方法可以方便的完成这事,但有时候数据库因权限问题自己不能完全控制,用这个类会有问题。

同样用SQL也可以完成这个问题:

-- 列用户所有表:
select name as tn from sysobjects where type='U'

-- 列某个表所有字段及类型,是否允许空等:
select a.colid as id, b.name as tab_name ,
a.name as COLUMN_NAME,
c.name as DATA_TYPE,
a.length as COLUMN_SIZE,
a.prec as length,
a.scale,
case isnull(a.status,0) when 0 then 'NOT NULL' ELSE 'NULL' END AS NULLABLE 
from syscolumns a, sysobjects b, systypes c 
where a.id = b.id and a.usertype = c.usertype and b.name= 'TargetTable' 
order by a.colid
标签:

Posted by hee at 10:03 AM | Permalink | 评论(0) | WEB

请输入名称
请输入邮件地址

 

    请输入邮件地址