USE [EnVisage]
GO

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

begin transaction
	CREATE TABLE [dbo].[User2Team](
		[Id] [uniqueidentifier] NOT NULL,
		[UserId] [nvarchar](128) NOT NULL,
		[TeamId] [uniqueidentifier] NOT NULL,
	 CONSTRAINT [PK_User2Team] 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].[User2Team] ADD  CONSTRAINT [DF_User2Team_Id]  DEFAULT (newid()) FOR [Id]
	GO

	ALTER TABLE [dbo].[User2Team]  WITH CHECK ADD  CONSTRAINT [FK_User2Team_AspNetUsers] FOREIGN KEY([UserId])
	REFERENCES [dbo].[AspNetUsers] ([Id])
	GO

	ALTER TABLE [dbo].[User2Team] CHECK CONSTRAINT [FK_User2Team_AspNetUsers]
	GO

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

	ALTER TABLE [dbo].[User2Team] CHECK CONSTRAINT [FK_User2Team_Team]
	GO

commit transaction	