CREATE TABLE [dbo].[XtraStopAddress]
(
[XtraStopAddressID] [int] NOT NULL IDENTITY(1, 1),
[XtraStopFID] [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] NOT NULL,
[AddressLocationTypeFID] [int] NULL,
[SPLC] [int] NULL
) ON [PRIMARY]
GO
ALTER TABLE [dbo].[XtraStopAddress] ADD CONSTRAINT [CK_XtraStopAddress_AddressType] CHECK (([dbo].[GetAddressTypeName]([AddressTypeFID])='Main'))
GO
ALTER TABLE [dbo].[XtraStopAddress] ADD CONSTRAINT [PK_XtraStopAddress] PRIMARY KEY NONCLUSTERED ([XtraStopAddressID]) WITH (FILLFACTOR=80) ON [PRIMARY]
GO
ALTER TABLE [dbo].[XtraStopAddress] ADD CONSTRAINT [IX_XtraStopAddress_AddressType] UNIQUE NONCLUSTERED ([XtraStopFID], [AddressTypeFID]) WITH (FILLFACTOR=80) ON [PRIMARY]
GO
ALTER TABLE [dbo].[XtraStopAddress] ADD CONSTRAINT [FK_XtraStopAddress_AddressLocationType] FOREIGN KEY ([AddressLocationTypeFID]) REFERENCES [dbo].[AddressLocationType] ([AddressLocationTypeID])
GO
ALTER TABLE [dbo].[XtraStopAddress] ADD CONSTRAINT [FK_XtraStopAddress_AddressType] FOREIGN KEY ([AddressTypeFID]) REFERENCES [dbo].[AddressType] ([AddressTypeID])
GO
ALTER TABLE [dbo].[XtraStopAddress] ADD CONSTRAINT [FK_XtraStopAddress_CountryCodeStandard] FOREIGN KEY ([CountryCodeStandardFID]) REFERENCES [dbo].[CountryCodeStandard] ([CountryCodeStandardID])
GO
ALTER TABLE [dbo].[XtraStopAddress] ADD CONSTRAINT [FK_XtraStopAddress_XtraStop] FOREIGN KEY ([XtraStopFID]) REFERENCES [dbo].[XtraStop] ([PriKey]) ON DELETE CASCADE
GO
GRANT SELECT ON [dbo].[XtraStopAddress] TO [MssExec]
GRANT INSERT ON [dbo].[XtraStopAddress] TO [MssExec]
GRANT DELETE ON [dbo].[XtraStopAddress] TO [MssExec]
GRANT UPDATE ON [dbo].[XtraStopAddress] TO [MssExec]
GO