CREATE TABLE [dbo].[Branch]
(
[BranchID] [varchar] (5) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL,
[Name] [varchar] (30) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL,
[AgentPriKey] [int] NULL,
[Prefix] [varchar] (4) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[Sequence] [int] NULL,
[GLCode] [varchar] (10) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[GLCPriKey] [int] NULL,
[BranchPriKey] [int] NOT NULL IDENTITY(1, 1),
[VLPriKey] [int] NOT NULL,
[CompanyGLCode] [varchar] (10) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[CommonView] [varchar] (4) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[ImageURL] [varchar] (2048) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[DOT] [varchar] (50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[AdvanceCompanyNumber] [varchar] (32) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[AdvanceFTPHostDirectory] [varchar] (64) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[AuthorityTypeFID] [int] NOT NULL,
[SalesTaxCompanyCode] [varchar] (25) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[CostBenefitsPercentage] [decimal] (14, 4) NULL,
[DefaultDriveTime] [decimal] (10, 2) NULL,
[LaborRatingGroupFID] [int] NULL,
[MssTimeZoneFID] [int] NULL,
[EmailFromAddress] [nvarchar] (120) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[EmailFromName] [nvarchar] (120) COLLATE SQL_Latin1_General_CP1_CI_AS NULL
) ON [PRIMARY]
GO
ALTER TABLE [dbo].[Branch] ADD CONSTRAINT [PK_Branch] PRIMARY KEY CLUSTERED ([BranchPriKey]) ON [PRIMARY]
GO
ALTER TABLE [dbo].[Branch] ADD CONSTRAINT [IX_Branch_AgentPriKey] UNIQUE NONCLUSTERED ([AgentPriKey]) ON [PRIMARY]
GO
ALTER TABLE [dbo].[Branch] ADD CONSTRAINT [IX_Branch_BranchID] UNIQUE NONCLUSTERED ([BranchID]) ON [PRIMARY]
GO
CREATE NONCLUSTERED INDEX [IX_Branch_AuthorityType] ON [dbo].[Branch] ([AuthorityTypeFID]) ON [PRIMARY]
GO
ALTER TABLE [dbo].[Branch] ADD CONSTRAINT [FK_BRANCH_Agent] FOREIGN KEY ([AgentPriKey]) REFERENCES [dbo].[Agent] ([AgentPriKey])
GO
ALTER TABLE [dbo].[Branch] ADD CONSTRAINT [FK_Branch_AuthorityType] FOREIGN KEY ([AuthorityTypeFID]) REFERENCES [dbo].[AuthorityTypes] ([AuthPriKey])
GO
ALTER TABLE [dbo].[Branch] ADD CONSTRAINT [FK_BRANCH_GLControl] FOREIGN KEY ([GLCPriKey]) REFERENCES [dbo].[GLControl] ([GLCPriKey])
GO
ALTER TABLE [dbo].[Branch] ADD CONSTRAINT [FK_BRANCH_LaborRatingGroup] FOREIGN KEY ([LaborRatingGroupFID]) REFERENCES [dbo].[LaborRatingGroup] ([LaborRatingGroupID])
GO
ALTER TABLE [dbo].[Branch] ADD CONSTRAINT [FK_branch_MssTimeZone] FOREIGN KEY ([MssTimeZoneFID]) REFERENCES [dbo].[MssTimeZone] ([MssTimeZoneID])
GO
ALTER TABLE [dbo].[Branch] ADD CONSTRAINT [FK_BRANCH_VANLINE] FOREIGN KEY ([VLPriKey]) REFERENCES [dbo].[VanLine] ([VLPriKey])
GO
GRANT SELECT ON [dbo].[Branch] TO [MssExec]
GRANT INSERT ON [dbo].[Branch] TO [MssExec]
GRANT DELETE ON [dbo].[Branch] TO [MssExec]
GRANT UPDATE ON [dbo].[Branch] TO [MssExec]
GO