怎么给联合主键设置外键啊
有表A(a1,a2,a3)其中(a1,a2)为主键 a1对应表B主键b1 a2对应表C主键c1 在GUI里面怎么设置外键啊
------解决方案--------------------我正好有一个例子和你说的一样,请参考:
CREATE TABLE [dbo].[ContractorMobileService](
[ContractorID] [int] NOT NULL,
[MobileServiceID] [int] NOT NULL,
[Charge] [money] NOT NULL,
CONSTRAINT [PK_ContractorMobileService] PRIMARY KEY CLUSTERED
(
[ContractorID] ASC,
[MobileServiceID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
ALTER TABLE [dbo].[ContractorMobileService] WITH NOCHECK ADD CONSTRAINT [FK_ContractorMobileService_Contractor] FOREIGN KEY([ContractorID])
REFERENCES [dbo].[Contractor] ([ID])
GO
ALTER TABLE [dbo].[ContractorMobileService] CHECK CONSTRAINT [FK_ContractorMobileService_Contractor]
GO
ALTER TABLE [dbo].[ContractorMobileService] WITH NOCHECK ADD CONSTRAINT [FK_ContractorMobileService_MobileService] FOREIGN KEY([MobileServiceID])
REFERENCES [dbo].[MobileService] ([ID])
GO
ALTER TABLE [dbo].[ContractorMobileService] CHECK CONSTRAINT [FK_ContractorMobileService_MobileService]
GO
------解决方案--------------------GUI界面,先右键表B,表C,选择设计,然后选择表B字段b1设置主键,表C字段c1设置主键,然后保存关闭。
右键表A,选择设计,按住shift然后选择a1,a2设置为联合主键,然后右键a1列,选择关系,添加后右面点击表和列规范,弹出界面,左边选择主键表主键列,右面选择本表字段a1即可。
a2同样设置。