SQL Server 2008 R2:纯SQL查看数据库描述文档

本文提供了一个SQL查询语句,用于查看数据库中表的详细结构、序号、名称、描述、标识、主键、类型、占用字节数、长度、小数位数、是否允许为空、默认值和字段说明。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

/***********************************
描述:纯SQL查看数据库描述文档
作者:jehn
联系:jehn@foxmail.com
时间:2011-12-07 14:33:30
************************************/

SELECT

(case when a.colorder=1 then
(
select CAST(表序号 as nvarchar) from
(SELECT d.name,
row_number() over(order by d.name) 表序号
FROM syscolumns a join sysobjects d on a.id=d.id and d.xtype='U' and d.name<>'dtproperties'
where a.colorder=1) as tmp where name=d.name
)
else '' end) 表序号,
(case when a.colorder=1 then d.name else '' end) 表名,
(case when a.colorder=1 then
(
select value from sys.extended_properties where minor_id=0 and major_id= OBJECT_ID(d.name)
) else '' end) 表描述,
a.colorder 字段序号,
a.name 字段名,
(case when COLUMNPROPERTY( a.id,a.name,'IsIdentity')=1 then '√'else '' end) 标识,
(case when (SELECT count(*)
FROM sysobjects
WHERE (name in (SELECT name
FROM sysindexes
WHERE (id = a.id) AND (indid in (SELECT indid
FROM sysindexkeys
WHERE (id = a.id) AND (colid in (SELECT colid
FROM syscolumns
WHERE (id = a.id) AND (name = a.name)
)
)
)
)
)
) AND (xtype = 'PK')
) > 0 then '√' else '' end) 主键,
b.name 类型,
a.length 占用字节数,
COLUMNPROPERTY(a.id,a.name,'PRECISION') as 长度,
--isnull(COLUMNPROPERTY(a.id,a.name,'Scale'),0) as 小数位数,
COLUMNPROPERTY(a.id,a.name,'Scale') 小数位数,
(case when a.isnullable=1 then '√'else '' end) 允许空,
isnull(e.text,'') 默认值,
isnull(g.[value],'') AS 字段说明

FROM syscolumns a
left join systypes b on a.xtype=b.xusertype
inner join sysobjects d on a.id=d.id and d.xtype='U' and d.name<>'dtproperties'
left join syscomments e on a.cdefault=e.id
left join sys.extended_properties g on a.id=g.major_id AND a.colid = g.minor_id --where d.name='T_SickRoom'
order by d.name,a.colorder

------where d.name='T_SickRoom'也可以指定单张表

