Hi ShanmugaPriya,
Try this one.
First, check if there exists any records which have ID equal or greater than 4. If so, then increment their ID values by 1. Then insert the record where its ID = 4.
BEGIN TRANSACTION TRASN_Insert
BEGIN TRY
IF EXISTS (SELECT ID FROM TableName WHERE ID >= 4)
BEGIN
UPDATE TableName
SET ID = ID + 1
WHERE ID >= 4
END
INSERT INTO TableName
(ID)
VALUES
(4)
COMMIT TRANSACTION TRASN_Insert
END TRY
BEGIN CATCH
ROLLBACK TRANSACTION TRASN_Insert
END CATCH
Its protected with a transaction and Try Catch for failure cases also.
Thank you,
RelicV.