• 查看表字段的相关的系统信息


    SELECT (case when a.colorder=1 then d.name else '' end) as tableName,--如果表名相同就返回空
    a.name as fieldName,
    (case when COLUMNPROPERTY( a.id,a.name,'IsIdentity')=1 then '1'else '0' end) as autoval,
    (case when (SELECT count(*) FROM sysobjects--查询主键
    WHERE (name in
    (SELECT name FROM sysindexes
    WHERE (id = a.id) AND (indid in
    (SELECT indid FROM sysindexkeys
    WHERE (id = a.id) AND (colid in
    (SELECT colid FROM syscolumns
    WHERE (id = a.id) AND (name = a.name))
    )))))
    AND (xtype = 'PK'))>0 then '1' else '0' end) as isKey,--查询主键END
    b.name as FieldType,
    COLUMNPROPERTY(a.id,a.name,'PRECISION') as fieldLength,
    isnull(g.[value],'') AS Description
    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 sys.extended_properties g
    on a.id=g.major_id AND a.colid = g.minor_id
    where d.name='DI_TreeType' order by a.id,a.colorder





    SELECT distinct c.column_name, c .data_type, c.is_nullable, tc.constraint_type, c.numeric_precision, c.numeric_scale, c.character_maximum_length, c.table_name, c.ordinal_position, tc.constraint_name,h.value as content
    from information_schema.columns c
    left outer join (
    information_schema.constraint_column_usage ccu
    join information_schema.table_constraints tc on (
    tc.table_schema = ccu.table_schema
    and tc.constraint_name = ccu.constraint_name
    and tc.constraint_type <> 'CHECK'
    )
    ) on (
    c.table_schema = ccu.table_schema and ccu.table_schema = 'dbo'
    and c.table_name = ccu.table_name
    and c.column_name = ccu.column_name
    )
    left join (select a.name,value,d.name as tableName 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 sys.extended_properties g
    on a.id=g.major_id AND a.colid = g.minor_id ) as h on c.COLUMN_NAME=h.name and c.TABLE_NAME=h.tableName

    where c.table_name = 'DI_TreeType'
    and c.table_schema ='dbo'
    order by c.table_name, c.ordinal_position

  • 相关阅读:
    虚拟机linux下git clone 报SSL connect error错误
    TooManyRedirects错误
    windows2008 使用 opencv_python 出现 DLL load failed错误
    禁止别人通过开发人员工具查看网站代码
    pipreqs 执行报错问题
    Vue-router 报NavigationDuplicated的解决方案
    git 记住用户密码
    获取python所有依赖包
    修改pip的安装源
    使用pycharm发布python程序到ubuntu中运行
  • 原文地址:https://www.cnblogs.com/yexinw/p/2728892.html
Copyright © 2020-2023  润新知