ALTER PROCEDURE [dbo].[getDBtableInfoByName]
(
@tableName nvarchar(200)
)
AS
BEGIN
SELECT
表名=d.name,
字段序号=a.colorder,
字段名=a.name,
标识=case when COLUMNPROPERTY( a.id,a.name,'IsIdentity')=1 then '√' else '' end,
主键=case when exists(SELECT 1 FROM sysobjects where xtype='PK' and parent_obj=a.id and name in (
SELECT name FROM sysindexes WHERE indid in(
SELECT indid FROM sysindexkeys WHERE id = a.id AND colid=a.colid
))) then '√' else '' end,
类型=b.name,
占用字节数=a.length,
长度=COLUMNPROPERTY(a.id,a.name,'PRECISION'),
小数位数=isnull(COLUMNPROPERTY(a.id,a.name,'Scale'),0),
允许空=case when a.isnullable=1 then '√' else '' end,
默认值=isnull(e.text,''),
字段说明=isnull(cast(g.PropValue as nvarchar(4000)),'')
FROM syscolumns a
left join systypes b on a.xusertype=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 dbo.sysproperties g on a.colid=g.ColID and g.TableID=a.id
where a.id=Object_Id(@tableName)
order by a.id,a.colorder
END
/* dbo.sysproperties 是sql2000的系统表,在之后的05等版本中无效,所以需要自己再创建如下的视图: */
create VIEW [dbo].[sysproperties]
AS
SELECT
A.name As TableName,
A.id As TableID,
B.Name As ColName,
C.minor_id As ColID,
B.xtype As ColType,
C.name As PropName,
C.Value As PropValue,
C.minor_id AS smallid
FROM sysobjects As A
INNER JOIN syscolumns As B ON A.id = B.id
INNER JOIN sys.extended_properties As C ON (C.major_id = A.id AND C.minor_id = B.colid) OR C.minor_id=0