Sqlserver中的一些技巧

本文涉及的产品
云数据库 RDS SQL Server,独享型 2核4GB
简介:
None.gif获取一个SQLServer上的所有数据库信息 用存储过程 sp_databases
None.gif
None.gif在查询分析其中执行命令exec sp_databases
None.gif
None.gif结果:master 14464 NULL
None.gifmodel 1280 NULL
None.gifmsdb 14336 NULL
None.gifNorthwind 4352 NULL
None.gifpubs 2560 NULL
None.gifStore 1912 NULL
None.giftempdb 8704 NULL
None.giftest 1272 NULL
None.gif
None.gif获取一个数据库的所有表用存储过程 sp_tables
None.gif
None.gif执行命令: use Northwind exec sp_tables 结果:
None.gif
None.gifNorthwind dbo sysusers SYSTEM TABLE NULL
None.gifNorthwind dbo Categories TABLE NULL
None.gifNorthwind dbo CustomerCustomerDemo TABLE NULL
None.gifNorthwind dbo CustomerDemographics TABLE NULL
None.gifNorthwind dbo Customers TABLE NULL
None.gifNorthwind dbo dtproperties TABLE NULL
None.gifNorthwind dbo Employees TABLE NULL
None.gifNorthwind dbo EmployeeTerritories TABLE NULL
None.gif( dot.gif dot.gif.)
None.gif
None.gif
None.gif获取一个表的列信息用存储过程sp_columns
None.gif
None.gif运行exec sp_columns ' Orders ' (Orders为表名) 结果
None.gif
None.gifNorthwind dbo Orders OrderID 4 int identity 10 4 0 10 0 NULL NULL 4 NULL NULL 1 NO 56
None.gifNorthwind dbo Orders CustomerID - 8 nchar 5 10 NULL NULL 1 NULL NULL - 8 NULL 10 2 YES 39
None.gifNorthwind dbo Orders EmployeeID 4 int 10 4 0 10 1 NULL NULL 4 NULL NULL 3 YES 38
None.gifNorthwind dbo Orders OrderDate 11 datetime 23 16 3 NULL 1 NULL NULL 9 3 NULL 4 YES 111
None.gifNorthwind dbo Orders RequiredDate 11 datetime 23 16 3 NULL 1 NULL NULL 9 3 NULL 5 YES 111
None.gifNorthwind dbo Orders ShippedDate 11 datetime 23 16 3 NULL 1 NULL NULL 9 3 NULL 6 YES 111
None.gifNorthwind dbo Orders ShipVia 4 int 10 4 0 10 1 NULL NULL 4 NULL NULL 7 YES 38
None.gifNorthwind dbo Orders Freight 3 money 19 21 4 10 1 NULL ( 0) 3 NULL NULL 8 YES 110
None.gifNorthwind dbo Orders ShipName - 9 nvarchar 40 80 NULL NULL 1 NULL NULL - 9 NULL 80 9 YES 39
None.gif( dot.gif dot.gif)
None.gif
None.gif获取一个数据库的所有存储过程,可以用
None.gif
None.gif select * from sysobjects where type = ' p '
None.gif
None.gif执行所得结果:
None.gif
None.gifCustOrdersDetail 789577851 P 1 0 1610612736 0 0 0 2000 - 08 - 06 01: 34: 52.513
None.gifCustOrdersOrders 805577908 P 1 0 1610612736 0 0 0 2000 - 08 - 06 01: 34: 52.733
None.gifCustOrderHist 821577965 P 1 0 1610612736 0 0 0 2000 - 08 - 06 01: 34: 52.967
None.gifSalesByCategory 837578022 P 1 0 1610612736 0 0 0 2000 - 08 - 06 01: 34: 53.200
None.gif( dot.gif dot.gif)
None.gif
None.gifsysobjects这个东西还有其他一些用法,具体可参照SQLServer连机帮助
None.gif
None.gif在ADO.NET里面获取一个存储过程的参数信息:
None.gif
None.gif SqlConnection connect = new SqlConnection(ConnectionString);
None.gif connect. Open();
None.gif SqlCommand sc = new SqlCommand("SalesByCategory", connect); // SalesByCategory 为Northwind数据库中的一个存储过程.
None.gif sc.CommandType = CommandType.StoredProcedure;
None.gif SqlCommandBuilder.DeriveParameters(sc);
None.gif foreach(SqlParameter param in sc.Parameters)
None.gif {
None.gif Console.WriteLine("Name:{ 0}, Size:{ 1}, Type:{ 2}, Value:{ 3},Direction:{ 4}, IsNull:{ 5}", param.ParameterName, param.Size, param.DbType, param.Value, param.Direction, param.IsNullable);
None.gif }



