Gets whether the default value is the primary key for all columns in the database and whether the type of the column is empty

Source: Internet
Author: User

Through a variety of search data, and read SQL Server's own stored procedures summarized

SELECT DISTINCT c.name as TableName, a.name,a.is_nullable,dbo. Getremoveparentheses (D.text) as defaultvalue,case when (A.name = Index_col (C.name, f.index_id, 1) or a.name = in Dex_col (C.name, f.index_id, 2) or a.name = Index_col (C.name, f.index_id, 3) or a.name = Index_col (C.N Ame, f.index_id, 4) or a.name = Index_col (C.name, f.index_id, 5) or a.name = Index_col (C.name, F.index         _ID, 6) or a.name = Index_col (C.name, f.index_id, 7) or a.name = Index_col (C.name, f.index_id, 8) or A.name = Index_col (C.name, f.index_id, 9) or a.name = Index_col (C.name, f.index_id, ten) or a.na me = Index_col (C.name, f.index_id, one) or A.name = Index_col (C.name, f.index_id,) or a.name = Index_c OL (C.name, f.index_id,) or A.name = Index_col (C.name, f.index_id, +) or A.name = Index_col (C.name, f.index_id) or a.name = Index_col (C.name, f.index_id, +) then 1 ELSE0 END as Isprimary, case a.precision if 0 then case a.is_ansi_padded when 1                 Then CONVERT (NVARCHAR, B.name + ' (' + CONVERT (NVARCHAR), a.max_length) + ')                 When 0 then b.name END ELSE case A.scale when 0 then B.name ELSE b.name + ' (' + CONVERT (NVARCHAR), a.precision) + ', ' + CONVERT (NVARCHAR (), A.scale) + ') ' End end as Typelength from Sys.columns a left JOIN sys.types b on a.system_type_id = B. system_type_id and a.user_type_id = B.user_type_idinner JOIN sysobjects c on c.id = A.obje Ct_idleft join syscomments D on d.id = A.default_object_idinner join sys.key_constraints e on e.parent_object_id = A.objec   T_idinner JOIN sys.indexes F on e.unique_index_id = F.index_idwhere C.xtype = ' u ' and F.is_primary_key = 1


Gets whether the default value is the primary key for all columns in the database and whether the type of the column is empty

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.