中文名: SQL Server 2008 R2详解手册 原名: Microsoft SQL Server 2008 R2 Unleashed 作者: Ray Rankins Paul Bertucci Chris Gallelli Alex T.Silverstein 资源格式: PDF 版本: 影印版 出版社: Sams书号: 978-0672330568发行时间: 2010年09月26日 地区: 美国 语言: 英文 简介: 内容简介: Microsoft SQL Server 2008 R2 Unleashed includes full coverage of SQL Server 2008 in addition to R2 coverage This is the industry the most comprehensive and useful guide to SQL Server 2008 and 2008 R2. It presents start-to-finish coverage of SQL Server core database server and management capabilities, plus complete introductions to Integration, Reporting, and Analysis Services, application development, and much more. Four expert SQL Server administrators, developers, and consultants have packed this book with real-world information, tips, guidelines, and samples drawn from their own extensive experience creating and managing complex database solutions. Writing for intermediate-to-advanced-level SQL Server professionals, they focus on the product most complex and powerful capabilities, and its newest tools and features. For example, you will find invaluable information on administering SQL Server more efficiently, analyzing and optimizing queries, implementing data warehouses, ensuring high availability, and tuning performance. The accompanying CD-ROM contains an extraordinary library of practical tools and information including sample databases and all code examples. Whether you’re responsible for SQL Server 2008 analysis, design, implementation, support, administration, or troubleshooting, no other book offers you this much value. * Understand the Microsoft SQL Server 2008 environment, R2 for newest features, and each edition capabilities * Manage SQL Server 2008 more effectively with SQL Server Management Studio, the SQLCMD command-line query tool, and Powershell * Efficiently manage security, users, backup/restore, replication, Database Mail, and database objects from tables and indexes to stored procedures and triggers * Increase availability with clustering, database mirroring, and other features * Use new Policy-Based Management to centrally configure and operate SQL Server throughout the organization * Use SQL Server Profiler to capture queries and identify bottlenecks * Improve performance by optimizing queries, design more effective databases, and manage workloads with the new Resource Governor * Develop applications using SQL Server 2008 enhancements to T-SQL and SQLCLR, .NET integration, LINQ to SQL, XML, and XQuery 作者介绍: Ray Rankins, president of Gotham Consulting Services, has worked with Sybase and Microsoft SQL Server for more than 23 years and is coauthor of Sybase SQL Server Unleashed, Microsoft SQL Server 2000 Unleashed, and Microsoft SQL Server 2005 Unleashed. Paul Bertucci, founder of Database Architechs, has more than 30 years of experience in database design, architecture, replication, tuning, integration, and high availability. Chris Gallelli, president of CGAL Consulting Services, specializes in database administration, tuning, and programming. Alex T. Silverstein is managing principal and chief architect of Unified Digital Group, LLC, a developer of custom SQL Server and Microsoft .NET solutions. 目录: Introduction Part I Welcome to Microsoft SQL Server 1. SQL Serve 2008 Overview 2. What’s new in SQL Serve 2008 3. Examples of SQL Server Implementations Part II SQL Server Tools and Utilities 4. SQL Server Management Studio 5. SQL Server Command-Line Utilities 6. SQL Server Profiler Part III SQL Server Administration 7. SQL Server System and Database Administration 8. Installing SQL Serve 2008 9. Upgrading to SQL Serve 2008 10. Client Installation and Configuration 11. Security and User Administration ………
aclui.CHM 访问控制 ad_ds.CHM Active Directory 域服务 adam.CHM Active Directory 轻型目录服务 adfs.CHM Active Directory 联合身份验证服务 adsiedit.CHM ADSI 编辑器 applocker_help.CHM Windows AppLocker appserver.CHM 应用程序服务器 authfw.CHM 具有高级安全性的 Windows 防火墙 authm.CHM 授权管理器 backup.CHM Windows Server Backup bitssrv.CHM 后台智能文件传送服务 (BITS) certmgr.CHM 证书 certsvr.CHM Active Directory 证书服务 certtmpl.CHM 证书模板 cliconf.chm SQL Server 客户端网络实用工具 cluadmin.CHM 故障转移群集 cmak_ops.CHM 连接管理器管理工具包 comexp.CHM 组件服务管理 connmgr.CHM 连接管理器 da_snap.CHM DirectAccess desktopexp.CHM 桌面体验概述 devmgr.CHM 设备管理器 dfs2.CHM DFS 管理 dhcp.CHM 动态主机配置协议 (DHCP) diskmgt.CHM 磁盘管理 dnsmgr.CHM 域名系统 domadmin.CHM Active Directory 域和信任关系 dsac.CHM Active Directory 管理中心 dsadmin.CHM Active Directory 用户和计算机 dssite.CHM Active Directory 站点和服务 eventviewer.CHM 事件查看器 faxcons.CHM 传真服务管理器 features.CHM Windows Server 2008 R2 中的可用功能 file_srv.CHM 共享文件夹 fsm.CHM 文件服务 fsrm.CHM 文件服务器资源管理器 gpedit.CHM 本地组策略编辑器 gpmc.CHM 组策略管理控制台 hra.CHM 健康注册机构 ieakmmc.CHM Internet Explorer 维护 iismmc.CHM Internet 信息服务(IIS)6.0管理器 inetsrvmmc.CHM Internet 信息服务(IIS)管理器 ipsecmonitor.CHM IPSec监视器 ...
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值