SQL constraint minvalue / maxvalue?

后端 未结 5 1379
故里飘歌
故里飘歌 2020-12-03 02:48

Is there a way to set a SQL constraint for a numeric field that min value should be 1234 and max value should be 4523?

5条回答
  •  执笔经年
    2020-12-03 03:08

    If you are using SQL Server, you want to use a CHECK constraint like this:

    CREATE TABLE foo (
      someint INT NOT NULL CHECK (someint >= 1234 AND someint <= 4523)
    )
    

提交回复
热议问题