Duombaze.sql
-- 1. Create the database (duombaze) CREATE DATABASE IF NOT EXISTS imones_duombaze CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; USE imones_duombaze; Use code with caution. Copied to clipboard 2. Table Definitions
: Always use NOT NULL for required fields and UNIQUE for identifiers like emails to prevent duplicates. Duombaze.sql
This section ensures the database exists and that you are working within the correct context. Table Definitions : Always use NOT NULL for
-- 2. Create 'Vartotojai' (Users) table CREATE TABLE vartotojai ( id INT AUTO_INCREMENT PRIMARY KEY, vardas VARCHAR(50) NOT NULL, pavarde VARCHAR(50) NOT NULL, el_pastas VARCHAR(100) UNIQUE NOT NULL, slaptazodis VARCHAR(255) NOT NULL, sukurta_data TIMESTAMP DEFAULT CURRENT_TIMESTAMP ); -- 3. Create 'Kategorijos' (Categories) table CREATE TABLE kategorijos ( id INT AUTO_INCREMENT PRIMARY KEY, pavadinimas VARCHAR(100) NOT NULL, aprasymas TEXT ); -- 4. Create 'Prekes' (Products) table with a Foreign Key CREATE TABLE prekes ( id INT AUTO_INCREMENT PRIMARY KEY, kategorija_id INT, pavadinimas VARCHAR(100) NOT NULL, kaina DECIMAL(10, 2) NOT NULL, kiekis INT DEFAULT 0, ar_aktyvus BOOLEAN DEFAULT TRUE, FOREIGN KEY (kategorija_id) REFERENCES kategorijos(id) ON DELETE SET NULL ); Use code with caution. Copied to clipboard 3. Data Population (Seed Data) Add initial "seed" data to verify the database structure. Create 'Vartotojai' (Users) table CREATE TABLE vartotojai (
: If building a CMS, you might implement a "draft" system by adding an IsFinal or Status column to your tables to distinguish between published and unpublished entries.
Below is a complete draft for a generic system (e.g., a simple Content Management or Inventory system) that you can adapt. 1. Database Initialization
Including common queries can serve as documentation for other developers. You can also use tools like dbForge Documenter to generate comprehensive documentation in HTML or PDF formats.