那个系统存储过程可以查询出来,谢谢

解决方案 »

  1.   

    create table #t(id int,colid int,datalen bigint)
    exec sp_msforeachtable @command1=N'
    declare @s1 nvarchar(4000),@s2 nvarchar(4000)
    select @s1='''',@s2=''''
    select @s1=@s1+'' union all select ''
    +rtrim(c.id)+'',''
    +rtrim(c.colid)+'',''
    +quotename(c.colid)+'' from #'',
    @s2=@s2+N'',''+quotename(c.colid)+''=max(''+case
    when t.name in(''sql_variant'',''image'',''money'')
    or t.name like ''%text'' 
    or t.name like ''%binary''
    then ''datalength'' else ''len'' end
    +''(''+quotename(c.name)+''))''
    from syscolumns c,systypes t
    where c.xusertype=t.xusertype
    and object_id(''?'')=c.id
    order by colid
    select @s1=stuff(@s1,1,10,''''),
    @s2=stuff(@s2,1,1,'''')
    exec(''select ''+@s2+'' into # from ? insert #t ''+@s1)'
    --,@whereand=' and o.name=''要查询的表'''  --如果只查询指定表,加上此条件SELECT 
    表名=case when a.colorder=1 then d.name else '' end,
    表说明=case when a.colorder=1 then isnull(f.value,'') else '' end,
    字段序号=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'),
    已有数据的最大长度=data.datalen,
    小数位数=isnull(COLUMNPROPERTY(a.id,a.name,'Scale'),0),
    允许空=case when a.isnullable=1 then '√'else '' end,
    默认值=isnull(e.text,''),
    字段说明=isnull(g.[value],'')
    FROM syscolumns a
    inner join #t data on a.id=data.id and a.colid=data.colid
    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 sysproperties g on a.id=g.id and a.colid=g.smallid  
    left join sysproperties f on d.id=f.id and f.smallid=0
    --where d.name='要查询的表'    --如果只查询指定表,加上此条件
    order by a.id,a.colorder
    drop table #t
      

  2.   

    --********************************************************************************************
    --************      表字段大全       整理:sdhdy     日期:2004-01-01   *******************
    --********************************************************************************************
     
     SELECT  
     表名=d.name, 
     表说明=isnull(f.value,''), 
     字段序号=a.colorder, 
     字段名=a.name, 
     标识=case when a.colstat=1 then '√'else '' end, 
     主键=case when exists(select 1 from sysindexes y,sysindexkeys z where y.id=z.id and y.indid=z.indid and z.id=a.id and z.colid=a.colid and y.status & 2948=2048) then '√'else '' end, 
     类型=b.name, 
     占用字节数=a.length, 
     精度=a.prec, 
     小数位数=isnull(a.Scale,0), 
     允许空=case when a.isnullable=1 then '√'else '' end, 
     默认值=isnull(e.text,''), 
     字段说明=isnull(g.[value],'') 
     FROM syscolumns a 
     left join systypes b on a.xtype=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 sysproperties g on a.id=g.id and a.colid=g.smallid  
     left join sysproperties f on a.id=f.id and f.smallid=0  
     where d.name='tablename'  --如果只查询指定表,加上此条件 
     order by a.id,a.colorder 
     
      

  3.   

    select * from syscolumns
      

  4.   

    DECLARE @tableName nvarchar(100)
    SET @tableName ='tab'
    SELECT  (    
           CASE WHEN a.colorder=1 THEN d.name ELSE '' END)表名,
            a.colorder 字段序号, a.name 字段名, 
            (CASE WHEN COLUMNPROPERTY( a.id,a.name,'IsIdentity')=1 THEN '√' ELSE '' END) 标识, 
            (CASE WHEN (    SELECT COUNT(*)     FROM sysobjects     WHERE (name IN               (SELECT name               FROM sysindexes               WHERE (id = a.id) AND (indid IN                         (SELECT indid                         FROM sysindexkeys                       WHERE (id = a.id) AND (colid IN                     (SELECT colid                     FROM syscolumns                     WHERE (id = a.id) AND (name = a.name))))))) AND             (xtype = 'PK'))>0 THEN '√' ELSE '' END) 主键, 
            b.name 类型, 
            a.length 占用字节数, 
            COLUMNPROPERTY(a.id,a.name,'PRECISION') AS 长度, 
            ISNULL(COLUMNPROPERTY(a.id,a.name,'Scale'),0) AS 小数位数, 
            (CASE WHEN a.isnullable=1 THEN '√' ELSE '' END) 允许空, 
            ISNULL(e.text,'') 默认值, ISNULL(g.[value],'') AS 字段说明 
            FROM syscolumns a 
            LEFT JOIN systypes b ON a.xtype=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 sys.extended_properties g  ON a.id=g.major_id AND a.colid = g.major_id WHERE d.name=@tableName 
            ORDER BY a.id,a.colorder 
      

  5.   

    sysproperties 无效,改成extended_properties  说ID 无效