SQL Server table structure Printing

Source: Internet
Author: User

Declare @ t table (table name: varchar (100); field name: varchar (100); Data Type: varchar (100); Length: varchar (100); Description: 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
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 table name = case when a. colorder = 1 then D. Name else ''end,
Field name = A. Name,
Type = B. Name,
Length = columnproperty (A. ID, A. Name, 'precision '),
Field description = isnull (G. [value], '')
From syscolumns
Left join policypes 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
Display and print with the foreground control.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.