【推荐】Sql Server 不常见应用之一:获取表的基本信息、字段列表、存储过程参数列表

本文涉及的产品
云数据库 RDS SQL Server,独享型 2核4GB
简介:

推荐Sql Server 不常见应用之一

获取表的基本信息、字段列表、存储过程参数列表

 

——通过知识共享树立个人品牌。

 

  


 

一、获取表的基本信息

 

  SELECT  [ TableName ]  =  [ Tables ].name ,

         [ TableOwner ]  =  [ Schemas ].name ,

         [ TableCreateDate ]  =  [ Tables ].create_date ,

         [ TableModifyDate ]  =  [ Tables ].modify_date

FROM    sys.tables  AS  [ Tables ]

         INNER  JOIN sys.schemas  AS  [ Schemas ]  ON  [ Tables ].schema_id  =  [ Schemas ].schema_id

WHERE    [ Tables ].name  =  ' 案卷目录 '

 

效果如图一所示:

 

 

 

图一 指定表的基本信息

 

二、根据表名获取字段列表

 

SELECT  [ ColumnName ]  =  [ Columns ].name ,

         [ 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 ,

         [ Description ]  =  [ Properties ].value

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  =案卷目录

ORDER  BY  [ Columns ].column_id

 

 

效果如图二所示:

 

图二 指定表的字段列表信息

 

 

三、获取指定存储过程参数列表

 

SELECT sc.name  AS 参数名 ,

        st.name  AS 类型 ,

        sc.length  AS 长度

FROM    syscolumns sc

         INNER  JOIN sysobjects so  ON so.id  = sc.id

         INNER  JOIN systypes st  ON sc.xtype  = st.xtype

WHERE   so.name  =  ' SP_Pagination '

 

效果如图三所示:

 

 

图三 指定存储过程的参数列表

 

 



本文转自yonghu86 51CTO博客,原文链接:http://blog.51cto.com/yonghu/1321322,如需转载请自行联系原作者

相关实践学习
使用SQL语句管理索引
本次实验主要介绍如何在RDS-SQLServer数据库中,使用SQL语句管理索引。
SQL Server on Linux入门教程
SQL Server数据库一直只提供Windows下的版本。2016年微软宣布推出可运行在Linux系统下的SQL Server数据库,该版本目前还是早期预览版本。本课程主要介绍SQLServer On Linux的基本知识。 相关的阿里云产品:云数据库RDS&nbsp;SQL Server版 RDS SQL Server不仅拥有高可用架构和任意时间点的数据恢复功能,强力支撑各种企业应用,同时也包含了微软的License费用,减少额外支出。 了解产品详情:&nbsp;https://www.aliyun.com/product/rds/sqlserver
相关文章
|
3月前
|
存储 SQL 缓存
4.2.1 SQL语句、索引、视图、存储过程
4.2.1 SQL语句、索引、视图、存储过程
|
28天前
|
存储 SQL 数据库
sql serve存储过程
sql serve存储过程
14 0
|
2月前
|
存储 SQL 关系型数据库
MySQL技能完整学习列表7、存储过程和函数——1、存储过程(Stored Procedures)的创建和执行——2、函数(Functions)的创建和使用
MySQL技能完整学习列表7、存储过程和函数——1、存储过程(Stored Procedures)的创建和执行——2、函数(Functions)的创建和使用
35 0
|
1月前
|
存储 SQL
物料清单应用输入模板的SQL存储过程设计
物料清单应用输入模板的SQL存储过程设计
|
2月前
|
SQL JSON 关系型数据库
sql如何获取字段里的json值
sql如何获取字段里的json值
|
2月前
|
SQL
Sql语法:字段不为空
Sql语法:字段不为空
|
3月前
|
存储 SQL Oracle
PL/SQL存储过程的使用
PL/SQL存储过程的使用
65 1
|
SQL 存储 数据安全/隐私保护