﻿ALTER TABLE [dbo].[T_ENTITYATTRIBUTEHISTORY] DROP CONSTRAINT IF EXISTS [FK_402508002_402508000]
GO

ALTER TABLE [dbo].[T_ENTITYATTRIBUTEHISTORY] DROP CONSTRAINT IF EXISTS [FK_402508005_402508003]
GO

DROP INDEX IF EXISTS I_T_402508002_402508000 ON [dbo].[T_ENTITYATTRIBUTEHISTORY]
GO

DROP INDEX IF EXISTS I_T_402508005_402508003 ON [dbo].[T_ENTITYATTRIBUTEHISTORY]
GO


DECLARE @sql nvarchar(max) = ''
SELECT
  @sql += 'ALTER TABLE ' + t.name + ' DROP CONSTRAINT IF EXISTS ' + df.name + ';' + char(13) + char(10)
FROM sys.all_columns c
  INNER JOIN sys.tables t ON c.object_id = t.object_id
  INNER JOIN sys.schemas s ON t.schema_id = s.schema_id
  INNER JOIN sys.default_constraints df ON c.default_object_id = df.object_id
WHERE s.name = 'dbo'
  AND t.name = 'T_ENTITYHISTORY'
  AND c.name IN ('TOROLT', 'SERIAL', 'LASTCHANGED')

EXEC sp_executesql @sql
GO

ALTER TABLE T_ENTITYHISTORY DROP COLUMN IF EXISTS C_SESSIONID
ALTER TABLE T_ENTITYHISTORY DROP COLUMN IF EXISTS C_USERIP
ALTER TABLE T_ENTITYHISTORY DROP COLUMN IF EXISTS MODIFIER
ALTER TABLE T_ENTITYHISTORY DROP COLUMN IF EXISTS CREATOR
ALTER TABLE T_ENTITYHISTORY DROP COLUMN IF EXISTS LASTCHANGED
ALTER TABLE T_ENTITYHISTORY DROP COLUMN IF EXISTS TOROLT
ALTER TABLE T_ENTITYHISTORY DROP COLUMN IF EXISTS SERIAL
ALTER TABLE T_ENTITYHISTORY DROP COLUMN IF EXISTS ELOZOTANEVIREKORDID
ALTER TABLE T_ENTITYHISTORY DROP COLUMN IF EXISTS NNID
GO



DECLARE @sql nvarchar(max) = ''
SELECT
  @sql += 'ALTER TABLE ' + t.name + ' DROP CONSTRAINT IF EXISTS ' + df.name + ';' + char(13) + char(10)
FROM sys.all_columns c
  INNER JOIN sys.tables t ON c.object_id = t.object_id
  INNER JOIN sys.schemas s ON t.schema_id = s.schema_id
  INNER JOIN sys.default_constraints df ON c.default_object_id = df.object_id
WHERE s.name = 'dbo'
  AND t.name = 'T_ENTITYATTRIBUTEHISTORY'
  AND c.name IN ('TOROLT', 'SERIAL', 'LASTCHANGED', 'CREATED')

EXEC sp_executesql @sql
GO

ALTER TABLE T_ENTITYATTRIBUTEHISTORY DROP COLUMN IF EXISTS C_INTEZMENYID
ALTER TABLE T_ENTITYATTRIBUTEHISTORY DROP COLUMN IF EXISTS C_TANEVID
ALTER TABLE T_ENTITYATTRIBUTEHISTORY DROP COLUMN IF EXISTS TOROLT
ALTER TABLE T_ENTITYATTRIBUTEHISTORY DROP COLUMN IF EXISTS SERIAL
ALTER TABLE T_ENTITYATTRIBUTEHISTORY DROP COLUMN IF EXISTS LASTCHANGED
ALTER TABLE T_ENTITYATTRIBUTEHISTORY DROP COLUMN IF EXISTS CREATED
ALTER TABLE T_ENTITYATTRIBUTEHISTORY DROP COLUMN IF EXISTS MODIFIER
ALTER TABLE T_ENTITYATTRIBUTEHISTORY DROP COLUMN IF EXISTS ELOZOTANEVIREKORDID
ALTER TABLE T_ENTITYATTRIBUTEHISTORY DROP COLUMN IF EXISTS NNID
ALTER TABLE T_ENTITYATTRIBUTEHISTORY DROP COLUMN IF EXISTS CREATOR
GO
