当前位置:数据库 > DB2 >>

如何获得Db2的表结构?

我想获取数据库的表结构信息,分别要取得表名,注释,是否为空,是否为主健等信息,示例(SQL Server) /* Author:Conis CreateDate:16:21 2007-08-09 Description: 获取指定表的所有字段属性 Remark: 1.如果你不精通SQL代码,请不要随便修改,以免程序不能正常运行。 ` 2.字段名称不能修改,否则会导致程序错误 3.如果你一定要修改,建议在修改之前做好备份 ======================================================================= ¦ CopyRight(C)Conis YI ¦ ¦ URL:http://www.conis.cn ¦ ¦ E-Mail:Conis.yi@gmail.com ¦ ======================================================================= */ DECLARE @Version VARCHAR(100) DECLARE @SysTable VARCHAR(50) DECLARE @sql NVARCHAR(2000) DECLARE @SmallID VARCHAR(10) DECLARE @MajorID VARCHAR(10) SET @Version = @@VERSION IF CHARINDEX('9.00', @Version) = 0 --2005 BEGIN SET @SysTable = 'sysproperties' SET @SmallID = 'smallid' SET @MajorID = 'id' END ELSE --2000 BEGIN SET @SysTable = 'sys.extended_properties' SET @SmallID = 'minor_id' SET @MajorID = 'major_id' END SET @sql = 'SELECT col.name AS ''FieldName'', (CASE WHEN (SELECT COUNT(*) FROM sysobjects WHERE (name in (SELECT name FROM sysindexes WHERE (id = col.id) AND (indid in (SELECT indid FROM sysindexkeys WHERE (id = col.id) AND (colid in (SELECT colid FROM syscolumns WHERE (id = col.id) AND (name = col.name))))))) AND (xtype = ''PK''))>0 THEN 1 ELSE 0 END) AS ''IsKey'', typ.name AS ''Type'', col.length AS ''Length'', ext.[value] AS ''Description'', col.isnullable AS ''AllowNull'', com.text AS ''DefaultValue'', col.colstat AS ''IsOutPut'',
答案:db2look   -d   数据库名   -i   用户名-w   密码   -e   -o   ./文件名.txt
其他:如果你能连接数据库,那么可以是呀pd(powerdesigner),连接数据库后,选择生成表结构,则自动生成了该数据库的表结构

上一个:db2 计算用的表
下一个:DB2数据库中数据类型问题?

CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,