

if not exists(select * FROM INFORMATION_SCHEMA.TABLES  where Table_Name='gen_bodega_usuario' )
EXEC _ini_creartabla 'gen_bodega_usuario', 1
go

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

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

if not exists(select * FROM INFORMATION_SCHEMA.COLUMNS  where Table_Name='gen_bodega_usuario' and column_name = 'sugerir')
begin
alter table [gen_bodega_usuario] add [sugerir] bit NOT NULL DEFAULT 0
end
go
if not exists(select * FROM INFORMATION_SCHEMA.TABLES  where Table_Name='gen_bodega_usuario_aux' )
begin
create table [gen_bodega_usuario_aux] (
uid varchar (500)
,[bodega_usuario_usuario_usuario] varchar (300)
,[bodega_usuario_usuario_usuario_codigo] varchar (100)
,[bodega_usuario_bodega_bodega] varchar (300)
,[bodega_usuario_bodega_bodega_codigo] varchar (100)

)
end


if not exists (select * FROM INFORMATION_SCHEMA.REFERENTIAL_CONSTRAINTS where CONSTRAINT_NAME= 'FK_gen_bodega_usuario_id_bodega')
begin
 ALTER TABLE [gen_bodega_usuario] ADD CONSTRAINT
	FK_gen_bodega_usuario_id_bodega FOREIGN KEY
	([id_bodega]) REFERENCES [gen_bodega]
	(id) ON UPDATE  NO ACTION ON DELETE  NO ACTION 
end
GO
 if not exists (select * FROM INFORMATION_SCHEMA.REFERENTIAL_CONSTRAINTS where CONSTRAINT_NAME= 'FK_gen_bodega_usuario_id_usuario')
begin
 ALTER TABLE [gen_bodega_usuario] ADD CONSTRAINT
	FK_gen_bodega_usuario_id_usuario FOREIGN KEY
	([id_usuario]) REFERENCES [seg_usuario]
	(id) ON UPDATE  NO ACTION ON DELETE  NO ACTION 
end
GO
