CREATE TABLE [dbo].[SysuserBranch]
(
[SysuserBranchPriKey] [int] NOT NULL IDENTITY(1, 1),
[SysuserPriKey] [int] NOT NULL,
[BranchPriKey] [int] NOT NULL,
[DefaultBranch] [smallint] NOT NULL CONSTRAINT [DF_SysuserBranch_DefaultBranch] DEFAULT (1)
) ON [PRIMARY]
GO
ALTER TABLE [dbo].[SysuserBranch] ADD CONSTRAINT [CK_SysuserBranch_DefaultBranch] CHECK (((1)<>[dbo].[CheckDuplicateDefaultBranches]([SysuserPriKey])))
GO
ALTER TABLE [dbo].[SysuserBranch] ADD CONSTRAINT [PK_SysuserBranch] PRIMARY KEY CLUSTERED ([SysuserBranchPriKey]) WITH (FILLFACTOR=80) ON [PRIMARY]
GO
CREATE NONCLUSTERED INDEX [IX_SysuserBranch_BranchPrikey] ON [dbo].[SysuserBranch] ([BranchPriKey]) WITH (FILLFACTOR=80) ON [PRIMARY]
GO
CREATE NONCLUSTERED INDEX [IX_SysUserBranch_SysUser] ON [dbo].[SysuserBranch] ([BranchPriKey], [SysuserPriKey], [SysuserBranchPriKey]) WITH (FILLFACTOR=80) ON [PRIMARY]
GO
CREATE NONCLUSTERED INDEX [IX_SysuserBranch_SysUserPriKey] ON [dbo].[SysuserBranch] ([SysuserPriKey]) WITH (FILLFACTOR=80) ON [PRIMARY]
GO
CREATE STATISTICS [STATS_SysUserBranch_SysUser_2] ON [dbo].[SysuserBranch] ([BranchPriKey], [SysuserBranchPriKey])
GO
CREATE STATISTICS [STATS_SysUserBranch_SysUser_1] ON [dbo].[SysuserBranch] ([BranchPriKey], [SysuserBranchPriKey], [SysuserPriKey])
GO
ALTER TABLE [dbo].[SysuserBranch] ADD CONSTRAINT [FK_SysuserBranch_Branch] FOREIGN KEY ([BranchPriKey]) REFERENCES [dbo].[Branch] ([BranchPriKey])
GO
ALTER TABLE [dbo].[SysuserBranch] ADD CONSTRAINT [FK_SysuserBranch_Sysuser] FOREIGN KEY ([SysuserPriKey]) REFERENCES [dbo].[Sysuser] ([SysUserID])
GO
GRANT SELECT ON [dbo].[SysuserBranch] TO [MssExec]
GRANT INSERT ON [dbo].[SysuserBranch] TO [MssExec]
GRANT DELETE ON [dbo].[SysuserBranch] TO [MssExec]
GRANT UPDATE ON [dbo].[SysuserBranch] TO [MssExec]
GO