﻿PRINT N'Dropping Index [dbo].[T_ESZKOZIGENYLES].[NCI_EszkozIgenyles_AlkalmazottId]...';


GO
DROP INDEX [NCI_EszkozIgenyles_AlkalmazottId]
    ON [dbo].[T_ESZKOZIGENYLES];


GO
PRINT N'Dropping Index [dbo].[T_ESZKOZIGENYLES].[NCI_EszkozIgenyles_GondviseloId]...';


GO
DROP INDEX [NCI_EszkozIgenyles_GondviseloId]
    ON [dbo].[T_ESZKOZIGENYLES];


GO
PRINT N'Dropping Index [dbo].[T_ESZKOZIGENYLES].[NCI_EszkozIgenyles_TanuloId]...';


GO
DROP INDEX [NCI_EszkozIgenyles_TanuloId]
    ON [dbo].[T_ESZKOZIGENYLES];


GO
PRINT N'Dropping Foreign Key [dbo].[FK_EszkozIgenyles_AlkalmazottId_REF_Alkalmazott]...';


GO
ALTER TABLE [dbo].[T_ESZKOZIGENYLES] DROP CONSTRAINT [FK_EszkozIgenyles_AlkalmazottId_REF_Alkalmazott];


GO
PRINT N'Dropping Foreign Key [dbo].[FK_EszkozIgenyles_GondviseloId_REF_Gondviselo]...';


GO
ALTER TABLE [dbo].[T_ESZKOZIGENYLES] DROP CONSTRAINT [FK_EszkozIgenyles_GondviseloId_REF_Gondviselo];


GO
PRINT N'Dropping Foreign Key [dbo].[FK_EszkozIgenyles_TanuloId_REF_Tanulo]...';


GO
ALTER TABLE [dbo].[T_ESZKOZIGENYLES] DROP CONSTRAINT [FK_EszkozIgenyles_TanuloId_REF_Tanulo];


GO
PRINT N'Altering Table [dbo].[T_ESZKOZIGENYLES]...';


GO
ALTER TABLE [dbo].[T_ESZKOZIGENYLES] ALTER COLUMN [C_ALKALMAZOTTID] INT NULL;

ALTER TABLE [dbo].[T_ESZKOZIGENYLES] ALTER COLUMN [C_ASZFELFOGADASIDEJE] DATETIME NULL;

ALTER TABLE [dbo].[T_ESZKOZIGENYLES] ALTER COLUMN [C_GONDVISELOID] INT NULL;

ALTER TABLE [dbo].[T_ESZKOZIGENYLES] ALTER COLUMN [C_TANULOID] INT NULL;


GO
PRINT N'Creating Index [dbo].[T_ESZKOZIGENYLES].[NCI_EszkozIgenyles_AlkalmazottId]...';


GO
CREATE NONCLUSTERED INDEX [NCI_EszkozIgenyles_AlkalmazottId]
    ON [dbo].[T_ESZKOZIGENYLES]([C_ALKALMAZOTTID] ASC);


GO
PRINT N'Creating Index [dbo].[T_ESZKOZIGENYLES].[NCI_EszkozIgenyles_GondviseloId]...';


GO
CREATE NONCLUSTERED INDEX [NCI_EszkozIgenyles_GondviseloId]
    ON [dbo].[T_ESZKOZIGENYLES]([C_GONDVISELOID] ASC);


GO
PRINT N'Creating Index [dbo].[T_ESZKOZIGENYLES].[NCI_EszkozIgenyles_TanuloId]...';


GO
CREATE NONCLUSTERED INDEX [NCI_EszkozIgenyles_TanuloId]
    ON [dbo].[T_ESZKOZIGENYLES]([C_TANULOID] ASC);


GO
PRINT N'Creating Foreign Key [dbo].[FK_EszkozIgenyles_AlkalmazottId_REF_Alkalmazott]...';


GO
ALTER TABLE [dbo].[T_ESZKOZIGENYLES] WITH NOCHECK
    ADD CONSTRAINT [FK_EszkozIgenyles_AlkalmazottId_REF_Alkalmazott] FOREIGN KEY ([C_ALKALMAZOTTID]) REFERENCES [dbo].[T_ALKALMAZOTT] ([ID]);


GO
PRINT N'Creating Foreign Key [dbo].[FK_EszkozIgenyles_GondviseloId_REF_Gondviselo]...';


GO
ALTER TABLE [dbo].[T_ESZKOZIGENYLES] WITH NOCHECK
    ADD CONSTRAINT [FK_EszkozIgenyles_GondviseloId_REF_Gondviselo] FOREIGN KEY ([C_GONDVISELOID]) REFERENCES [dbo].[T_GONDVISELO] ([ID]);


GO
PRINT N'Creating Foreign Key [dbo].[FK_EszkozIgenyles_TanuloId_REF_Tanulo]...';


GO
ALTER TABLE [dbo].[T_ESZKOZIGENYLES] WITH NOCHECK
    ADD CONSTRAINT [FK_EszkozIgenyles_TanuloId_REF_Tanulo] FOREIGN KEY ([C_TANULOID]) REFERENCES [dbo].[T_TANULO] ([ID]);


GO
PRINT N'Checking existing data against newly created constraints';

GO
ALTER TABLE [dbo].[T_ESZKOZIGENYLES] WITH CHECK CHECK CONSTRAINT [FK_EszkozIgenyles_AlkalmazottId_REF_Alkalmazott];

ALTER TABLE [dbo].[T_ESZKOZIGENYLES] WITH CHECK CHECK CONSTRAINT [FK_EszkozIgenyles_GondviseloId_REF_Gondviselo];

ALTER TABLE [dbo].[T_ESZKOZIGENYLES] WITH CHECK CHECK CONSTRAINT [FK_EszkozIgenyles_TanuloId_REF_Tanulo];

GO

EXECUTE dev.uspCreateSchemaViews 'T_ESZKOZIGENYLES'
EXECUTE dev.sp_Global_GenerateAsyncAuditTriggerAll
GO

ALTER QUEUE auditLog.[AuditQueue]
WITH ACTIVATION 
(
  STATUS =  ON,
  PROCEDURE_NAME =  auditLog.usp_AuditProcessing,
  MAX_QUEUE_READERS =  2,
  EXECUTE AS 'Kreta_tech_user'
);
GO

PRINT N'Update complete.'
GO
