how to increment integer Columns value by 1 in SQL

前端 未结 6 1019
青春惊慌失措
青春惊慌失措 2020-12-05 01:50

My questions is

how to increment a column\'s value by 1.

For example, suppose a column ID has values 1,2,3,4, ..

6条回答
  •  [愿得一人]
    2020-12-05 02:26

    You can use IDENTITY which will do this for you.

    CREATE TABLE [dbo].[MyTable](
        [MyTableID] [int] IDENTITY(1,1) NOT NULL,
        -- Other columns
    )
    

    When you insert your first record, you'll get an Id of 1.

提交回复
热议问题