Skip to main content
The talla table stores available size options for clothing items. Sizes are referenced by products through the id_talla foreign key, ensuring consistent sizing across the inventory system.

Table Structure

id_talla
int(11)
required
Primary key - Auto-incrementing unique identifier for each size
talla
varchar(10)
required
Size code (e.g., “ch”, “m”, “g”, “ech”, “eg”)

SQL Definition

TiendaRopa.sql
CREATE TABLE `talla` (
  `id_talla` int(11) NOT NULL,
  `talla` varchar(10) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;

ALTER TABLE `talla`
  ADD PRIMARY KEY (`id_talla`);

ALTER TABLE `talla`
  MODIFY `id_talla` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=9;

Sample Data

The database includes these default size options:
INSERT INTO `talla` (`id_talla`, `talla`) VALUES
(1, 'ch'),
(2, 'm'),
(3, 'g'),
(7, 'ech'),
(8, 'eg');

Size Code Reference

CH - Chico

ID: 1 - Small size

M - Mediano

ID: 2 - Medium size

G - Grande

ID: 3 - Large size

ECH - Extra Chico

ID: 7 - Extra small size

EG - Extra Grande

ID: 8 - Extra large size
Size codes use Spanish abbreviations: ch (chico/small), m (mediano/medium), g (grande/large), ech (extra chico/extra small), eg (extra grande/extra large)

Relationships

Referenced By

prenda Table

Products reference sizes through id_talla foreign key
Foreign Key Constraint:
ALTER TABLE `prenda`
  ADD CONSTRAINT `fk_prenda_talla` 
  FOREIGN KEY (`id_talla`) REFERENCES `talla` (`id_talla`);

Common Queries

List All Sizes

SELECT * FROM talla ORDER BY id_talla ASC;

Products by Size

SELECT p.*, t.talla as talla_nombre
FROM prenda p
JOIN talla t ON p.id_talla = t.id_talla
WHERE t.talla = 'm';

Size Distribution

SELECT t.talla, COUNT(*) as productos
FROM prenda p
JOIN talla t ON p.id_talla = t.id_talla
GROUP BY t.id_talla
ORDER BY productos DESC;

Products by Category and Size

SELECT c.nombre as categoria, t.talla, COUNT(*) as productos
FROM prenda p
JOIN categoria c ON p.id_categoria = c.id_categoria
JOIN talla t ON p.id_talla = t.id_talla
GROUP BY c.id_categoria, t.id_talla
ORDER BY c.nombre, t.talla;
The database has a composite index idx_prenda_cat_talla on (id_categoria, id_talla) that optimizes queries filtering by both category and size.

Usage in Application

Sizes are managed through tallas.php:
  • Create: Add new size codes
  • Update: Edit existing size codes via modal dialog
  • Delete: Remove sizes (only if not referenced by products)
  • View: Display all sizes in a sortable table

Create Operation

tallas.php
if(isset($_POST['add'])){
    $stmt = $conn->prepare("INSERT INTO talla (talla) VALUES (?)");
    $stmt->execute([$_POST['talla']]);
    header("Location: tallas.php?msg=creado");
}

Update Operation

tallas.php
if(isset($_POST['update'])){
    $stmt = $conn->prepare("UPDATE talla SET talla = ? WHERE id_talla = ?");
    $stmt->execute([$_POST['talla'], $_POST['id_talla']]);
    header("Location: tallas.php?msg=actualizado");
}

Delete Operation

tallas.php
if(isset($_GET['delete'])){
    try {
        $stmt = $conn->prepare("DELETE FROM talla WHERE id_talla = ?");
        $stmt->execute([$_GET['delete']]);
        header("Location: tallas.php?msg=eliminado");
    } catch (Exception $e) {
        $error = "No se puede eliminar esta talla porque tiene productos asociados.";
    }
}

Business Rules

  1. Lowercase Convention: Size codes are stored in lowercase for consistency
  2. Abbreviations: Use standardized Spanish abbreviations (ch, m, g, ech, eg)
  3. Deletion Constraints: Sizes cannot be deleted if referenced by products
  4. Unique Codes: Avoid duplicate size codes to prevent confusion
Unlike categories and colors, sizes can be deleted if they have no associated products. Exercise caution when deleting sizes to avoid accidentally removing commonly used options.

Extension Possibilities

Add columns for international size equivalents:
ALTER TABLE talla 
  ADD COLUMN talla_us VARCHAR(10),
  ADD COLUMN talla_eu VARCHAR(10),
  ADD COLUMN talla_uk VARCHAR(10);
Store measurement ranges for each size:
ALTER TABLE talla 
  ADD COLUMN medida_min DECIMAL(5,2),
  ADD COLUMN medida_max DECIMAL(5,2),
  ADD COLUMN unidad ENUM('cm', 'inch');
Categorize sizes by type (adult, child, infant):
ALTER TABLE talla 
  ADD COLUMN tipo ENUM('adulto', 'infantil', 'bebe');
Distinguish between men’s and women’s sizing:
ALTER TABLE talla 
  ADD COLUMN genero ENUM('hombre', 'mujer', 'unisex') DEFAULT 'unisex';

Analytics Queries

Stock Value by Size

SELECT t.talla, 
       COUNT(*) as productos,
       SUM(p.stock_actual) as stock_total,
       SUM(p.precio * p.stock_actual) as valor_inventario
FROM prenda p
JOIN talla t ON p.id_talla = t.id_talla
GROUP BY t.id_talla
ORDER BY valor_inventario DESC;

Low Stock by Size

SELECT t.talla, p.nombre, p.stock_actual
FROM prenda p
JOIN talla t ON p.id_talla = t.id_talla
WHERE p.stock_actual < 10
ORDER BY p.stock_actual ASC;

prenda Table

Product catalog that references sizes

Catalog Management

Using the size management interface

Database Indexes

Composite index for category+size queries

Managing Categories

User guide for catalog management

Build docs developers (and LLMs) love