SQL Snippets
Common SQL patterns for FiveM databases. Review column sizes and constraints against the framework’s real identifiers before running migrations. Apply schema changes through versioned migrations, back up production data first, and parameterize every application query. Test both forward migration and restore procedures on a non-production copy.
User Table
CREATE TABLE users (
id INT AUTO_INCREMENT PRIMARY KEY,
identifier VARCHAR(50) UNIQUE NOT NULL,
name VARCHAR(100) NOT NULL,
money INT DEFAULT 0,
bank INT DEFAULT 0,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
INDEX idx_identifier (identifier)
);Items Table
CREATE TABLE items (
id INT AUTO_INCREMENT PRIMARY KEY,
name VARCHAR(50) UNIQUE NOT NULL,
label VARCHAR(100) NOT NULL,
weight DECIMAL(10,2) DEFAULT 0,
INDEX idx_name (name)
);Inventory Table
CREATE TABLE inventory (
id INT AUTO_INCREMENT PRIMARY KEY,
user_id INT NOT NULL,
item_name VARCHAR(50) NOT NULL,
count INT DEFAULT 1,
FOREIGN KEY (user_id) REFERENCES users(id),
INDEX idx_user_id (user_id)
);