论坛交流
首页办公自动化| 网页制作| 平面设计| 动画制作| 数据库开发| 程序设计| 全部视频教程
应用视频: Windows | Word2007 | Excel2007 | PowerPoint2007 | Dreamweaver 8 | Fireworks 8 | Flash 8 | Photoshop cs | CorelDraw 12
编程视频: C语言视频教程 | HTML | Div+Css布局 | Javascript | Access数据库 | Asp | Sql Server数据库Asp.net  | Flash AS
当前位置 > 文字教程 > Sql Server教程
Tag:注入,存储过程,分页,安全,优化,加密,索引,日志,压缩,base64,函数,内存,PDF,迁移,结构,破解,编译,配置,进程,分词,触发器,socket,安装,sqlserver2000,sqlserver2005,sqlserver2008,视频教程

将SQL Server中所有表的列信息显示出来

文章类别:Sql Server | 发表日期:2008-10-5 21:27:40

 正在作一个关于SQL SERVER数据库导入Excel文件的程序,要读取数据库中的列的信息,从网上找了很多资料,终于总结出来比较理想的sql语句,执行后返回的列分别是:表名、列名、列类型、列长度、列描述、是否主键,语句如下:



1 Select Sysobjects.Name As Tb_name, Syscolumns.Name As Col_name, Systypes.Name As Col_type, Syscolumns.Length As Col_len, Isnull(Sysproperties.Value,Syscolumns.Name) As Col_memo,
2 Case When Syscolumns.Name In
3 (Select 主键=A.Name
4 From Syscolumns A
5 Inner Join Sysobjects B On A.Id=B.Id And B.Xtype='U' And B.Name<>'Dtproperties'
6 Where Exists(Select 1 From Sysobjects Where Xtype='Pk' And Name In (
7 Select Name From Sysindexes Where Indid In(
8 Select Indid From Sysindexkeys Where Id = A.Id And Colid=A.Colid
9 )))
10 And B.Name=Sysobjects.Name
11 )
12 Then 1 Else 0 End As Is_key
13
14 From Sysobjects,Systypes,Syscolumns
15 Left Join Sysproperties On (Syscolumns.Id = Sysproperties.Id And
16 Syscolumns.Colid = Sysproperties.Smallid)
17
18 Where (Sysobjects.Xtype ='U' Or Sysobjects.Xtype ='V')
19 And Sysobjects.Id = Syscolumns.Id And Systypes.Xtype = Syscolumns.Xtype
20 And Systypes.Name <> 'Sysname' And Sysobjects.Name Like '%' Order By Sysobjects.Name, Syscolumns.Colid


结果如图:


视频教程列表
文章教程搜索
 
Sql Server推荐教程
Sql Server热门教程
看全部视频教程
购买方式/价格
购买视频教程: 咨询客服
tel:15972130058