﻿	--------------------------- Előző Tanév Rekord ID Betétele, ha még nincs ---------------------------
	--------------------------- Előző Tanév Rekord ID Betétele, ha még nincs ---------------------------
DECLARE @sql nvarchar(max) = '';
SELECT  @sql += 'ALTER TABLE dbo.' +  T.TABLE_NAME + '  DROP COLUMN ELOZOTANEVIREKORDID;' + 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 = 'ELOZOTANEVIREKORDID')
  AND T.TABLE_TYPE = 'BASE TABLE';
 
EXEC sp_executesql @sql;  
GO

DECLARE @sql nvarchar(max) = '';
SELECT  @sql += 'ALTER TABLE dbo.' +  T.TABLE_NAME + '  DROP COLUMN ELOZOTANEVIREKORDIDA;' + 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 = 'ELOZOTANEVIREKORDIDA')
  AND T.TABLE_TYPE = 'BASE TABLE'; 
 
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_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';
 
EXEC sp_executesql @sql;  
GO

DECLARE @sql nvarchar(max) = '';
SELECT  @sql += 'ALTER TABLE dbo.' +  T.TABLE_NAME + '  ADD ELOZOTANEVIREKORDIDA 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 = 'ELOZOTANEVIREKORDIDA')
  AND T.TABLE_TYPE = 'BASE TABLE' 
  AND TABLE_SCHEMA = 'dbo';
 
EXEC sp_executesql @sql;  
GO