




-- se crea tabla grupo
if not exists(select * FROM INFORMATION_SCHEMA.TABLES  where Table_Name='pro_GrupoSesion')
begin
EXEC _ini_creartabla 'pro_GrupoSesion', 1
end

-- se crea la tabla sesion actividad
if not exists(select * FROM INFORMATION_SCHEMA.TABLES  where Table_Name='pro_SesionActividad')
begin
EXEC _ini_creartabla 'pro_SesionActividad', 1
end



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


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

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

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

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


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

-- se crean las foraneas 



IF NOT  EXISTS (SELECT * FROM sys.foreign_keys WHERE parent_object_id = OBJECT_ID(N'[dbo].[pro_SesionActividad]') AND object_id = OBJECT_ID(N'[dbo].[FK_pro_SesionActividad_id_actividad]')  )
ALTER TABLE [pro_SesionActividad] ADD CONSTRAINT
	[FK_pro_SesionActividad_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_SesionActividad]') AND object_id = OBJECT_ID(N'[dbo].[FK_pro_SesionActividad_id_ejecutores]')  )
ALTER TABLE [pro_SesionActividad] ADD CONSTRAINT
	[FK_pro_SesionActividad_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_SesionActividad]') AND object_id = OBJECT_ID(N'[dbo].[FK_pro_SesionActividad_id_GrupoSesion]')  )
ALTER TABLE [pro_SesionActividad] ADD CONSTRAINT
	[FK_pro_SesionActividad_id_GrupoSesion] FOREIGN KEY
	([id_GrupoSesion]) REFERENCES [pro_GrupoSesion](id)