本文转自高海东博客园博客,原文链接:http://www.cnblogs.com/ghd258/archive/2005/10/24/260745.html,如需转载请自行联系原作者 
相关实践学习
使用SQL语句管理索引
本次实验主要介绍如何在RDS-SQLServer数据库中,使用SQL语句管理索引。
SQL Server on Linux入门教程
SQL Server数据库一直只提供Windows下的版本。2016年微软宣布推出可运行在Linux系统下的SQL Server数据库,该版本目前还是早期预览版本。本课程主要介绍SQLServer On Linux的基本知识。 相关的阿里云产品:云数据库RDS SQL Server版 RDS SQL Server不仅拥有高可用架构和任意时间点的数据恢复功能,强力支撑各种企业应用,同时也包含了微软的License费用,减少额外支出。 了解产品详情: https://www.aliyun.com/product/rds/sqlserver
相关文章
|
1天前
|
SQL 数据处理 API
实时计算 Flink版产品使用合集之遇到SQL Server锁表问题如何解决
实时计算Flink版作为一种强大的流处理和批处理统一的计算框架,广泛应用于各种需要实时数据处理和分析的场景。实时计算Flink版通常结合SQL接口、DataStream API、以及与上下游数据源和存储系统的丰富连接器,提供了一套全面的解决方案,以应对各种实时计算需求。其低延迟、高吞吐、容错性强的特点,使其成为众多企业和组织实时数据处理首选的技术平台。以下是实时计算Flink版的一些典型使用合集。
7 0
|
1天前
|
SQL API 流计算
实时计算 Flink版产品使用合集之在Mac M1下的Docker环境中开启SQL Server代理的操作步骤是什么
实时计算Flink版作为一种强大的流处理和批处理统一的计算框架,广泛应用于各种需要实时数据处理和分析的场景。实时计算Flink版通常结合SQL接口、DataStream API、以及与上下游数据源和存储系统的丰富连接器,提供了一套全面的解决方案,以应对各种实时计算需求。其低延迟、高吞吐、容错性强的特点,使其成为众多企业和组织实时数据处理首选的技术平台。以下是实时计算Flink版的一些典型使用合集。
17 1
|
2天前
|
SQL 关系型数据库 MySQL
实时计算 Flink版产品使用合集之当 SQL Server 源数据库中的数据更新后,CDC 吐出的操作(op)是怎样的
实时计算Flink版作为一种强大的流处理和批处理统一的计算框架,广泛应用于各种需要实时数据处理和分析的场景。实时计算Flink版通常结合SQL接口、DataStream API、以及与上下游数据源和存储系统的丰富连接器,提供了一套全面的解决方案,以应对各种实时计算需求。其低延迟、高吞吐、容错性强的特点,使其成为众多企业和组织实时数据处理首选的技术平台。以下是实时计算Flink版的一些典型使用合集。
12 0
|
3天前
|
SQL XML Linux
SQL Server的版本
【5月更文挑战第14天】SQL Server的版本
18 3
|
3天前
|
SQL 关系型数据库 数据管理
Microsoft SQL Server 是微软公司开发的一款关系型数据库管理系统
【5月更文挑战第14天】Microsoft SQL Server 是微软公司开发的一款关系型数据库管理系统
16 2
|
3天前
|
SQL 存储 数据库连接
LabVIEW与SQL Server 2919 Express通讯
LabVIEW与SQL Server 2919 Express通讯
|
3天前
|
SQL Windows
安装SQL Server 2005时出现对性能监视器计数器注册表值执行系统配置检查失败的解决办法...
安装SQL Server 2005时出现对性能监视器计数器注册表值执行系统配置检查失败的解决办法...
14 4
|
3天前
|
SQL 数据可视化 Oracle
这篇文章教会你:从 SQL Server 移植到 DM(上)
这篇文章教会你:从 SQL Server 移植到 DM(上)
|
3天前
|
SQL 关系型数据库 数据库
SQL Server语法基础:入门到精通
SQL Server语法基础:入门到精通
SQL Server语法基础:入门到精通
|
3天前
|
SQL 存储 网络协议
SQL Server详细使用教程
SQL Server详细使用教程
31 2