USE [EnVisage]

begin transaction

create table tmp_ProjectAccess(
	[PrincipalId] [uniqueidentifier] NOT NULL,
	[ProjectId] [uniqueidentifier] NOT NULL,
	[Read] [int] NOT NULL,
	[Write] [int] NOT NULL
)

insert into tmp_ProjectAccess
select * from ProjectAccess

ALTER TABLE [dbo].[ProjectAccess] DROP CONSTRAINT [FK_ProjectAccess_Project]

ALTER TABLE [dbo].[ProjectAccess] DROP CONSTRAINT [DF_ProjectAccess_Write]

ALTER TABLE [dbo].[ProjectAccess] DROP CONSTRAINT [DF_ProjectAccess_Read]

/****** Object:  Table [dbo].[ProjectAccess]    Script Date: 10/17/2014 4:23:19 PM ******/
DROP TABLE [dbo].[ProjectAccess]

/****** Object:  Table [dbo].[ProjectAccess]    Script Date: 10/17/2014 4:23:19 PM ******/
CREATE TABLE [dbo].[ProjectAccess](
	[PrincipalId] [uniqueidentifier] NOT NULL,
	[ProjectId] [uniqueidentifier] NOT NULL,
	[Read] [int] NOT NULL,
	[Write] [int] NOT NULL,
 CONSTRAINT [PK_ProjectAccess] PRIMARY KEY CLUSTERED 
(
	[PrincipalId] ASC,
	[ProjectId] 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].[ProjectAccess] ADD  CONSTRAINT [DF_ProjectAccess_Read]  DEFAULT ((0)) FOR [Read]

ALTER TABLE [dbo].[ProjectAccess] ADD  CONSTRAINT [DF_ProjectAccess_Write]  DEFAULT ((0)) FOR [Write]

ALTER TABLE [dbo].[ProjectAccess]  WITH CHECK ADD  CONSTRAINT [FK_ProjectAccess_Project] FOREIGN KEY([ProjectId])
REFERENCES [dbo].[Project] ([Id])

ALTER TABLE [dbo].[ProjectAccess] CHECK CONSTRAINT [FK_ProjectAccess_Project]

insert into ProjectAccess
select * from tmp_ProjectAccess

drop table tmp_ProjectAccess

commit

