[dbo].[OrderContactAddress]
CREATE TABLE [dbo].[OrderContactAddress]
(
[OrderContactAddressID] [int] NOT NULL IDENTITY(1, 1),
[OrderContactFID] [int] NOT NULL,
[AddressTypeFID] [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].[OrderContactAddress] ADD CONSTRAINT [CK_OrderContactAddress_MainAddressType] CHECK (([dbo].[GetAddressTypeName]([AddressTypeFID])='Main'))
GO
ALTER TABLE [dbo].[OrderContactAddress] ADD CONSTRAINT [PK_OrderContactAddress] PRIMARY KEY NONCLUSTERED ([OrderContactAddressID]) ON [PRIMARY]
GO
ALTER TABLE [dbo].[OrderContactAddress] ADD CONSTRAINT [IX_OrderContactAddress_OrderContactAddressType] UNIQUE NONCLUSTERED ([OrderContactFID], [AddressTypeFID]) ON [PRIMARY]
GO
ALTER TABLE [dbo].[OrderContactAddress] ADD CONSTRAINT [FK_OrderContactAddress_AddressType] FOREIGN KEY ([AddressTypeFID]) REFERENCES [dbo].[AddressType] ([AddressTypeID])
GO
ALTER TABLE [dbo].[OrderContactAddress] ADD CONSTRAINT [FK_OrderContactAddress_CountryCodeStandard] FOREIGN KEY ([CountryCodeStandardFID]) REFERENCES [dbo].[CountryCodeStandard] ([CountryCodeStandardID])
GO
ALTER TABLE [dbo].[OrderContactAddress] ADD CONSTRAINT [FK_OrderContactAddress_OrderContact] FOREIGN KEY ([OrderContactFID]) REFERENCES [dbo].[OrderContacts] ([OrderContactID]) ON DELETE CASCADE
GO
GRANT SELECT ON [dbo].[OrderContactAddress] TO [MssExec]
GRANT INSERT ON [dbo].[OrderContactAddress] TO [MssExec]
GRANT DELETE ON [dbo].[OrderContactAddress] TO [MssExec]
GRANT UPDATE ON [dbo].[OrderContactAddress] TO [MssExec]
GO