SELECT * FROM INFORMATION_SCHEMA.columns WHERE TABLE_NAME='MenuInfo' 

select * from sysobjects where name='MenuInfo' --查询所有表
select * from sysobjects where = AND xtype='U' --查询用户创建所有表
select * from syscolumns where = AND id='' --查询 指定id(也就是表)下的所有列名
select * from systypes where = AND status= AND xtype ='' --查询 系统类型表
select t1.name,t1.id as t1id, t4.id as t4id from(
select name,id,colid,xtype FROM SYSCOLUMNS where =
AND id=(select id from sysobjects where = AND xtype='U' AND name='MenuInfo')
AND (name='MenuName' or name='Id')
)t1
left join
(
select id,colid from SYSINDEXKEYS --sys index keys 系统主键表
where = and id ='' --这个id 是表名id; 用户所创建的表中的id,
-- 查询 出的数据 是
/*
--sysindexkeys
id colid
565577053 2 //这个colid=2 表示 这个是主键 --syscolums 系统所有列的数据信息
name id colid xtype
MenuName 565577053 1 231
Id 565577053 2 56
*/
)t4
on
t4.id = t1.id
and
t1.colid = t4.colid
          select name,id,colid,xtype, case when COLUMNPROPERTY(id,name,'IsIdentity') =  then 'true' else 'false' end as  自增 FROM SYSCOLUMNS   where =
AND id=(select id from sysobjects where = AND xtype='U' AND name='MenuInfo')
AND (name='MenuName' or name='Id')
          select name,id,colid,xtype,  COLUMNPROPERTY(id,name,'IsIdentity') as  自增 FROM SYSCOLUMNS   where =
AND id=(select id from sysobjects where = AND xtype='U' AND name='MenuInfo')
AND (name='MenuName' or name='Id')

--转自

https://blog.csdn.net/xiaozaq/article/details/58584970

//加以修改

-------------最终版
select t1.name,t3.name,t1.[length],t1.isnullable,t2.id as 主键,COLUMNPROPERTY(t1.id,t1.name,'IsIdentity') as 自增 from(
select name,id,colid,xtype,[length],isnullable FROM SYSCOLUMNS where =
AND id=(select id from sysobjects where = AND xtype='U' AND name='MenuInfo')
)t1
left join
(
select id,colid from SYSINDEXKEYS --sys index keys 系统主键表
)t2
on
t2.id = t1.id
and t1.colid = t2.colid
left join
(
select name,xtype from systypes where = AND status= --AND xtype =''
)t3
on
t1.xtype = t3.xtype
select
c.name as [字段名],t.name as [字段类型]
,convert(bit,c.IsNullable) as [可否为空]
,convert(bit,case when exists(select 1 from sysobjects where xtype='PK' and parent_obj=c.id and name in (
select name from sysindexes where indid in(
select indid from sysindexkeys where id = c.id and colid=c.colid))) then 1 else 0 end)
as [是否主键]
,convert(bit,case when exists(select 1 from syscolumns col,sysforeignkeys f
where f.fkeyid=col.id and col.name=c.name and f.fkey=col.colid and f.constid in (
select distinct(id) from sysobjects where OBJECT_NAME(parent_obj)='User' and xtype='F'
)) then 1 else 0 end) as [是否外键]
,convert(bit,COLUMNPROPERTY(c.id,c.name,'IsIdentity')) as [自动增长]
,c.Length as [占用字节]
,COLUMNPROPERTY(c.id,c.name,'PRECISION') as [长度]
,isnull(COLUMNPROPERTY(c.id,c.name,'Scale'),0) as [小数位数]
,ISNULL(CM.text,'') as [默认值]
,isnull(ETP.value,'') AS [字段描述]
--,ROW_NUMBER() OVER (ORDER BY C.name) AS [Row]
from syscolumns c
inner join systypes t on c.xusertype = t.xusertype
left join sys.extended_properties ETP on ETP.major_id = c.id and ETP.minor_id = c.colid and ETP.name ='MS_Description'
left join syscomments CM on c.cdefault=CM.id
where c.id = object_id('MenuInfo')

--

select * from sys.columns where object_id=object_id('MenuInfo')

--查询注释

select
a.name as table_name,
b.name as column_name,
c.value as remarks
from sys.tables a left join sys.columns b on a.object_id=b.object_id
left join sys.extended_properties c on a.object_id=c.major_id
where a.name='db_table5' and c.minor_id<> and b.column_id=c.minor_id
and a.schema_id=(
select schema_id from sys.schemas where name='dbo'
)
--查询注释所需要的表
select * from sys.tables
select * from sys.columns
select * from sys.extended_properties --备注
select * from sys.schemas
---其他表
select * from sysobjects
select * from syscolumns
SELECT * FROM INFORMATION_SCHEMA.columns
select * FROM SYSINDEXKEYS
select * FROM systypes

---

--查看表的所有字段注释
use FileManageDB;
SELECT [ColumnName] = [Columns].name ,
[Description] = [Properties].value,
[SystemTypeName] = [Types].name ,
[Precision] = [Columns].precision ,
[Scale] = [Columns].scale ,
[MaxLength] = [Columns].max_length ,
[IsNullable] = [Columns].is_nullable ,
[IsRowGUIDCol] = [Columns].is_rowguidcol ,
[IsIdentity] = [Columns].is_identity ,
[IsComputed] = [Columns].is_computed ,
[IsXmlDocument] = [Columns].is_xml_document
FROM sys.tables AS [Tables]
INNER JOIN sys.columns AS [Columns] ON [Tables].object_id = [Columns].object_id
INNER JOIN sys.types AS [Types] ON [Columns].system_type_id = [Types].system_type_id
AND is_user_defined = 0
AND [Types].name <> 'sysname'
LEFT OUTER JOIN sys.extended_properties AS [Properties] ON [Properties].major_id = [Tables].object_id
AND [Properties].minor_id = [Columns].column_id
AND [Properties].name = 'MS_Description'
WHERE [Tables].name ='T_Logs' -- and [Columns].name = '字段名'
ORDER BY [Columns].column_id

