In SQL Server 2005, how do I set a column of integers to ensure values are greater than 0?
This is probably a simple answer but I can't find it. I have a table with a column of integers and I want to ensure that when a row is inserted that the value in this column is greater than zero. I could do this on the code side but thought it would be best to enforce it on the table. Thanks! I was in error with my last comment all is good now. You can use a check constraint on the column. IIRC the syntax for this looks like: create table foo ( [...] ,Foobar int not null check (Foobar > 0) [...] ) As the poster below says (thanks Constantin), you should create the check constraint outside the