USE [envisage]
Go

if not exists (select * from sys.tables where name='User2GLDepartment' and [object_id] = object_id('User2GLDepartment'))
begin
CREATE TABLE dbo.User2GLDepartment(
	[Id] [uniqueidentifier] NOT NULL,
	[GLDepartmentId] [uniqueidentifier] NOT NULL,
	[UserId] [uniqueidentifier] NOT NULL,
 CONSTRAINT [PK_User2GLDepartment] PRIMARY KEY CLUSTERED 
(
	[Id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]


ALTER TABLE [dbo].[User2GLDepartment]  WITH CHECK ADD  CONSTRAINT [FK_User2GLDepartment_GLDepartment] FOREIGN KEY([GLDepartmentId])
REFERENCES [dbo].[GLDepartment] ([Id])

ALTER TABLE [dbo].[User2GLDepartment] CHECK CONSTRAINT [FK_User2GLDepartment_GLDepartment]

end
GO