SQL Server表結構列印

來源:互聯網
上載者:User

declare @t table(表名 varchar(100),欄位名 varchar(100),資料類型 varchar(100),長度 varchar(100),描述 sql_variant )
declare @table varchar(100),@counter int,@tablecount int,@talben varchar(100),@a varchar(100),@b varchar(100),@c varchar(100),@d varchar(100),@e varchar(100)
select @tablecount=count(name) from sysobjects where xtype='u'
declare tablen cursor for
select name from sysobjects where xtype ='U'
open tablen
set @counter=1
while @counter<@tablecount
begin
  fetch next from tablen
  into @talben
  insert @t SELECT  表名=case when a.colorder=1 then d.name else '' end,
欄位名=a.name,
類型=b.name,
長度=COLUMNPROPERTY(a.id,a.name,'PRECISION'),
欄位描述=isnull(g.[value],'')
FROM syscolumns a
left join systypes b on a.xtype=b.xusertype
inner join sysobjects d on a.id=d.id  and d.xtype='U' and  d.name<>'dtproperties'
left join syscomments e on a.cdefault=e.id
left join sysproperties g on a.id=g.id and a.colid=g.smallid 
left join sysproperties f on d.id=f.id and f.smallid=0
  where d.id=object_id(@talben)
  order by a.id,a.colorder
  --insert @t select @talben

set @counter=@counter+1
end
close tablen
deallocate tablen
select * from @t
用前台控制項顯示再列印。

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.