USE [EnVisage]
GO

IF not EXISTS (SELECT * FROM sys.tables where name like 'Template2TemplateGroup')
begin
begin tran
CREATE TABLE [dbo].[Template2TemplateGroup](
	[Id] [uniqueidentifier] NOT NULL,
	[TemplateId] [uniqueidentifier] NOT NULL,
	[TemplateGroupId] [uniqueidentifier] NOT NULL,
	 CONSTRAINT [PK_Template2TemplateGroup] 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].[Template2TemplateGroup] ADD  CONSTRAINT [DF_Template2TemplateGroup_Id]  DEFAULT (newid()) FOR [Id]

	ALTER TABLE [dbo].[Template2TemplateGroup]  WITH CHECK ADD  CONSTRAINT [FK_Template2TemplateGroup_Scenario] FOREIGN KEY([TemplateId])
	REFERENCES [dbo].[Scenario] ([Id])

	ALTER TABLE [dbo].[Template2TemplateGroup] CHECK CONSTRAINT [FK_Template2TemplateGroup_Scenario]

	ALTER TABLE [dbo].[Template2TemplateGroup]  WITH CHECK ADD  CONSTRAINT [FK_Template2TemplateGroup_TemplateGroup] FOREIGN KEY([TemplateGroupId])
	REFERENCES [dbo].[TemplateGroup] ([Id])

	ALTER TABLE [dbo].[Template2TemplateGroup] CHECK CONSTRAINT [FK_Template2TemplateGroup_TemplateGroup]

	commit tran
end