You are working on a program for importing an Excel file from a SQL Server database. To read the columns in the database information, looking for a lot of information from the Internet, and finally summed up the more ideal SQL statements, after the execution of the returned columns are: Table name, column name, column type, column length, column description, whether the primary key, Statement as follows:
1 Select sysobjects.name as Tb_name, syscolumns.name as Col_name, systypes.name as Col_type, syscolumns.length as Col_l En, Isnull (sysproperties.value,syscolumns.name) as Col_memo,
2 case is syscolumns.name in
3 (Select primary key =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 Wh Ere 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))
and B.name=sysobjects.name
One)
12 Then 1 Else 0 end as Is_key
a
from Sysobjects,systypes,syscolumns
A left Join sysproperties on (Sysco Lumns. Id = sysproperties.id and
Syscolumns.colid = sysproperties.smallid)
Where (sysobjects.xtype = ' U ' Or S Ysobjects. Xtype = ' V ')
and sysobjects.id = syscolumns.id and Systypes.xtype = Syscolumns.xtype
and Systypes.name <&G T ' SysnAme ' and sysobjects.name like '% ' order by Sysobjects.name, Syscolumns.colid
The result is as shown in figure: