IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[ReservationMembership]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[ReservationMembership](
	[ReservationMembershipId] [int] IDENTITY(1,1) NOT NULL,
	[ReferenceNumber] [int] NOT NULL,
	[GuestNumber] [smallint] NOT NULL,
	[ProgramID] [varchar](100) NOT NULL,
	[MembershipID] [varchar](100) NOT NULL,
 CONSTRAINT [PK_ReservationMembership] PRIMARY KEY CLUSTERED 
(
	[ReservationMembershipId] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
END
GO
/****** Object:  Index [IX_ReservationMembership]    Script Date: 23-03-2023 14:11:08 ******/
IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_ID(N'[dbo].[ReservationMembership]') AND name = N'IX_ReservationMembership')
CREATE NONCLUSTERED INDEX [IX_ReservationMembership] ON [dbo].[ReservationMembership]
(
	[ReferenceNumber] ASC,
	[GuestNumber] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
GO
IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_ReservationMembership_Reservations]') AND parent_object_id = OBJECT_ID(N'[dbo].[ReservationMembership]'))
ALTER TABLE [dbo].[ReservationMembership]  WITH CHECK ADD  CONSTRAINT [FK_ReservationMembership_Reservations] FOREIGN KEY([ReferenceNumber], [GuestNumber])
REFERENCES [dbo].[Reservations] ([ReferenceNumber], [GuestNumber])
GO
IF  EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_ReservationMembership_Reservations]') AND parent_object_id = OBJECT_ID(N'[dbo].[ReservationMembership]'))
ALTER TABLE [dbo].[ReservationMembership] CHECK CONSTRAINT [FK_ReservationMembership_Reservations]
GO
