[dbo].[OrderLocationAddress]
CREATE TABLE [dbo].[OrderLocationAddress]
(
[OrderLocationAddressID] [int] NOT NULL IDENTITY(1, 1),
[OrderLocationFID] [int] NOT NULL,
[AddressTypeFID] [int] NOT NULL,
[AddressLocationTypeFID] [int] NULL,
[Address1] [dbo].[Address] NULL,
[Address2] [dbo].[Address] NULL,
[Address3] [dbo].[Address] NULL,
[City] [dbo].[AddressCity] NULL,
[State] [dbo].[AddressState] NULL,
[PostalCode] [dbo].[AddressPostalCode] NULL,
[CountryCodeStandardFID] [int] NULL
) ON [PRIMARY]
GO
ALTER TABLE [dbo].[OrderLocationAddress] ADD CONSTRAINT [CK_OrderLocationAddress_MainAddressType] CHECK (([dbo].[GetAddressTypeName]([AddressTypeFID])='Main'))
GO
ALTER TABLE [dbo].[OrderLocationAddress] ADD CONSTRAINT [PK_OrderLocationAddress] PRIMARY KEY NONCLUSTERED ([OrderLocationAddressID]) ON [PRIMARY]
GO
CREATE NONCLUSTERED INDEX [ix_OrderLocationAddress_OrderLocation] ON [dbo].[OrderLocationAddress] ([OrderLocationFID]) ON [PRIMARY]
GO
ALTER TABLE [dbo].[OrderLocationAddress] ADD CONSTRAINT [FK_OrderLocationAddress_AddressLocationType] FOREIGN KEY ([AddressLocationTypeFID]) REFERENCES [dbo].[AddressLocationType] ([AddressLocationTypeID])
GO
ALTER TABLE [dbo].[OrderLocationAddress] ADD CONSTRAINT [FK_OrderLocationAddress_AddressType] FOREIGN KEY ([AddressTypeFID]) REFERENCES [dbo].[AddressType] ([AddressTypeID])
GO
ALTER TABLE [dbo].[OrderLocationAddress] ADD CONSTRAINT [FK_OrderLocationAddress_CountryCodeStandard] FOREIGN KEY ([CountryCodeStandardFID]) REFERENCES [dbo].[CountryCodeStandard] ([CountryCodeStandardID])
GO
ALTER TABLE [dbo].[OrderLocationAddress] ADD CONSTRAINT [FK_OrderLocationAddress_OrderLocation] FOREIGN KEY ([OrderLocationFID]) REFERENCES [dbo].[OrderLocations] ([OrderLocationID]) ON DELETE CASCADE
GO
GRANT SELECT ON [dbo].[OrderLocationAddress] TO [MssExec]
GRANT INSERT ON [dbo].[OrderLocationAddress] TO [MssExec]
GRANT DELETE ON [dbo].[OrderLocationAddress] TO [MssExec]
GRANT UPDATE ON [dbo].[OrderLocationAddress] TO [MssExec]
GO