user4420906
user4420906

Reputation:

Data validation for a column in SQL Server

I have a table in SQL Server. I have a field in this table and its value should be between 1 and 9. How can I set this constraint to prevent invalid data entries? Providing an error message by message box is preferable for me.

Upvotes: 0

Views: 1344

Answers (1)

Pரதீப்
Pரதீப்

Reputation: 93754

Use Check Constraint to restrict the data inserted into that column.

CREATE TABLE Persons
(
..
field int CHECK (field between 1 and 9)
..
)

If you don't want to allow NULL then make it as NOT NULL column

Upvotes: 2

Related Questions