I'm not sure of the header question. Just to elaborate.
I have Table Users and have columns:
And change the column Type to Type_id and reference it to User_type Table. And instead of inserting string values ["Admin", "Operator", etc]. I now insert integer 1 for Admin, 2 for Operator, 3 for maintainer.
Hope somebody can enlighten me, I am a beginner in database design.
You're right to question this requirement, since apparently your colleague didn't explain clearly why it was so important.
The fact is there is no rule in database normalization that requires that we use a pseudokey, that is an integer like your example of Type_id
.
It's a good idea to create a lookup table of User_type
so you have a concise list of the user types allowed by your system. If you add a new type, you only need to INSERT a row to that lookup table, and then the Users
table that references the lookup table will be allowed to use the new type.
But there's no reason dictated by rules of normalization that the reference has to be to an integer. You can make the primary key of that lookup table a string.
CREATE TABLE User_type (
Type VARCHAR(10) NOT NULL PRIMARY KEY
);
CREATE TABLE Users (
...
Type VARCHAR(10) NOT NULL,
FOREIGN KEY (Type) REFERENCES User_type(Type)
);
So why did your "someone" tell you that you have to use an integer Type_id
?
Well, there could be reasons, but they're not due to rules of normalization.