-- se crea  la  tabla pro_reporteActividad

if not exists(select * FROM INFORMATION_SCHEMA.TABLES  where Table_Name='pro_reporteActividad')
begin
EXEC _ini_creartabla 'pro_reporteActividad', 1
end

-- se cran los  campos 



if not exists(select * FROM INFORMATION_SCHEMA.COLUMNS  where Table_Name='pro_reporteActividad' and column_name = 'id_actividad' )
begin
alter table [pro_reporteActividad] add [id_actividad] int  not NULL DEFAULT 0
end

if not exists(select * FROM INFORMATION_SCHEMA.COLUMNS  where Table_Name='pro_reporteActividad' and column_name = 'id_SesionActividad' )
begin
alter table [pro_reporteActividad] add [id_SesionActividad] int  not NULL DEFAULT 0
end

if not exists(select * FROM INFORMATION_SCHEMA.COLUMNS  where Table_Name='pro_reporteActividad' and column_name = 'id_ejecutores' )
begin
alter table [pro_reporteActividad] add [id_ejecutores] int  not NULL DEFAULT 0
end


if not exists(select * FROM INFORMATION_SCHEMA.COLUMNS  where Table_Name='pro_reporteActividad' and column_name = 'id_sucursal' )
begin
alter table [pro_reporteActividad] add [id_sucursal] int not NUll DEFAULT 0 
end

if not exists(select * FROM INFORMATION_SCHEMA.COLUMNS  where Table_Name='pro_reporteActividad' and column_name = 'fecha_inicio' )
begin
alter table [pro_reporteActividad] add [fecha_inicio] smalldatetime  null DEFAULT (((1)/(1))/(1900))
end

if not exists(select * FROM INFORMATION_SCHEMA.COLUMNS  where Table_Name='pro_reporteActividad' and column_name = 'duracion' )
begin
alter table [pro_reporteActividad] add [duracion] float  null DEFAULT 0
end


if not exists(select * FROM INFORMATION_SCHEMA.COLUMNS  where Table_Name='pro_reporteActividad' and column_name = 'texto' )
begin
alter table [pro_reporteActividad] add [texto] varchar(3000)  null 
end


if not exists(select * FROM INFORMATION_SCHEMA.COLUMNS  where Table_Name='pro_reporteActividad' and column_name = 'texto' )
begin
alter table [pro_reporteActividad] add [texto] varchar(3000)  null 
end

if not exists(select * FROM INFORMATION_SCHEMA.COLUMNS  where Table_Name='pro_reporteActividad' and column_name = 'porcentaje_avance' )
begin
alter table [pro_reporteActividad] add [porcentaje_avance] float null DEFAULT 0 
end

-- se crean relaciones ---


IF NOT  EXISTS (SELECT * FROM sys.foreign_keys WHERE parent_object_id = OBJECT_ID(N'[dbo].[pro_reporteActividad]') AND object_id = OBJECT_ID(N'[dbo].[FK_pro_reporteActividad_id_actividad]')  )
ALTER TABLE [pro_reporteActividad] ADD CONSTRAINT
	[FK_pro_reporteActividad_id_actividad] FOREIGN KEY
	([id_actividad]) REFERENCES [pro_actividad](id)
	
IF NOT  EXISTS (SELECT * FROM sys.foreign_keys WHERE parent_object_id = OBJECT_ID(N'[dbo].[pro_reporteActividad]') AND object_id = OBJECT_ID(N'[dbo].[FK_pro_reporteActividad_id_SesionActividad]')  )
ALTER TABLE [pro_reporteActividad] ADD CONSTRAINT
	[FK_pro_reporteActividad_id_SesionActividad] FOREIGN KEY
	([id_SesionActividad]) REFERENCES [pro_SesionActividad](id)
	
	
IF NOT  EXISTS (SELECT * FROM sys.foreign_keys WHERE parent_object_id = OBJECT_ID(N'[dbo].[pro_reporteActividad]') AND object_id = OBJECT_ID(N'[dbo].[FK_pro_reporteActividad_id_ejecutores]')  )
ALTER TABLE [pro_reporteActividad] ADD CONSTRAINT
	[FK_pro_reporteActividad_id_ejecutores] FOREIGN KEY
	([id_ejecutores]) REFERENCES [pro_ejecutores](id)
	
	
IF NOT  EXISTS (SELECT * FROM sys.foreign_keys WHERE parent_object_id = OBJECT_ID(N'[dbo].[pro_reporteActividad]') AND object_id = OBJECT_ID(N'[dbo].[FK_pro_reporteActividad_id_sucursal]')  )
ALTER TABLE [pro_reporteActividad] ADD CONSTRAINT
	[FK_pro_reporteActividad_id_sucursal] FOREIGN KEY
	([id_sucursal]) REFERENCES [ter_sucursal](id)