求一条SQL语句,需要一个表的字段名和类型及长度
例如在创建表示如下:
create table T1
( ........
Col1 int,
Col2 nvarchar(20),
Col3 varchar(40),
Col4 float,
........
)
求一条SQL语句输出如下内容
1 "Col1,int "
2 "Col2,nvarchar,20 "
3 "Col3,varchar,40 "
4 "Col4,float "
输出字符串时都要把定义时的长度输出.
请问这个SQL语句怎么写?谢谢
------解决方案--------------------create table T1
( Col1 int,
Col2 nvarchar(20),
Col3 varchar(40),
Col4 float
)
select colid 序号, ltrim(a.name)+ ', '+ltrim(b.name)+ ', '+ltrim(a.length) 列名 from syscolumns a inner join systypes b on a.xusertype=b.xusertype where id=object_id( 't1 ')
------解决方案--------------------Select
A.ColID,
A.Name + ', ' + B.Name + ', ' + Rtrim(COLUMNPROPERTY(A.ID, A.Name, 'PRECISION ')) As Name
From SysColumns A
Inner Join Systypes B On A.Xtype = B.XuserType
Where ID = OBJECT_ID(N 'TEST ')