Quick Build Database Dictionary __ Database

Source: Internet
Author: User
Tags one table
SELECT tablename=case when c.column_id=1 THEN o.name ELSE N ' "End, Tabledesc=isnull (case when C.column_id=1 THEN Ptb. [Value] End,n '), column_id=c.column_id, Columnname=c.name, Primarykey=isnull (IDX. Primarykey,n '), [identity]=case when C.is_identity=1 THEN n ' √ ' ELSE n ' ", computed=case when C.is_computed=1 TH EN n ' √ ' ELSE n ' end, Type=t.name, Length=c.max_length, Precision=c.precision, Scale=c.scale, nullable= case when c.is_nullable=1 THEN n ' √ ' ELSE n ' End, [Default]=isnull (D.definition,n '), Columndesc=isnull (Pfd.[value) , N '), Indexname=isnull (IDX. Indexname,n '), Indexsort=isnull (IDX.
        Sort,n '), Create_date=o.create_date, modify_date=o.modify_date from sys.columns C INNER JOIN sys.objects O  On c.[object_id]=o.[object_id] and o.type= ' U ' and o.is_ms_shipped=0 INNER JOIN sys.types T on c.user_type_id=t.user_type_id left JOIN sys.default_constraints D onc.[object_id]=d.parent_object_id and c.column_id=d.parent_column_id and C.default_object_id=d.[obj 
            ECT_ID] left JOIN sys.extended_properties PFD on Pfd.class=1 and c.[object_id]=pfd.major_id and c.column_id=pfd.minor_id--and Pfd.name= ' Caption '--the description name corresponding to the field description (one field can add more than one description of different name) left J OIN sys.extended_properties PTB on Ptb.class=1 and Ptb.minor_id=0 and C.[OBJECT_ID]=PTB. MAJOR_ID--and Pfd.name= ' Caption '--table description corresponding description name (one table can add multiple descriptions of different names) left JOIN--cable Primer and primary key information (SELECT idxc.[ OBJECT_ID], idxc.column_id, Sort=case indexkey_property (idxc.[  object_id],idxc.index_id,idxc.index_column_id, ' isdescending ') when 1 THEN ' DESC ' when 0 THEN ' ASC ' ELSE ' End, primarykey=case when Idx.is_primary_key=1 THEN n ' √ ' ELSE n ' "End, Indexname=idx. Name from Sys.indeXes IDX INNER JOIN sys.index_columns idxc on IDX. [OBJECT_ID]=IDXC.
                [OBJECT_ID] and idx.index_id=idxc.index_id left JOIN sys.key_constraints KC on IDX. [object_id]=kc.[parent_object_id] and idx.index_id=kc.unique_index_id INNER JOIN--For a column that contains multiple indexes condition, only the 1th index information is displayed (SELECT [object_id], column_id, Index_id=min (index_id) from Sys.index_column s GROUP by [object_id], column_id) Idxcuq on IDXC. [Object_id]=idxcuq.
                [OBJECT_ID] and IDXC. Column_id=idxcuq. column_id and idxc.index_id=idxcuq.index_id) IDX on C.[object_id]=idx.
            [OBJECT_ID] and c.column_id=idx.column_id--where o.name=n ' table to query '--if only the specified table is queried, plus this condition order by o.name,c.column_id--select * fro  M sys.databases

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.