Say I defined a char column Type. I want to strict its value to say for example (Black, White, Red, Blue) Only...
How can I do that??
All i know, this is easy in Access :P
Say I defined a char column Type. I want to strict its value to say for example (Black, White, Red, Blue) Only...
How can I do that??
All i know, this is easy in Access :P
If there are just a few permitted values then you can use a
CHECK
constraint:If there are more values then you can use a lookup table and a
FOREIGN KEY
constraint:You need a rule on the column
And yes , it's as easy as it is in access.
You should either use a Rule (as was pointed out Rules are now deprecated instead constraints should be used) or a foreign key to a Color table containing the Colors you allow.
A Check constraint can be created like this:
If you want to go with a table, then you should create a 'Color' table with the colorName and an ID. On the table(s) that need the reference you should add a column with the foreign key to the 'Color'-table ID.
To reference the 'Color'-table you have to use a join e.g.
Updated: With Constraint instead of Rule older Databases can still use Rules though (2000).
Hope it helps
One way to do this would be to create a separate table "Type" and put your values there. The table that use to have the Type varchar, would now have a FK TypeID that points to the other table.
This will require an extra join, but will give you control over what strings can be Types.