

--tabla 
if not exists(select * FROM INFORMATION_SCHEMA.TABLES  where Table_Name='alq_detallealquiler_itemdocumento')
EXEC _ini_creartabla 'alq_detallealquiler_itemdocumento',1
GO

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

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

--relaciones

IF NOT  EXISTS (SELECT * FROM sys.foreign_keys WHERE parent_object_id = OBJECT_ID(N'[dbo].[alq_detallealquiler_itemdocumento]') AND object_id = OBJECT_ID(N'[dbo].[FK_alq_detallealquiler_id_itemDocumento]')  )
begin
ALTER TABLE [alq_detallealquiler_itemdocumento] ADD CONSTRAINT
	FK_alq_detallealquiler_id_itemDocumento FOREIGN KEY
	([id_itemDocumento]) REFERENCES [doc_itemDocumento]
	(id) 
ALTER TABLE [dbo].[alq_detallealquiler_itemdocumento] CHECK CONSTRAINT [FK_alq_detallealquiler_id_itemDocumento]
end

IF NOT  EXISTS (SELECT * FROM sys.foreign_keys WHERE parent_object_id = OBJECT_ID(N'[dbo].[alq_detallealquiler_itemdocumento]') AND object_id = OBJECT_ID(N'[dbo].[FK_alq_detallealquiler_id_detallealquiler]')  )
begin
ALTER TABLE [alq_detallealquiler_itemdocumento] ADD CONSTRAINT
	FK_alq_detallealquiler_id_detallealquiler FOREIGN KEY
	([id_detallealquiler]) REFERENCES [equ_detallealquiler]
	(id) 
ALTER TABLE [dbo].[alq_detallealquiler_itemdocumento] CHECK CONSTRAINT [FK_alq_detallealquiler_id_detallealquiler]
end
