Overview
The users and roles tables manage user authentication, authorization, and role-based access control in TechCore Mini ERP. Therol table defines available roles, while the users table stores user account information with foreign key references to roles.
Rol Table
Therol table stores role definitions for the role-based access control system.
SQL Schema
Columns
Primary key with auto-increment. Uniquely identifies each role in the system.
Role name (e.g., “Administrator”, “Sales Manager”, “Cashier”). This field is required and defines the role’s identity.
Indicates if the role is enabled/active. Defaults to 1 (true). When set to 0, the role is disabled but not deleted from the database.
Indexes
- IDX_rol_habilitado: Index on
habilitadocolumn for efficient filtering of active roles
C# Model
Relationships
- One-to-Many with users: One role can be assigned to multiple users
Users Table
Theusers table stores user account information including credentials, contact details, and role assignments.
SQL Schema
Columns
Primary key with auto-increment. Uniquely identifies each user in the system.
Unique user code/identifier. This is a business identifier separate from the auto-generated ID. Must be unique (enforced by index).
Full name of the user. Required field.
Login username. Must be unique across all users (enforced by UNIQUE constraint).
Encrypted/hashed password. Stored as VARCHAR(MAX) to accommodate various hashing algorithms and future-proofing.
Contact phone number. Optional field.
Foreign key reference to the
rol table. Defines the user’s role and permissions. Required field.User’s email address. Optional but indexed for quick lookups.
Timestamp when the user account was created. Defaults to current date/time (GETDATE()).
Constraints
- Primary Key:
id - Unique Constraint:
usernamemust be unique - Foreign Key:
idrolreferencesrol(id)
Indexes
- IDX_users_code: Unique index on
codefor fast lookups by user code - IDX_users_idrol: Index on
idrolfor efficient role-based queries - IDX_users_email: Index on
emailfor quick email-based searches
C# Model
Relationships
- Many-to-One with rol: Each user belongs to one role (via
idrol) - One-to-Many with ventas: Users can process multiple sales (as vendor/seller)
- One-to-Many with compras: Users can process multiple purchases
Entity Relationship
Usage Notes
- The
users.codefield provides a business-friendly identifier separate from the technicalid - Passwords should always be hashed before storage; never store plain text passwords
- The
habilitadofield inrolallows soft-deletion of roles without breaking foreign key relationships - Users are referenced in both sales (ventas) and purchases (compras) to track who processed each transaction
- The unique index on
usernameensures no duplicate login credentials