Auto increment table column

后端 未结 4 1586
梦毁少年i
梦毁少年i 2020-11-22 02:35

Using Postgres, I\'m trying to use AUTO_INCREMENT to number my primary key automatically in SQL. However, it gives me an error.

CREATE TABLE Sta         


        
4条回答
  •  囚心锁ツ
    2020-11-22 03:25

    You do not specify which RDBMS you are using, however, in SQL Server you can use this syntax:

    CREATE TABLE [dbo].[Staff]
    (
    [ID] [int] IDENTITY(1,1) NOT NULL,
    [Name] VARCHAR(40) NOT NULL,
    CONSTRAINT [ID] PRIMARY KEY CLUSTERED 
    (
    [ID] ASC
    )WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
    ) ON [PRIMARY]
    
    GO
    

提交回复
热议问题