CREATE TABLE [dbo].[ProfileAddress]
(
[ProfileAddressID] [int] NOT NULL IDENTITY(1, 1),
[ProfileFID] [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].[ProfileAddress] ADD CONSTRAINT [CK_ProfileAddress_AddressType] CHECK (([dbo].[GetAddressTypeName]([AddressTypeFID])='Main'))
GO
ALTER TABLE [dbo].[ProfileAddress] ADD CONSTRAINT [PK_ProfileAddress] PRIMARY KEY NONCLUSTERED ([ProfileAddressID]) WITH (FILLFACTOR=80) ON [PRIMARY]
GO
ALTER TABLE [dbo].[ProfileAddress] ADD CONSTRAINT [IX_ProfileAddress_AddressType] UNIQUE NONCLUSTERED ([ProfileFID], [AddressTypeFID]) WITH (FILLFACTOR=80) ON [PRIMARY]
GO
ALTER TABLE [dbo].[ProfileAddress] ADD CONSTRAINT [FK_ProfileAddress_AddressType] FOREIGN KEY ([AddressTypeFID]) REFERENCES [dbo].[AddressType] ([AddressTypeID])
GO
ALTER TABLE [dbo].[ProfileAddress] ADD CONSTRAINT [FK_ProfileAddress_CountryCodeStandard] FOREIGN KEY ([CountryCodeStandardFID]) REFERENCES [dbo].[CountryCodeStandard] ([CountryCodeStandardID])
GO
ALTER TABLE [dbo].[ProfileAddress] ADD CONSTRAINT [FK_ProfileAddress_Profile] FOREIGN KEY ([ProfileFID]) REFERENCES [dbo].[Profiles] ([ProfileID]) ON DELETE CASCADE
GO
GRANT SELECT ON [dbo].[ProfileAddress] TO [MssExec]
GRANT INSERT ON [dbo].[ProfileAddress] TO [MssExec]
GRANT DELETE ON [dbo].[ProfileAddress] TO [MssExec]
GRANT UPDATE ON [dbo].[ProfileAddress] TO [MssExec]
GO