`

查询数据库字段的默认值

阅读更多
if object_id('tb') is not null  
drop table tb   
go   
create table tb(id int,name varchar(50) default 'abc',num int default 5)   
insert into tb(id) select 1   
insert into tb select 1,'oo',100   
insert into tb(id,name) select 1,'oo'  
go   
declare @tbname varchar(50)   
set @tbname='tb'--表名   
select @tbname as tbname,c.name as colname,replace(replace(replace(replace(b.[text],'(''',''),''')',''),'((',''),'))','') as defaultvalue   
from sysconstraints a join syscomments b on a.constid=b.id     
join syscolumns c on a.id=c.id and a.colid=c.colid   
where a.id=object_id(@tbname) and object_name(a.constid) like '%df%' 
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics