Reputation: 10784
To homework, asking me to make a table of a DB, the table corresponds to a branch of a department store, this table must contain the following information:
CREATE TABLE STORE
(
id_store varchar (50),
name_store varchar (50),
city varchar (50),
country varchar (50),
region varchar (50)
);
My question is do we need to have the fields of city, country and region, or by the metadata information I can set a pattern for which that information is provided by the decomposition of the primary key id_state? For example the first 3 digits correspond to the country and the next 3 correspond to the city and so on.
Upvotes: 1
Views: 260
Reputation: 231671
You would never want to create a system where the primary key tries to encode data about other attributes in the row. That is the path to great heartache and much suffering.
SUBSTR
and INSTR
to parse out which country a row is in. That is eminently more difficult to index and for the optimizer to understand than a separate column. It's also much harder to ensure that you don't have 'MEX', 'mex', and 'mx' rows all representing Mexico.Upvotes: 8