CREATE TABLE [dbo].[AgentAddress]
(
[AgentAddressID] [int] NOT NULL IDENTITY(1, 1),
[AgentFID] [int] NOT NULL,
[AddressTypeFID] [int] NOT 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].[AgentAddress] ADD CONSTRAINT [CK_AgentAddress_AddressType] CHECK (([dbo].[GetAddressTypeName]([AddressTypeFID])='Main'))
GO
ALTER TABLE [dbo].[AgentAddress] ADD CONSTRAINT [PK_AgentAddress] PRIMARY KEY NONCLUSTERED ([AgentAddressID]) WITH (FILLFACTOR=80) ON [PRIMARY]
GO
ALTER TABLE [dbo].[AgentAddress] ADD CONSTRAINT [IX_AgentAddress_Agent] UNIQUE CLUSTERED ([AgentFID], [AddressTypeFID]) WITH (FILLFACTOR=80) ON [PRIMARY]
GO
ALTER TABLE [dbo].[AgentAddress] ADD CONSTRAINT [FK_AgentAddress_AddressType] FOREIGN KEY ([AddressTypeFID]) REFERENCES [dbo].[AddressType] ([AddressTypeID])
GO
ALTER TABLE [dbo].[AgentAddress] ADD CONSTRAINT [FK_AgentAddress_Agent] FOREIGN KEY ([AgentFID]) REFERENCES [dbo].[Agent] ([AgentPriKey]) ON DELETE CASCADE
GO
ALTER TABLE [dbo].[AgentAddress] ADD CONSTRAINT [FK_AgentAddress_CountryCodeStandard] FOREIGN KEY ([CountryCodeStandardFID]) REFERENCES [dbo].[CountryCodeStandard] ([CountryCodeStandardID])
GO
GRANT SELECT ON [dbo].[AgentAddress] TO [MssExec]
GRANT INSERT ON [dbo].[AgentAddress] TO [MssExec]
GRANT DELETE ON [dbo].[AgentAddress] TO [MssExec]
GRANT UPDATE ON [dbo].[AgentAddress] TO [MssExec]
GO