How To Create Table with Identity Column

前端 未结 4 1793
深忆病人
深忆病人 2020-11-27 17:18

I have an existing table that I am about to blow away because I did not create it with the ID column set to be the table\'s Identity column.

Using

4条回答
  •  青春惊慌失措
    2020-11-27 17:45

    This has already been answered, but I think the simplest syntax is:

    CREATE TABLE History (
        ID int primary key IDENTITY(1,1) NOT NULL,
        . . .
    

    The more complicated constraint index is useful when you actually want to change the options.

    By the way, I prefer to name such a column HistoryId, so it matches the names of the columns in foreign key relationships.

提交回复
热议问题