i'm new to MySql(3hours under my belt),just finished reading PHP & MYSQL for dummies 4th Edition and i'm currently to create a database that contains information about shops for practice.
The database i'm trying to create contains information about a list of stores.Each store will contain some basic information about the store,the industry(E.g Clothes, Food) the store is operating in, as well as their inventory.
While i currently have a table containing the store's name,description(which can be a short write up and/or a URL to the store's website), and a store ID(Which serves as the primary key)
create table Merchant(
MerchantID SERIAL,
Industry ENUM("Retail","Dining","Entertainment"),
Name VARCHAR(1000) NOT NULL,
Description VARCHAR(1000),
PRIMARY KEY(MerchantID)
)
Each store will then have multiple categories for what they are selling, and each categories will have multiple items.Would i be right in saying that what i am looking at is a One(Store) to Many(Categories) table linked to a One(Category) to Many(Items) table? The reason being that although the first table(Store to Categories) has a One to Many R/S, the second table(Category to Item) also has a One to Many, and NOT a Many to Many R/S as i am only looking at a singular category which contains multiple items in it.
Table for Categories:
Create table Categories(
CategoryID SERIAL references MerchantID,
Category VARCHAR(50) NOT NULL,
PRIMARY KEY(CategoryID)
)
Table for Items:
Create table Items(
ItemID Serial references CategoryID,
Item VARCHAR(50) NOT NULL,
PRIMARY KEY(ItemID)
)
Is the code above correct? Or do i have to enter all the Primary Keys that are one level above. E.g:
Create table Item(
MerchantID SERIAL,
CategoryID SERIAL,
ItemID SERIAL,
Item VARCHAR(50),
PRIMARY KEY(MerchantID,CategoryID,ItemID)
)
Furthermore, is there any difference between having VARCHAR(50) and VARCHAR(1000) seeing as MYSQL would automatically get rid of all the unused space?Also, is there any way to further optimise the database for performance etc.?