教您如何获取SQL字段默认值


  本文标签:SQL字段默认值

  在sql server 中,如何获取SQL字段默认值呢?下面就为您介绍实现该功能的方法,如果您遇到过类似的问题,不妨一看,希望对您有所帮助  。

  sql server 中获取SQL字段默认值 ,获取所有的默认值列表:

  1. select   
  2. object_name(c.id) as 表名  
  3.  ,c.name as 字段名  
  4.  ,t.name as 数据类型  
  5.  ,c.prec as 长度  
  6.  ,p.value as 字段说明  
  7.  ,m.text as 默认值  
  8. from syscolumns c  
  9.  inner join  
  10.  systypes t  
  11.  on c.xusertype=t.xusertype  
  12.  left join   
  13.  sysproperties p  
  14.  on c.id=p.id and c.colid = p.smallid  
  15.  left join  
  16.  syscomments m  
  17.  on c.cdefault=m.id 

  研究了很久 终于搞定了

  获取单个SQL字段默认值列表

  1. select   
  2. object_name(c.id) as 表名  
  3.  ,c.name as 字段名  
  4.  ,t.name as 数据类型  
  5.  ,c.prec as 长度  
  6.  ,p.value as 字段说明  
  7.  ,m.text as 默认值  
  8. from syscolumns c  
  9.  inner join  
  10.  systypes t  
  11.  on c.xusertype=t.xusertype  
  12.  left join   
  13.  sysproperties p  
  14.  on c.id=p.id and c.colid = p.smallid  
  15.  left join  
  16.  syscomments m  
  17.  on c.cdefault=m.id  
  18. where objectproperty(c.id,IsUserTable)=1  
  19.  and object_name(c.id) = T_good and c.name = ishot