0

We usually use autoincrement columns to add identifiers to table rows. Those values are generated as positive integers by mysql.

When I want to model a relation between two tables I use columns of type unsigned int to store the foreign keys. unsigned ints can store int values including 0. As 0 is not a valid value for relations I would like to disallow those values.

Question: Is there any way to define a column that can only hold positive integers > 0?

maxhb
  • 8,554
  • 9
  • 29
  • 53
  • Note that "relation" in relational databases refer to tables, not foreign key constraints. Relations between entities are represented by associating the primary keys of the entities in a table. Columns of the same domain in different tables are artifacts of decomposing a relation graph into discrete relations. They don't represent relationships among entities. Foreign key constraints are integrity constraints, not relationships. – reaanb Feb 02 '16 at 09:46
  • What do you want to happen if someone tries to `INSERT` a '0'? – Rick James Feb 03 '16 at 01:36

0 Answers0