我想插入一條記錄像下面如何在SQL Server中使用2個主鍵創建表?
ID VendorName RequestNo VendorCode ChequeDateSearch Description StoreID
-------------------------------------------------------------------------------------
1 John 1011 1021 2017-10-25 00:00:00.000 descr 6000
2 michael 1011 1022 2017-10-25 00:00:00.000 descr 6000
3 Abraham 1011 1023 2017-10-25 00:00:00.000 descr 6000
注意
它不應該接受相同
RequestNo
重複VendorCode
我的表ID
,RequestNo
和VendorCode
應成爲主鍵。 ID
是自動遞增,以及RequestNo
和VendorCode
是用戶指定
CREATE TABLE [dbo].[CheqVendorSearch](
[ID] [bigint] IDENTITY(1,1) NOT NULL,
[VendorName] [nvarchar](max) NULL,
[RequestNo] [varchar](50) Not NULL,
[VendorCode] [varchar](50) NOT NULL,
[ChequeDateSearch] [datetime] NULL,
[Description] [nvarchar](max) NULL,
[StoreID] [varchar](10) NULL,
PRIMARY KEY CLUSTERED
(
[ID] ASC,
[RequestNo] ASC,
[VendorCode] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF,
ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
但該表受理RequestNo
和重複VendorCode
像下面
ID VendorName RequestNo VendorCode ChequeDateSearch Description StoreID
-------------------------------------------------------------------------------------
1 John 1011 1023 2017-10-25 00:00:00.000 descr 6000
2 michael 1011 1023 2017-10-25 00:00:00.000 descr 6000
3 Abraham 1011 1023 2017-10-25 00:00:00.000 descr 6000