USE [EnVisage]
GO

IF (EXISTS (SELECT * 
    FROM INFORMATION_SCHEMA.TABLES where
    TABLE_NAME = 'Team2Scenario'))
	set noexec on

begin transaction

CREATE TABLE [dbo].[Team2Scenario](
	[Id] [uniqueidentifier] NOT NULL,
	[ScenarioId] [uniqueidentifier] NOT NULL,
	[TeamId] [uniqueidentifier] NOT NULL,
	[Allocation] [int] NOT NULL,
 CONSTRAINT [PK_Team2Scenario] 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]

GO

ALTER TABLE [dbo].[Team2Scenario] ADD  CONSTRAINT [DF_Team2Scenario_Id]  DEFAULT (newid()) FOR [Id]
GO

ALTER TABLE [dbo].[Team2Scenario] ADD  CONSTRAINT [DF_Team2Scenario_Allocation]  DEFAULT ((0)) FOR [Allocation]
GO

ALTER TABLE [dbo].[Team2Scenario]  WITH CHECK ADD  CONSTRAINT [FK_Team2Scenario_Scenario] FOREIGN KEY([ScenarioId])
REFERENCES [dbo].[Scenario] ([Id])
GO

ALTER TABLE [dbo].[Team2Scenario] CHECK CONSTRAINT [FK_Team2Scenario_Scenario]
GO

ALTER TABLE [dbo].[Team2Scenario]  WITH CHECK ADD  CONSTRAINT [FK_Team2Scenario_Team] FOREIGN KEY([TeamId])
REFERENCES [dbo].[Team] ([Id])
GO

ALTER TABLE [dbo].[Team2Scenario] CHECK CONSTRAINT [FK_Team2Scenario_Team]
GO

commit transaction
