O
O
Oxoron2015-09-10 19:40:37
Transact SQL
Oxoron, 2015-09-10 19:40:37

How to limit max value of int field in ms sql?

Good evening.
I came across a problem: it is necessary to store a set of int values ​​in the database. They must all be between zero and 10. Can this be done at table creation time?
PS I know about triggers, I can control recording from .NET application. But installation of restriction during design \creation of the table interests.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Andrey Nikiforov, 2015-09-10
@Oxoron

create table numbers (
    number int not null
        check(number >= 1234 and number <= 4523),
    ...
)

create table numbers (
    number int not null,
    check(number >= 1234 and number <= 4523),
    ...
)

create table numbers (
    number int not null,
    constraint number_range_check
        check(number >= 1234 and number <= 4523),
    ...
)

stackoverflow.com/questions/1736630/sql-constraint...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question