CREATE TABLE [dbo].[T]( [id] [int] NOT NULL, [Name] [int] NULL, [qty] [int] NOT NULL, [date] [int] NOT NULL, CONSTRAINT [PK_T] PRIMARY KEY CLUSTERED ( [id] ASC, [qty] ASC, [date] ASC ) ) ON [PRIMARY]GO --主鍵名 select [Name] from sysobjects where object_id('T')=parent_obj and xtype='pk' and type='K'/* Name ------ PK_T */ GO--主鍵欄位 select [Name] from syscolumns Where object_id('T')=ID and colid in ( select colid from sysindexkeys where object_id('T')=ID and indid = (select top 1 indid from sysindexes where object_id('T')=ID and [Name]= (select [Name] from sysobjects where object_id('T')=parent_obj and xtype='PK' and type='K') ) ) /* Name ----- id qty date */ GODrop table T
CREATE TABLE [dbo].[T](
[id] [int] NOT NULL,
[Name] [int] NULL,
[qty] [int] NOT NULL,
[date] [int] NOT NULL,
CONSTRAINT [PK_T] PRIMARY KEY CLUSTERED
(
[id] ASC,
[qty] ASC,
[date] ASC
)
) ON [PRIMARY]GO
--主鍵名
select [Name] from sysobjects
where object_id('T')=parent_obj
and xtype='pk' and type='K'/*
Name
------
PK_T
*/
GO--主鍵欄位
select [Name] from syscolumns Where object_id('T')=ID
and colid in
(
select colid from sysindexkeys
where object_id('T')=ID
and indid = (select top 1 indid from sysindexes where object_id('T')=ID and [Name]= (select [Name] from sysobjects
where object_id('T')=parent_obj
and xtype='PK' and type='K') )
) /*
Name
-----
id
qty
date
*/
GODrop table T