正在作一个关于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
Java Asp PHP .Net XML C/C++ CGI VB Jsp J2ee J2se J2me EJB Servlet Tomcat Resin Struts Weblogic Eclipse ANT GUI JMS Web servise IDEA Webphere Hibernate Spring Jboss Applet Swing Socket Javamail Perl Ajax P2P 安全 模式 框架 测试 开源 游戏
Windows XP Windows 2000 Windows 2003 Windows Me Windows 9.x Linux UNIX 注册表 操作系统 服务器 应用服务器