if not exists(select 1 from syscolumns where id = object_id('WEB_CONV_DEMITE_WEB_CONV_USU_GLB_USU') and name = 'CD_USU')
begin

	declare @sql varchar(max)
--CRIANDO NOVA COLUNA
	set @sql = 'ALTER TABLE WEB_CONV_DEMITE_WEB_CONV_USU_GLB_USU ADD CD_USU INT NULL DEFAULT ( 0 );'
	
--INSERINGO DADOS
	set @sql = @sql + 'UPDATE A SET A.CD_USU = B.CD_USU '
	set @sql = @sql + 'FROM WEB_CONV_DEMITE_WEB_CONV_USU_GLB_USU A '
	set @sql = @sql + '	 INNER JOIN WEB_CONV_USU_GLB_USU B ON '
	set @sql = @sql + '		A.CD_USU_CONV = B.CD_USU_CONV;'
	

--ALTERANDO COLUNA PARA NOT NULL
	set @sql = @sql + 'ALTER TABLE WEB_CONV_DEMITE_WEB_CONV_USU_GLB_USU ALTER COLUMN CD_USU INT NOT NULL;'	
	

	set @sql = @sql + 'ALTER TABLE [WEB_CONV_DEMITE_WEB_CONV_USU_GLB_USU] DROP CONSTRAINT [FK_WEB_CONV_DEMITE_WEB_CONV_USU_GLB_USU_WEB_CONV_USU_GLB_USU];'
	

	/****** Object:  Index [PK_WEB_CONV_DEMITE_WEB_CONV_USU_GLB_USU]    Script Date: 05/08/2014 15:26:29 ******/
	set @sql = @sql + 'ALTER TABLE [WEB_CONV_DEMITE_WEB_CONV_USU_GLB_USU] DROP CONSTRAINT [PK_WEB_CONV_DEMITE_WEB_CONV_USU_GLB_USU];'
	

	/****** Object:  Index [PK_WEB_CONV_DEMITE_WEB_CONV_USU_GLB_USU]    Script Date: 05/08/2014 15:26:29 ******/
	set @sql = @sql + 'ALTER TABLE [WEB_CONV_DEMITE_WEB_CONV_USU_GLB_USU] ADD  CONSTRAINT [PK_WEB_CONV_DEMITE_WEB_CONV_USU_GLB_USU] PRIMARY KEY CLUSTERED '
	set @sql = @sql + '( '
	set @sql = @sql + '	[CD_CONV_DEMITE] ASC, '
	set @sql = @sql + '	[CD_USU] ASC '
	set @sql = @sql + ')WITH (PAD_INDEX = ON, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, IGNORE_DUP_KEY = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 98) ON [PRIMARY];'
	

	set @sql = @sql + 'ALTER TABLE [WEB_CONV_DEMITE_WEB_CONV_USU_GLB_USU]  WITH CHECK ADD  CONSTRAINT [FK_WEB_CONV_DEMITE_WEB_CONV_USU_GLB_USU_WEB_CONV_USU_GLB_USU] FOREIGN KEY([CD_USU]) '
	set @sql = @sql + 'REFERENCES  [GLB_USU] ([CD_USU]);'
	

	set @sql = @sql + 'ALTER TABLE [dbo].[WEB_CONV_DEMITE_WEB_CONV_USU_GLB_USU] CHECK CONSTRAINT [FK_WEB_CONV_DEMITE_WEB_CONV_USU_GLB_USU_WEB_CONV_USU_GLB_USU];'
	

	set @sql = @sql + 'ALTER TABLE WEB_CONV_DEMITE_WEB_CONV_USU_GLB_USU DROP CONSTRAINT DF_WEB_CONV_DEMITE_WEB_CONV_USU_GLB_USU_CD_USU_CONV;'
	
	EXEC @sql

end

if exists(select 1 from syscolumns where id = object_id('WEB_CONV_DEMITE_WEB_CONV_USU_GLB_USU') and name = 'CD_USU_CONV')
begin

	ALTER TABLE WEB_CONV_DEMITE_WEB_CONV_USU_GLB_USU DROP COLUMN CD_USU_CONV
end
