Q: Is it possible to auto increment data type "time(7)" in SQL server? Currently I have a table which contains a row for "time", which have the data type "time(7)". I've made the default value for 05:00:00 since, that's where I wish to start the time. For every entered data in the table, the time have to go "up" by 2 minutes. I was wondering if there is anyway that I can auto increment it, so it automatically increases the time by 2 minutes?
I've tried to look into some of the features in Microsoft SQL Server Management Studio (which I use), but haven't really found a way to auto incremement it, if it's a possibility.

A: *

*Create a trigger that on insert updates inserted value

*Get previous entry and add 2 minutes to new row


Example:
Create TRIGGER updatetime
ON dbo.TimeTable
AFTER INSERT
AS
BEGIN
    SET NOCOUNT ON;

    DECLARE @NewTime time

    SELECT Top 1 @NewTime = DATEADD(MINUTE, 2,tbl.tmt_time)
    FROM (
        SELECT TOP 2 *
        FROM [dbo].[TimeTable]
        ORDER BY tmt_Id DESC) as tbl
    ORDER BY tmt_ID ASC


    UPDATE tm
    SET tmt_time = @NewTime
    FROM [dbo].[TimeTable] tm
        INNER JOIN inserted i ON i.tmt_ID = tm.tmt_ID

END
GO

You could use lag as well instead of the top 1 top 2 select.
This query also adds 2 minutest to your 1st entry. So you may want to seed the first row with your default value.
References:
https://learn.microsoft.com/en-us/sql/t-sql/statements/create-trigger-transact-sql
https://learn.microsoft.com/en-us/sql/t-sql/functions/lag-transact-sql
https://learn.microsoft.com/en-us/sql/t-sql/queries/update-transact-sql
