用 sp_helpindex TABLE就好了。。
用sp_help 'Customer' 查出来的好象是这个表的信息。。

解决方案 »

  1.   

    select 
        d.name 
    from 
        sysindexes a,
        sysobjects b,
        sysindexkeys c,
        syscolumns d
    where 
        c.id = object_id('表名')
        and 
        c.id = b.parent_obj 
        and 
        a.name = b.name 
        and 
        b.xtype='PK' 
        and 
        a.indid = 1
        and 
        d.colid = c.colid 
        and 
        d.id = c.id
      

  2.   

    select 
        d.name 
    from 
        sysindexes a,
        sysobjects b,
        sysindexkeys c,
        syscolumns d
    where 
        c.id = object_id('表名')
        and 
        c.id = b.parent_obj 
        and 
        a.name = b.name 
        and 
        b.xtype='PK' 
        and 
        a.indid = 1
        and 
        d.colid = c.colid 
        and 
        d.id = c.id
      

  3.   

    create table #primary
    (
      a     sysname,
      b     sysname,
      c     sysname,
      d     sysname,
      e     int,
      f     sysname
    )
    insert #primary exec sp_pkeys t_pcdmx#primary中的d列就要楼主要的吧??
      

  4.   

    --得到主键字段名1:
    SELECT TABLE_NAME,COLUMN_NAME FROM INFORMATION_SCHEMA.KEY_COLUMN_USAGE 
    WHERE TABLE_NAME<>'dtproperties'2:
    EXEC sp_pkeys @table_name='表名'3:
    select o.name as 表名,c.name as 字段名,k.colid as 字段序号,k.keyno as 索引顺序,t.name as 类型
    from sysindexes i
    join sysindexkeys k on i.id = k.id and i.indid = k.indid
    join sysobjects o on i.id = o.id
    join syscolumns c on i.id=c.id and k.colid = c.colid
    join systypes t on c.xusertype=t.xusertype
    where o.xtype = 'U'
    and o.name='要查询的表名'
    and exists(select 1 from sysobjects where xtype = 'PK' and parent_obj=i.id and name = i.name)
    order by o.name,k.colid