转至繁体中文版     | 网站首页 | 文章中心 | 下载中心 | 图片中心 | 笑话频道 | 教程频道 | 会员中心 | 雁过留声 | 
最新公告:     "MinTao学以致用网"欢迎您的光临,你的支持便是我们的动力,欢迎广大网友和各界人士亲临指导,你们的一个小小的建议便是我们发展的开路石!  [MinTao  2007年9月5日]        
您现在的位置: MinTao学以致用网 >> 文章中心 >> 电子课堂 >> 数据库 >> Sql Server >> 文章正文
专题栏目
更多内容
最新推荐 更多内容
相关文章
SQL语言快速入门之一
SQL语言快速入门之二
SQL语言快速入门之三(一
SQL7.0储存过程调试
通过HTTP访问SQL Server
SQL Server的存储过程调
SQL Server安全性简介
定制PB与SQL Anywhere的
全面接触SQL语法
SQL 语法参考手册
更多内容
Sqlserver中的一些技巧         
Sqlserver中的一些技巧
作者:yzx110 文章来源:不详 点击数: 更新时间:2007-11-14 11:12:21

获取一个SQLServer上的所有数据库信息 用存储过程 sp_databases

在查询分析其中执行命令exec sp_databases

结果:master 14464 NULL
model 1280 NULL
msdb 14336 NULL
Northwind 4352 NULL
pubs 2560 NULL
Store 1912 NULL
tempdb 8704 NULL
test 1272 NULL

获取一个数据库的所有表用存储过程 sp_tables

执行命令: use Northwind exec sp_tables 结果:

Northwind dbo sysusers SYSTEM TABLE NULL
Northwind dbo Categories TABLE NULL
Northwind dbo CustomerCustomerDemo TABLE NULL
Northwind dbo CustomerDemographics TABLE NULL
Northwind dbo Customers TABLE NULL
Northwind dbo dtproperties TABLE NULL
Northwind dbo Employees TABLE NULL
Northwind dbo EmployeeTerritories TABLE NULL
(.......)

获取一个表的列信息用存储过程sp_columns

运行exec sp_columns ''''Orders'''' (Orders为表名) 结果

Northwind dbo Orders OrderID 4 int identity 10 4 0 10 0 NULL NULL 4 NULL NULL 1 NO  56
Northwind dbo Orders CustomerID -8 nchar 5 10 NULL NULL 1 NULL NULL -8 NULL 10 2 YES 39
Northwind dbo Orders EmployeeID 4 int 10 4 0 10 1 NULL NULL 4 NULL NULL 3 YES 38
Northwind dbo Orders OrderDate 11 datetime 23 16 3 NULL 1 NULL NULL 9 3 NULL 4 YES 111
Northwind dbo Orders RequiredDate 11 datetime 23 16 3 NULL 1 NULL NULL 9 3 NULL 5 YES 111
Northwind dbo Orders ShippedDate 11 datetime 23 16 3 NULL 1 NULL NULL 9 3 NULL 6 YES 111
Northwind dbo Orders ShipVia 4 int 10 4 0 10 1 NULL NULL 4 NULL NULL 7 YES 38
Northwind dbo Orders Freight 3 money 19 21 4 10 1 NULL (0) 3 NULL NULL 8 YES 110
Northwind dbo Orders ShipName -9 nvarchar 40 80 NULL NULL 1 NULL NULL -9 NULL 80 9 YES 39
(......)

获取一个数据库的所有存储过程,可以用

select * from sysobjects where type=''''p''''

执行所得结果:

CustOrdersDetail 789577851 P  1 0 1610612736 0 0 0 2000-08-06 01:34:52.513
CustOrdersOrders 805577908 P  1 0 1610612736 0 0 0 2000-08-06 01:34:52.733
CustOrderHist 821577965 P  1 0 1610612736 0 0 0 2000-08-06 01:34:52.967
SalesByCategory 837578022 P  1 0 1610612736 0 0 0 2000-08-06 01:34:53.200
(......)

sysobjects这个东西还有其他一些用法,具体可参照SQLServer连机帮助

在ADO.NET里面获取一个存储过程的参数信息:

    SqlConnection connect = new SqlConnection(ConnectionString);
    connect.Open();
    SqlCommand sc = new SqlCommand("SalesByCategory", connect); // SalesByCategory 为Northwind数据库中的一个存储过程.
    sc.CommandType = CommandType.StoredProcedure;
    SqlCommandBuilder.DeriveParameters(sc);
    foreach(SqlParameter param in sc.Parameters)
    {
    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);
    }


 

文章录入:mintao    责任编辑:mintao 
  • 上一篇文章:

  • 下一篇文章:
  • 【字体: 】【发表评论】【加入收藏】【告诉好友】【打印此文】【关闭窗口
      注:本站部分文章源于互联网,版权归原作者所有!如有侵权,请原作者与本站联系,本站将立即删除! 本站文章除特别注明外均可转载,但需注明出处! [MinTao学以致用网]
      网友评论:(只显示最新10条。评论内容只代表网友观点,与本站立场无关!)

    | 设为首页 |加入收藏 | 联系站长 | 友情链接 | 版权申明 | 广告服务
    MinTao学以致用网

    Copyright @ 2007 MinTao学以致用网(www.mintao.net) Inc All Rights Reserved.
    QQ:543098146有事请Q我! QQ:261561092有事请Q我 QQ:179647303有事请Q我 MSN:min906@126.com
    站长:MinTao 信息产业部ICP备案号:鄂ICP备07500065号

    学以致用是我们学习者的至高境界和不懈追求,[MinTao学以致用网]与大家共同学习,共同进步……
    信息产业部备案
    *鄂ICP备07500065号