Overview
The products and categories tables form the core of inventory management in TechCore Mini ERP. Thecategoria table organizes products into logical groups, while the productos table stores detailed product information including pricing, stock levels, and category assignments.
Categoria Table
Thecategoria table defines product categories for organizing and classifying inventory items.
SQL Schema
Columns
Primary key with auto-increment. Uniquely identifies each category in the system.
Business-defined category code. Must be unique (enforced by UNIQUE constraint and index). This provides a human-readable identifier for the category.
Category name/title. Required field.
Detailed description of the category. Optional field for additional context.
Category status flag. Defaults to 1 (active). Set to 0 to deactivate category without deleting it or affecting existing products.
Timestamp when the category was created. Defaults to current date/time (GETDATE()).
Constraints
- Primary Key:
codCategoria - Unique Constraint:
codigomust be unique
Indexes
- IDX_categoria_codigo: Unique index on
codigofor fast lookups by category code - IDX_categoria_nombre: Index on
nombrefor efficient name-based searches - IDX_categoria_estado: Index on
estadofor filtering active categories
C# Model
Relationships
- One-to-Many with productos: One category can contain multiple products
Productos Table
Theproductos table stores comprehensive product information including pricing, inventory levels, and category associations.
SQL Schema
Columns
Primary key. Product code/SKU that uniquely identifies each product. Business-defined identifier.
Foreign key reference to
categoria table. Assigns the product to a category. Nullable to allow uncategorized products.Product description. Optional field with extended length for detailed product information.
Purchase/cost price. Required field. Uses DECIMAL(18,2) for precise monetary calculations. This is the price at which the product is purchased from suppliers.
Selling/retail price. Required field. Uses DECIMAL(18,2) for precise monetary calculations. This is the price at which the product is sold to customers.
Current inventory quantity. Defaults to 0. Updated automatically by triggers when sales and purchases are processed.
Minimum stock level/reorder point. Defaults to 5. When stock falls below this value, the product should be reordered.
Product status flag. Defaults to 1 (active). Set to 0 to deactivate product without deleting historical transaction data.
Timestamp when the product was created. Defaults to current date/time (GETDATE()).
Constraints
- Primary Key:
codprod - Foreign Key:
codCategoriareferencescategoria(codCategoria)
Indexes
- IDX_productos_descripcion: Index on
descripcionfor text searches - IDX_productos_idcategoria: Index on
codCategoriafor category-based queries - IDX_productos_estado: Index on
estadofor filtering active products - IDX_productos_stock: Composite index on
(stock, stockMinimo)for efficient restock alert queries
C# Model
Relationships
- Many-to-One with categoria: Each product can belong to one category (nullable)
- One-to-Many with ventasDetalle: Products can appear in multiple sales line items
- One-to-Many with comprasDetalle: Products can appear in multiple purchase line items
Entity Relationships
Inventory Management
Stock Updates
Product stock is automatically managed through database triggers: TR_DisminuirStock: Decreases stock when sales are processed (only for non-voided sales)Reorder Alerts
The composite index on(stock, stockMinimo) enables efficient queries to identify products that need restocking:
Usage Notes
- Products use business codes (VARCHAR) as primary keys for easier human reference
- The
codCategoriafield is nullable, allowing uncategorized products - DECIMAL(18,2) ensures precise currency calculations without floating-point errors
- The
stockandstockMinimofields work together for automatic reorder point detection - Stock levels are automatically updated by triggers when processing sales
- The
estadofield allows soft-deletion to preserve historical transaction integrity - Categories cannot be hard-deleted if they have associated products