n-m

DROP TABLE Product;
DROP TABLE ProductCategory;
DROP TABLE Category;

CREATE TABLE Product (
  productId INT NOT NULL PRIMARY KEY,
  name VARCHAR(40) NOT NULL,
  description VARCHAR(100) NULL,
  price DECIMAL(7,2),
  weight FLOAT(5,4) NULL
);

CREATE TABLE ProductCategory (
  productID INT NOT NULL,
  categoryID INT NOT NULL,
  PRIMARY KEY (productID, categoryID)
);

CREATE TABLE Category (
  categoryID INT NOT NULL PRIMARY KEY,
  name VARCHAR(40),
  description VARCHAR (100) NULL
);

INSERT INTO Product (productId, name, price) VALUES
  (1, \’Mouse\’, 9.99),
  (2, \’External HDD\’, 9.99),
  (3, \’Keyboard\’, 9.99),
  (4, \’Headphones\’, 9.99);
 
 
INSERT INTO Category (categoryID, name) VALUES
  (1, \’Wireless\’),
  (2, \’Wired\’),
  (3, \’Bluetooth\’),
  (4, \’USB\’),
  (5, \’PS/2\’),
  (6, \’Radio\’),
  (7, \’IR\’);

 

Leave a Reply

Your email address will not be published. Required fields are marked *