MSSQL – Trigger for update field copy form others field.

This script is useful when you want update field with a same value from other field.

CREATE TRIGGER[dbo].[trigger_item_download]
ON [dbo].[ILINK_ITEM_DOWNLOAD]
AFTER INSERT
AS
BEGIN
IF EXISTS (SELECT *
FROM inserted)
BEGIN
UPDATE o
SET o.IM_INTERFACE_RECORD_ID = i.RecordNo
FROM [ILINK_UT].[dbo].[ILINK_ITEM_DOWNLOAD] o,
inserted i
WHERE o.RecordNo = i.RecordNo
END
END
GO

The query above mean if you insert into ILINK_ITEM_DOWNLOAD recordNo = 1

then, trigger will update on that rows, field IM_INTERFACE_RECORD_ID = 1

How to configure memory options using SQL Server Management Studio

Hi, today I will share about setting Memory Consume in SQL Server. This feature is one of advantages using MSSQL.

You can change Minimum and Maximum memory without restart the services.

  1. In Object Explorer, right-click a server and select Properties.
  2. Click the Memory node.
  3. Under Server Memory Options, enter the same amount that you want for Minimum server memory and Maximum server memory.

a foreign key constraint fails

In SQL Server, if you got a problem while deleting a rows with error:

Cannot delete or update a parent row: a foreign key constraint fails

The simple way to do is:

SET FOREIGN_KEY_CHECKS=0;

Don’t forget to set it back again after deleting rows.

SET FOREIGN_KEY_CHECKS=1;