I need to create a database which stores details products, Manufactures,Suppliers. So initially I divided Products into categories and subcategories.
These are the tables I created.
Manufacturer, Category, Sub_Category, Products,
ProductSpecs, ProductAvailability, Supplier
- Manufacturer table contains Brand Details (Ex: Apple,Windows..etc).
- Supplier table should contain supplier details and price they are offering.
- Category contains provides details like Electronics, Sports...etc.
- Subcategory table should contains subcategories like Electronics(Mobiles,Laptops...).
- Products table have only basic product details like ID,Name.
- ProductSpecs contains specifications. Based on product we should have separate separate table for each subcategory.
- ProductAvailability should contains product price and availability.
I am not good at database design. But managed to create the below one. Could you please anyone review this? Please help me if it needs any corrections.
CREATE TABLE Supplier
(
SupplierID INT IDENTITY(1,1) NOT NULL PRIMARY KEY,
SupplierName VARCHAR(30) NOT NULL DEFAULT '',
SupplierTag VARCHAR(30) NOT Null DEFAULT '',
);
CREATE TABLE Category
(
CategoryID INT IDENTITY(1,1) NOT NULL PRIMARY KEY,
CategoryName VARCHAR(30) NOT NULL DEFAULT '',
CreatedBy VARCHAR(30) NOT NULL DEFAULT '',
CreatedOn DATETIME NOT NULL
);
CREATE TABLE Sub_Category
(
SubCategoryID INT IDENTITY(1,1) NOT NULL PRIMARY KEY,
SubCategoryName VARCHAR(30) NOT NULL,
CategoryID INT FOREIGN KEY REFERENCES CATEGORY(CategoryID),
CreatedBy VARCHAR(30) NOT NULL,
CreatedOn DATETIME NOT NULL
);
CREATE TABLE Manufacturer
(
ManufacturerID INT IDENTITY(1,1) NOT NULL PRIMARY KEY,
ManufacturerName VARCHAR(30) NOT NULL DEFAULT '',
SubCategoryID INT FOREIGN KEY REFERENCES SUB_CATEGORY(SubCategoryID),
);
CREATE TABLE Products
(
ProductID INT IDENTITY(1,1) NOT NULL PRIMARY KEY,
ProductName VARCHAR(50) NOT NULL DEFAULT '',
CategoryID INT FOREIGN KEY REFERENCES CATEGORY(CategoryID),
SubCategoryID INT FOREIGN KEY REFERENCES SUB_CATEGORY(SubCategoryID),
ManufacturerID INT FOREIGN KEY REFERENCES Manufacturer(ManufacturerID)
);
CREATE TABLE ProductSpecs
(
RowID INT IDENTITY(1,1) NOT NULL PRIMARY KEY,
ProductID INT FOREIGN KEY REFERENCES Products(ProductID),
SubCategoryID INT FOREIGN KEY REFERENCES SUB_CATEGORY(SubCategoryID),
ProductSpec1 VARCHAR(30),
ProductSpec2 VARCHAR(30),
ProductSpec3 VARCHAR(30),
)
CREATE TABLE ProductAvailability
(
RowID INT IDENTITY(1,1) NOT NULL PRIMARY KEY,
ProductID INT FOREIGN KEY REFERENCES Products(ProductID),
SupplierID INT FOREIGN KEY REFERENCES Supplier(SupplierID),
SupplierWEB Varchar(30) NOT NULL,
ProductPrice decimal(6,2) NOT NULL,
)
