Overview
The TiendaRopa database uses foreign key constraints to maintain referential integrity between tables. This page documents all relationships, their cascade behaviors, and how tables connect to form the complete data model.Relationship Diagram
The database follows a relational model with the following key connections:Foreign Key Constraints
prenda Table Relationships
Theprenda table is the core entity that connects to three catalog tables:
- prenda → categoria: Each garment belongs to exactly one category (Caballero, Dama, Infantil, Deportiva, Accesorios)
- prenda → talla: Each garment has a specific size (ch, m, g, ech, eg)
- prenda → color: Each garment variant has a specific color (Negro Nocturno, Blanco Pureza, etc.)
actualizacion Table Relationships
Theactualizacion table tracks price changes for garments:
- actualizacion → prenda: Links each price update to a specific garment
- actualizacion → empleado: Records which employee performed the price update
movimiento_stock Table Relationships
Themovimiento_stock table records inventory movements:
- movimiento_stock → prenda: Links each stock movement to a specific garment
- movimiento_stock → empleado: Records which employee performed the stock operation
registro Table Relationships
Theregistro table connects garments with their suppliers and the employees who registered them:
- registro → prenda: Links registration record to a specific garment
- registro → empleado: Records which employee registered the garment
- registro → proveedor: Identifies the supplier of the garment
Relationship Details by Table
Central Tables
prenda (Garment)
The central table that most operations reference. Outgoing relationships:- References
categoriafor garment classification - References
tallafor size information - References
colorfor color variants
- Referenced by
actualizacionfor price history - Referenced by
movimiento_stockfor inventory movements - Referenced by
registrofor supplier information
empleado (Employee)
Tracks employee involvement in various operations. Incoming relationships:- Referenced by
actualizacionto track who updated prices - Referenced by
movimiento_stockto track who performed stock operations - Referenced by
registroto track who registered new garments
Catalog Tables
These tables define the attributes of garments:categoria (Category)
- Referenced by
prendato classify garments - Contains: Caballero, Dama, Infantil, Deportiva, Accesorios
talla (Size)
- Referenced by
prendato specify garment sizes - Contains: ch (chico), m (mediano), g (grande), ech (extra chico), eg (extra grande)
color (Color)
- Referenced by
prendato specify color variants - Contains: Negro Nocturno, Blanco Pureza, Azul Marino, Rojo Pasión, Gris Oxford
Operational Tables
proveedor (Supplier)
- Referenced by
registroto track garment suppliers - Contains local Aguascalientes textile suppliers
Data Integrity Rules
Referential Integrity
All foreign key constraints use the default RESTRICT behavior:- Cannot delete a
categoria,talla, orcolorthat is referenced by existing garments - Cannot delete a
prendathat has price updates, stock movements, or registration records - Cannot delete an
empleadowho has performed any recorded operations - Cannot delete a
proveedorthat has supplied registered garments
Best Practices
- Before deleting catalog records (categoria, talla, color), verify no garments reference them
- Before deleting garments, check for related records in actualizacion, movimiento_stock, and registro
- Before deleting employees, ensure they have no historical records
- Maintain referential integrity by creating parent records (categories, sizes, colors) before creating garments
Query Examples
Find All Relationships for a Garment
Find All Operations for a Garment
Check for Dependent Records Before Deletion
Related Pages
- Database Schema - Complete schema structure
- Database Indexes - Index definitions and performance optimization
- Tables Reference - Detailed table documentation