CREATE DATABASE IF NOT EXISTS TiendaFabricantes;
USE TiendaFabricantes;

SET FOREIGN_KEY_CHECKS = 0;
DROP TABLE IF EXISTS Productos;
DROP TABLE IF EXISTS Fabricantes;
SET FOREIGN_KEY_CHECKS = 1;

CREATE TABLE Fabricantes (
    IdFabricante INT PRIMARY KEY AUTO_INCREMENT,
    NombreFabricante VARCHAR(60) NOT NULL,
    Pais VARCHAR(40)
);

CREATE TABLE Productos (
    IdProducto INT PRIMARY KEY AUTO_INCREMENT,
    NombreProducto VARCHAR(70) NOT NULL,
    Categoria VARCHAR(40) NOT NULL,
    Precio DECIMAL(10,2) NOT NULL,
    Existencias INT NOT NULL,
    IdFabricante INT NULL,
    CONSTRAINT FK_Productos_Fabricantes
        FOREIGN KEY (IdFabricante)
        REFERENCES Fabricantes(IdFabricante)
);

INSERT INTO Fabricantes (NombreFabricante, Pais) VALUES
('Lenovo', 'China'),
('HP', 'Estados Unidos'),
('Samsung', 'Corea del Sur'),
('Logitech', 'Suiza'),
('Sony', 'Japón');

INSERT INTO Productos
(NombreProducto, Categoria, Precio, Existencias, IdFabricante) VALUES
('Laptop ThinkPad', 'Computo', 14500.00, 8, 1),
('Laptop IdeaPad', 'Computo', 11500.00, 12, 1),
('Impresora Laser HP', 'Impresion', 4200.00, 6, 2),
('Monitor HP', 'Pantallas', 3100.00, 10, 2),
('Monitor Samsung', 'Pantallas', 2800.00, 7, 3),
('Teclado Logitech', 'Accesorios', 650.00, 20, 4),
('Mouse Logitech', 'Accesorios', 350.00, 25, 4),
('Bocinas Logitech', 'Audio', 700.00, 9, 4),
('Adaptador Universal', 'Accesorios', 220.00, 15, NULL);

Embed on website

To embed this project on your website, copy the following code and paste it into your website's HTML: