IF NOT EXISTS (SELECT * FROM sysobjects WHERE id = object_id(N'[dbo].[pal_LoyaltyMember]')
 AND OBJECTPROPERTY(id, N'IsUserTable') = 1)
BEGIN
	CREATE TABLE [dbo].[pal_LoyaltyMember](
		[recId] [int] IDENTITY(1,1) NOT NULL,
		[name] [varchar](200) NULL,
		[surname] [varchar](200) NULL,
		[idNumber] [varchar](20) NULL,
		[mobileNo] [varchar](20) NULL,
		[email] [varchar](200) NULL,
		[loyaltyStoreId] [int] NULL,
		[loyaltyGroupId] [int] NULL,
		[loyaltyNumber] [varchar](20) NULL,
		[isActive] [bit] NULL,
		[optIn] [bit] NULL,
	 CONSTRAINT [PK_pal_LoyaltyMember] PRIMARY KEY CLUSTERED 
	(
		[recId] 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

IF NOT EXISTS (SELECT * FROM sysobjects WHERE id = object_id(N'[dbo].[pal_LoyaltyGroup]')
 AND OBJECTPROPERTY(id, N'IsUserTable') = 1)
BEGIN
CREATE TABLE [dbo].[pal_LoyaltyGroup](
	[recId] [int] IDENTITY(1,1) NOT NULL,
	[groupName] [varchar](50) NULL,
	[groupCode] [varchar](5) NULL,
	[loyaltyStoreId] [int] NULL,
	[nextSequence] [int] NULL,
	[isActive] [bit] NULL,
 CONSTRAINT [PK_pal_LoyaltyGroup] PRIMARY KEY CLUSTERED 
(
	[recId] 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

IF NOT EXISTS (SELECT * FROM sysobjects WHERE id = object_id(N'[dbo].[pal_LoyaltyStore]')
 AND OBJECTPROPERTY(id, N'IsUserTable') = 1)
BEGIN
CREATE TABLE [dbo].[pal_LoyaltyStore](
	[recId] [int] IDENTITY(1,1) NOT NULL,
	[storeName] [varchar](200) NULL,
	[storeCode] [varchar](10) NULL,
	[isActive] [bit] NULL,
 CONSTRAINT [PK_pal_LoyaltyStore] PRIMARY KEY CLUSTERED 
(
	[recId] 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