CREATE TABLE [dbo].[OrderLocations]
(
[OrderLocationID] [int] NOT NULL IDENTITY(1, 1),
[OrderFID] [int] NOT NULL,
[Name] [varchar] (100) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL,
[OrderContactFID] [int] NULL,
[ImportedFlag] [bit] NOT NULL CONSTRAINT [DF_OrderLocations_ImportedFlag] DEFAULT ((0)),
[BuildingFID] [int] NULL,
[CrossStreet] [varchar] (1024) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[ServiceEntrance] [varchar] (1024) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[SiteNote] [varchar] (1024) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[OrderLocationAddressTypeFID] [int] NULL
) ON [PRIMARY]
GO
ALTER TABLE [dbo].[OrderLocations] ADD CONSTRAINT [PK_OrderLocations] PRIMARY KEY CLUSTERED ([OrderLocationID]) ON [PRIMARY]
GO
CREATE NONCLUSTERED INDEX [ix_OrderLocations_Order] ON [dbo].[OrderLocations] ([OrderFID]) ON [PRIMARY]
GO
ALTER TABLE [dbo].[OrderLocations] ADD CONSTRAINT [FK_OrderLocations_BuildingFID] FOREIGN KEY ([BuildingFID]) REFERENCES [dbo].[Buildings] ([BuildingID]) ON DELETE SET NULL
GO
ALTER TABLE [dbo].[OrderLocations] ADD CONSTRAINT [FK_OrderLocations_OrderContactFID] FOREIGN KEY ([OrderContactFID]) REFERENCES [dbo].[OrderContacts] ([OrderContactID]) ON DELETE CASCADE
GO
ALTER TABLE [dbo].[OrderLocations] ADD CONSTRAINT [FK_OrderLocations_OrderFID] FOREIGN KEY ([OrderFID]) REFERENCES [dbo].[Orders] ([PriKey])
GO
ALTER TABLE [dbo].[OrderLocations] ADD CONSTRAINT [FK_OrderLocations_OrderLocationAddressTypeFID] FOREIGN KEY ([OrderLocationAddressTypeFID]) REFERENCES [dbo].[OrderLocationAddressType] ([OrderLocationAddressTypeID])
GO
GRANT SELECT ON [dbo].[OrderLocations] TO [MssExec]
GRANT INSERT ON [dbo].[OrderLocations] TO [MssExec]
GRANT DELETE ON [dbo].[OrderLocations] TO [MssExec]
GRANT UPDATE ON [dbo].[OrderLocations] TO [MssExec]
GO