|
Sqlserver中的一些技巧(1)
获取一个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
|