动网论坛,站长建站首选,国内使用量最多的论坛软件 动网论坛官方技术讨论区 站长工具 申请属于您自己的免费论坛
首页 | 新闻资讯 | 网站运营 | 网络编程 | 数据库 | 服务器 | 网页设计 | 图像媒体 | 网络应用 | 搜索优化 | 资源下载 | 动网主机 | DVBOX
    本站内  互联网 ASP论坛  ASP.Net论坛  PHP论坛
   数据库 → 阅读文章

 Sqlserver中的一些技巧

作者:无从考证 来源:CSDN 
阅读 3406 人次 , 2006-2-15 17:39:00 

获取一个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);
    }    
 本文Tags数据库  
 收藏本文  打印本文  论坛讨论  关闭窗口
· 上一篇:备份服务器端SQL SERVER数据库至本地目录
· 下一篇:在SQL Server存储过程中执行DTS包
· SQL Server 2000之日志传送功能 - 设定(2)
· 浅谈如何有效建立权限管理体系
· SQL查询语句精华使用简要
· MySQL 如何对抗解密高手
· Access数据库安全的几个问题


关于本站 | 联系我们 | 业务合作 | 客户案例 | 诚聘英才 | 广告合作 | 收藏本站
海口动网先锋网络科技有限公司版权所有
Copyright © 2000 - 2006 Cndw.Com
中华人民共和国电信与信息服务业务经营许可证编号 琼 ICP 020077