﻿DECLARE @sql nvarchar(max) = '';
SELECT  @sql += 'ALTER TABLE dbo.' +  T.TABLE_NAME + '  ADD ELOZOTANEVIREKORDID INT;' + char(13) + char(10)
FROM INFORMATION_SCHEMA.TABLES T
WHERE EXISTS (SELECT 1 FROM INFORMATION_SCHEMA.COLUMNS C WHERE C.TABLE_SCHEMA = T.TABLE_SCHEMA AND C.TABLE_NAME = T.TABLE_NAME AND C.COLUMN_NAME = 'C_INTEZMENYID')
  AND NOT EXISTS (SELECT 1 FROM INFORMATION_SCHEMA.COLUMNS C WHERE C.TABLE_SCHEMA = T.TABLE_SCHEMA AND C.TABLE_NAME = T.TABLE_NAME AND C.COLUMN_NAME = 'ELOZOTANEVIREKORDID')
  AND T.TABLE_TYPE = 'BASE TABLE'
  AND TABLE_SCHEMA = 'dbo';

--PRINT @sql;  
EXEC sp_executesql @sql;  
GO

DECLARE @sql nvarchar(max) = '';
SELECT  @sql += 'ALTER TABLE dbo.' +  T.TABLE_NAME + '  ADD ELOZOTANEVIREKORDID INT;' + char(13) + char(10)
FROM INFORMATION_SCHEMA.TABLES T
WHERE EXISTS (SELECT 1 FROM INFORMATION_SCHEMA.COLUMNS C WHERE C.TABLE_SCHEMA = T.TABLE_SCHEMA AND C.TABLE_NAME = T.TABLE_NAME AND C.COLUMN_NAME = 'C_ALINTEZMENYID')
  AND NOT EXISTS (SELECT 1 FROM INFORMATION_SCHEMA.COLUMNS C WHERE C.TABLE_SCHEMA = T.TABLE_SCHEMA AND C.TABLE_NAME = T.TABLE_NAME AND C.COLUMN_NAME = 'ELOZOTANEVIREKORDID')
  AND T.TABLE_TYPE = 'BASE TABLE'
  AND TABLE_SCHEMA = 'dbo';

--PRINT @sql;   
EXEC sp_executesql @sql;  
GO