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


IF NOT EXISTS(SELECT *FROM [_columnas] WHERE[tabla]='gen_bodega'
      AND [columna]='id_sucursal' AND[mostrarEnGrilla]=1 AND[ordenGrilla]=1AND[requerido]=1 AND[tipo]='int'AND[defecto]=0 AND [tamano] IS NULL)
BEGIN
INSERT INTO [_columnas]
([tabla] ,[columna] ,[mostrarEnGrilla],[ordenGrilla],[requerido] ,[tipo],[defecto],[tamano])
 VALUES
 ('gen_bodega' ,'id_sucursal',1 ,1 ,1 ,'int' ,0 ,null)
END


IF NOT  EXISTS (SELECT * FROM sys.foreign_keys WHERE parent_object_id = OBJECT_ID(N'[dbo].[gen_bodega]') AND object_id = OBJECT_ID(N'[dbo].[FK_gen_bodega_id_sucursal]')  )
 ALTER TABLE [gen_bodega] ADD CONSTRAINT
	FK_gen_bodega_id_sucursal FOREIGN KEY
	([id_sucursal]) REFERENCES [ter_sucursal]
	(id) ON UPDATE  NO ACTION ON DELETE  NO ACTION 
