if not exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Location]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
BEGIN
CREATE TABLE [dbo].[Location](
	[Id] [int] IDENTITY(1,1) NOT NULL,
	[LocationName] [varchar](50) NOT NULL,
	[LocationDescription] [varchar](1000) NULL,
	[ExternalId] [int] NULL,
	[SortNumber] [int] NULL,
 CONSTRAINT [PK_Location] PRIMARY KEY CLUSTERED 
(
	[Id] ASC
)
) ON [PRIMARY]
END

if not exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[LocationCustomerXTab]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
BEGIN
CREATE TABLE [dbo].[LocationCustomerXTab](
	[FKLocationID] [int] NOT NULL,
	[FKCustomerNumber] [int] NOT NULL,
 CONSTRAINT [PK_LocationCustomerXTab] PRIMARY KEY CLUSTERED 
(
	[FKLocationID] ASC,
	[FKCustomerNumber] ASC
)
) ON [PRIMARY]


ALTER TABLE [dbo].[LocationCustomerXTab]  WITH CHECK ADD  CONSTRAINT [FK_LocationCustomerXTab_Customer] FOREIGN KEY([FKCustomerNumber])
REFERENCES [dbo].[Customer] ([CustomerNumber])

ALTER TABLE [dbo].[LocationCustomerXTab] CHECK CONSTRAINT [FK_LocationCustomerXTab_Customer]

ALTER TABLE [dbo].[LocationCustomerXTab]  WITH CHECK ADD  CONSTRAINT [FK_LocationCustomerXTab_Location] FOREIGN KEY([FKLocationID])
REFERENCES [dbo].[Location] ([Id])

ALTER TABLE [dbo].[LocationCustomerXTab] CHECK CONSTRAINT [FK_LocationCustomerXTab_Location]
END