----

--增加字段注释
EXEC sp_addextendedproperty
'MS_Description', '性别123', 'user', dbo, 'table',T_Logs, --表名
'column', LogType; --列名 ---更新字段注释
EXEC sp_updateextendedproperty 'MS_Description', '性别3', 'user', dbo, 'table',T_Logs, --表名
'column', LogType; --列名

sqlserver 查询 字段的更多相关文章

  1. sqlserver中怎么查询字段为空的记录

    sqlserver中怎么查询字段为空的记录的两种方法: 详细介绍请查看全文:https://cnblogs.com/qianzf/ 原文博客的链接地址:https://cnblogs.com/qzf/

  2. 【转载】看懂SqlServer查询计划

    看懂SqlServer查询计划 阅读目录 开始 SQL Server 查找记录的方法 SQL Server Join 方式 更具体执行过程 索引统计信息:查询计划的选择依据 优化视图查询 推荐阅读-M ...

  3. 看懂SqlServer查询计划

    看懂SqlServer查询计划 阅读目录 开始 SQL Server 查找记录的方法 SQL Server Join 方式 更具体执行过程 索引统计信息:查询计划的选择依据 优化视图查询 推荐阅读-M ...

  4. 把sqlserver查询结果复制到Excel出现数据记录遗漏

    问题:今天在sqlserver查询,总共有10000记录,把结果复制到Excel,发现少掉352条,用导出csv也是如此. 原因:经排查发现缺少的记录是因为商品名称字段包含英文双引号". 解 ...

  5. SQLServer查询语句收集

    常用的SQLServer查询语句,有空可以多练习一下,增加记忆,可以提高工作效率! 1.数据操作 Select      --从数据库表中检索数据行和列Insert      --向数据库表添加新数据 ...

  6. Mybatis按SQL查询字段的顺序返回查询结果

    在SpringMVC+Mybatis的开发过程中,可以通过指定resultType="hashmap"来获得查询结果,但其输出是没有顺序的.如果要按照SQL查询字段的顺序返回查询结 ...

  7. SQLServer查询执行计划分析 - 案例

    SQLServer查询执行计划分析 - 案例 http://pan.baidu.com/s/1pJ0gLjP 包括学习笔记.书.样例库

  8. Oracle 查询字段在什么表

    -- 查询字段在什么表 select * from all_tab_cols t where t.column_name='ABC'; -- 查询字段在什么表并且 判断是否是主键 select * f ...

  9. SqlServer查询数据库所有表

    //SqlServer查询数据库所有表SELECT * FROM SYSOBJECTS WHERE TYPE='U' and name like '%dict%'

随机推荐

  1. php exec执行不等待返回结果

    windows中:pclose(popen("start php.exe test.php","r"));lnuix中: pclose(popen(" ...

  2. Ruby Rails学习中:关于测试的补充,MiniTest报告程序,Guard自动测试

    一. 关于测试的补充 1.MiniTest报告程序 为了让 Rails 应用的测试适时显示红色和绿色,我建议你在测试辅助文件中加入以下内容: (1).打开文件:test/test_helper.rb ...

  3. url编码问题小计

    昨天通过get访问服务器遇到了服务器获取不到参数的问题,最后排查下来是因为url编码的原因,之前使用的是字符串拼接,所以有一些特殊字符如‘%’没有正确的编码, 通过改成各个部分编码,正确获取到数据. ...

  4. Excel导入异常Cannot get a text value from a numeric cell解决

    POI操作Excel时偶尔会出现Cannot get a text value from a numeric cell的异常错误. 异常原因:Excel数据Cell有不同的类型,当我们试图从一个数字类 ...

  5. k8s遇坑:The connection to the server k8s-api.virtual.local:6443 was refused - did you specify the right host or port?

    k8s坑The connection to the server localhost:8080 was refused - did you specify the right host or port ...

  6. TreeMap——实现comparable接口并重写CompareTo方法

    public class TreeMapTest { public static void main(String[] args) { Map<Student,Integer> stude ...

  7. Cannot resolve the collation conflict between "SQL_Latin1_General_CP1_CI_AS" and "Chinese_PRC_CI_AI" in the equal to operation.

    Executed as user: NT AUTHORITY\SYSTEM. Cannot resolve the collation conflict between "Chinese_P ...

  8. 【原创】大数据基础之Logstash(6)mongo input

    logstash input插件之mongodb是第三方的,配置如下: input { mongodb { uri => 'mongodb://mongo_server:27017/db' pl ...

  9. SpringCloud 配置文件 application.yml和 bootstrap.yml区别

    前言: SpringBoot默认支持properties和YAML两种格式的配置文件.前者格式简单,但是只支持键值对.如果需要表达列表,最好使用YAML格式.SpringBoot支持自动加载约定名称的 ...

  10. [转载]python with语句的用法

    https://www.cnblogs.com/DswCnblog/p/6126588.html 看这篇文章的时候看到了python的类名()用法,很好奇,上网查了下,原来这就相当于对类进行实例化了. ...