zoukankan      html  css  js  c++  java
  • View

    •  示例
    SELECT     b.name AS TableName, a.name AS FieldName, ISNULL(a.is_nullable, 1) AS AllowNull, d.definition AS DefaultValue, CASE WHEN c.Name = 'image' THEN 'System.Byte[]' WHEN c.Name IN ('image', 
                          'uniqueidentifier', 'ntext', 'varchar', 'ntext', 'nchar', 'nvarchar', 'text', 'char') THEN 'System.String' WHEN c.Name IN ('tinyint', 'smallint', 'int', 'bigint') 
                          THEN 'System.Int32' WHEN c.Name IN ('datetime', 'smalldatetime', 'date') THEN 'System.DateTime' WHEN c.Name IN ('float', 'decimal', 'numeric', 'money', 'real', 'smallmoney') 
                          THEN 'System.Decimal' WHEN c.Name = 'bit' THEN 'System.Boolean' ELSE c.Name END AS ValueType, CASE WHEN ColumnProperty(a.object_id, a.Name, 'Precision') 
                          = - 1 THEN '2^31-1' ELSE rtrim(ColumnProperty(a.object_id, a.Name, 'Precision')) END AS MaxLength, CASE WHEN a.[max_length] = - 1 AND 
                          c.Name != 'xml' THEN 'max/2G' WHEN c.Name = 'xml' THEN '2^31-1字节/2G' ELSE rtrim(a.[max_length]) END AS MaxByteCount, CASE WHEN CHARINDEX('', CAST(e.value AS nvarchar(100))) 
                          > 0 THEN substring(CAST(e.value AS nvarchar(100)), 1, CHARINDEX('', CAST(e.value AS nvarchar(100))) - 1) ELSE CAST(e.value AS nvarchar(100)) END AS FieldDesc, CASE WHEN CHARINDEX('', 
                          CAST(f.value AS nvarchar(100))) > 0 THEN substring(CAST(f.value AS nvarchar(100)), 1, CHARINDEX('', CAST(f.value AS nvarchar(100))) - 1) ELSE CAST(f.value AS nvarchar(100)) END AS TableDesc, 
                          CASE WHEN c.Name = 'image' THEN '图片' WHEN c.Name IN ('image', 'uniqueidentifier', 'ntext', 'varchar', 'ntext', 'nchar', 'nvarchar', 'text', 'char') THEN '字符串' WHEN c.Name IN ('tinyint', 
                          'smallint', 'int', 'bigint') THEN '数字' WHEN c.Name IN ('datetime', 'smalldatetime', 'date') THEN '时间' WHEN c.Name IN ('float', 'decimal', 'numeric', 'money', 'real', 'smallmoney') 
                          THEN '金额' WHEN c.Name = 'bit' THEN '布尔' ELSE c.Name END AS ValueTypeDesc
    FROM         sys.columns AS a INNER JOIN
                          sys.objects AS b ON a.object_id = b.object_id LEFT OUTER JOIN
                          sys.types AS c ON a.user_type_id = c.user_type_id LEFT OUTER JOIN
                          sys.default_constraints AS d ON a.default_object_id = d.object_id LEFT OUTER JOIN
                          sys.extended_properties AS e ON e.name = 'MS_Description' AND e.major_id = a.object_id AND e.minor_id = a.column_id LEFT OUTER JOIN
                          sys.extended_properties AS f ON e.name = 'MS_Description' AND f.major_id = a.object_id AND f.minor_id = 1
    WHERE     (b.type IN ('U', 'V')) AND (a.name <> 'WBDBH')

     整理版

    SELECT     b.name AS TableName, a.name AS FieldName, 
        ISNULL(a.is_nullable, 1) AS AllowNull, d.definition AS DefaultValue, 
        CASE WHEN c.Name = 'image' THEN 'System.Byte[]' 
        WHEN c.Name IN ('image','uniqueidentifier', 'ntext', 'varchar', 'ntext', 'nchar', 'nvarchar', 'text', 'char') 
            THEN 'System.String' 
        WHEN c.Name IN ('tinyint', 'smallint', 'int', 'bigint') 
            THEN 'System.Int32' 
        WHEN c.Name IN ('datetime', 'smalldatetime', 'date') THEN 'System.DateTime' 
        WHEN c.Name IN ('float', 'decimal', 'numeric', 'money', 'real', 'smallmoney') 
            THEN 'System.Decimal' 
        WHEN c.Name = 'bit' THEN 'System.Boolean' ELSE c.Name END AS ValueType, 
        CASE WHEN ColumnProperty(a.object_id, a.Name, 'Precision') 
                          = - 1 THEN '2^31-1' ELSE rtrim(ColumnProperty(a.object_id, a.Name, 'Precision')) END AS MaxLength, CASE WHEN a.[max_length] = - 1 AND 
                          c.Name != 'xml' THEN 'max/2G' WHEN c.Name = 'xml' THEN '2^31-1字节/2G' ELSE rtrim(a.[max_length]) END AS MaxByteCount, CASE WHEN CHARINDEX('', CAST(e.value AS nvarchar(100))) 
                          > 0 THEN substring(CAST(e.value AS nvarchar(100)), 1, CHARINDEX('', CAST(e.value AS nvarchar(100))) - 1) ELSE CAST(e.value AS nvarchar(100)) END AS FieldDesc, CASE WHEN CHARINDEX('', 
                          CAST(f.value AS nvarchar(100))) > 0 THEN substring(CAST(f.value AS nvarchar(100)), 1, CHARINDEX('', CAST(f.value AS nvarchar(100))) - 1) ELSE CAST(f.value AS nvarchar(100)) END AS TableDesc, 
                          CASE WHEN c.Name = 'image' THEN '图片' WHEN c.Name IN ('image', 'uniqueidentifier', 'ntext', 'varchar', 'ntext', 'nchar', 'nvarchar', 'text', 'char') THEN '字符串' WHEN c.Name IN ('tinyint', 
                          'smallint', 'int', 'bigint') THEN '数字' WHEN c.Name IN ('datetime', 'smalldatetime', 'date') THEN '时间' WHEN c.Name IN ('float', 'decimal', 'numeric', 'money', 'real', 'smallmoney') 
                          THEN '金额' WHEN c.Name = 'bit' THEN '布尔' ELSE c.Name END AS ValueTypeDesc
    FROM         sys.columns AS a INNER JOIN
                          sys.objects AS b ON a.object_id = b.object_id 
                          LEFT OUTER JOIN sys.types AS c ON a.user_type_id = c.user_type_id 
                          LEFT OUTER JOIN sys.default_constraints AS d ON a.default_object_id = d.object_id 
                          LEFT OUTER JOIN sys.extended_properties AS e ON e.name = 'MS_Description' AND e.major_id = a.object_id AND e.minor_id = a.column_id 
                          LEFT OUTER JOIN sys.extended_properties AS f ON e.name = 'MS_Description' AND f.major_id = a.object_id AND f.minor_id = 1
    WHERE     (b.type IN ('U', 'V')) 
            AND (a.name <> 'WBDBH')
            
            
    
    select *    
    FROM         sys.columns AS a 
                INNER JOIN sys.objects AS b ON a.object_id = b.object_id 
                LEFT OUTER JOIN sys.types AS c ON a.user_type_id = c.user_type_id 
                LEFT OUTER JOIN sys.default_constraints AS d ON a.default_object_id = d.object_id 
                LEFT OUTER JOIN sys.extended_properties AS e ON e.name = 'MS_Description' AND e.major_id = a.object_id AND e.minor_id = a.column_id 
                LEFT OUTER JOIN sys.extended_properties AS f ON e.name = 'MS_Description' AND f.major_id = a.object_id AND f.minor_id = 1
    WHERE     (b.type IN ('U', 'V')) 
            AND (a.name <> 'WBDBH')
            
        
    select * From  sys.columns where object_id = '17'
    select * From sys.objects where object_id = '17'
        
    
    

    a:sys.columns

    user_type_id
    object_id
    default_object_id
    column_id

    b:sys.objects

      object_id

      

    c:sys.types

      

    sys.default_constraints

      

  • 相关阅读:
    ecstore前台模板变量处理
    MySQL慢查询日志总结
    Linux 操作MySQL常用命令行
    CGI、FastCGI和php-fpm的概念和区别
    sync实现windows与nginx主机端文件同步(参考文档)
    PHP实现四种基本排序算法
    http和https协议
    linux的计划任务
    php封装一个接口类
    mysql的常见面试问题
  • 原文地址:https://www.cnblogs.com/jacketlin/p/6557739.html
Copyright © 2011-2022 走看看