--用T-SQL得到数据库表的默认值select 默认值名称=a.name,
       默认值=b.text,
       所属表名=object_name(d.id),
       所属列名=d.name
  from sysobjects a join syscomments b on a.id=b.id
  join sysconstraints c on c.constid=a.id
  join syscolumns d on c.colid=d.colid and c.id=d.id
  where a.xtype='D' and object_name(d.id)<>'dtproperties'

解决方案 »

  1.   

    --限于2000
    select case when c.colid=1 then object_name(c.id) else '' end as 表名 
    ,c.name as 字段名
    ,t.name 数据类型
    ,c.prec as 长度
    ,p.value as 字段说明
    ,m.text as 默认值
    from syscolumns c
    inner join systypes t on c.xusertype=t.xusertype
    left join sysproperties p on c.id=p.id and c.colid = p.smallid
    left join syscomments m on c.cdefault=m.id
    where objectproperty(c.id,'IsUserTable')=1
      

  2.   

    谢谢楼上两位。但我是要通过SqlDmo来取值,不用系统表。
      

  3.   

    SQLDMO.Column的default属性可以取到默认值,但字段说明好像无法取到.
      

  4.   

    在SQL SERVER安装光盘上有很多SQLDMO的示例,楼主自己研究一下吧.
      

  5.   

    我在dmo的帮助里找到了这个,但我研究不出来。请大家研究一下。我用VB的。
    Applies ToSQLServer2 Object
    Syntaxobject.EnumCollations( ) as QueryResultsPartsobjectExpression that evaluates to an object in the Applies To listPrototype (C/C++)HRESULT EnumCollations(LPSQLDMOQUERYRESULTS *ppResults);ReturnsA QueryResults object that contains one result set defined by these columns.Column Data type Description
    Name String Collation name
    Description String Collation description
    ResEnumCollations is similar to the ListCollations method, and is used in conjunction with column-level collation. After using EnumCollations to enumerate the collation names, an application can set the Collation property to use a specific collation with a Database2 or UserDefinedFunction object.Note牋營f an application calls EnumCollations on an instance of SQL Server version 7.0, the constant, SQLDMO_E_SQL80ONLY, and the message "This property or method requires Microsoft SQL Server 2000" are returned.See AlsoCollation Property
    ListCollations Method
      

  6.   

    请问你字段描述取出来了吗,我也需要在dmo里面取字段描述,有答案,或者其他解决办法请分享一下
      

  7.   

    select b.value from syscolumns a join sysproperties b on a.id=b.id
    where a.id=object_id('表') and a.name='字段'