noon
noon

Reputation: 1

help on database in c#

I have an Sql database in my C# program since c# allows you to build database inside the program. The question can an attribute(column) in a database be a range. for example, can I have attribute for the weight such as one of its values 120-130, so that it's more easy than specifying 10 values.

Upvotes: 0

Views: 77

Answers (2)

Abe Miessler
Abe Miessler

Reputation: 85116

I assume you are talking about the Server Explorer in Visual Studio. If you are talking about a SQL Server database that is being used by your application this can be done using the a constraints.

If you add two, one that checks that Weight > 129 and one that checks that Weight < 131, it should prevent people from entering values outside of those ranges.

That said I would probably enforce this business rule through your C# Application logic rather than in the Database structure.

In other words present people with a drop down list to select from that contains only the range of values that you want. You could do server side validation on the selected values if security is a concern.

Upvotes: 0

Phil Lamb
Phil Lamb

Reputation: 1437

You could use two columns: Min and Max.

 Name   | Min | Max
--------------------
 Item 1 | 120 | 130
          ...

Upvotes: 1

Related Questions