-- Create sequences for primary key generation
CREATE SEQUENCE seq_products START WITH 1 INCREMENT BY 1;
CREATE SEQUENCE seq_orders START WITH 1 INCREMENT BY 1;
CREATE SEQUENCE seq_users START WITH 1 INCREMENT BY 1;
CREATE SEQUENCE seq_transactions START WITH 1 INCREMENT BY 1;
CREATE SEQUENCE seq_tasks START WITH 1 INCREMENT BY 1;

-- Create tables with meaningful names and relevant columns
CREATE TABLE products (
    id NUMBER PRIMARY KEY,
    name VARCHAR2(100),
    category VARCHAR2(20),
    quantity INTEGER
);

CREATE TABLE orders (
    id NUMBER PRIMARY KEY,
    description VARCHAR2(255),
    status VARCHAR2(20)
);

CREATE TABLE users (
    id NUMBER PRIMARY KEY,
    created_at DATE DEFAULT SYSDATE,
    username VARCHAR2(20),
    age INTEGER,
    location VARCHAR2(20)
);

CREATE TABLE transactions (
    id NUMBER PRIMARY KEY,
    amount NUMBER(10,2),
    currency VARCHAR2(20)
);

CREATE TABLE tasks (
    id NUMBER PRIMARY KEY,
    status VARCHAR2(50),
    priority INTEGER,
    type VARCHAR2(20),
    assigned_to VARCHAR2(20)
);

-- Create triggers to auto-generate primary key values using sequences
CREATE OR REPLACE TRIGGER trg_products_pk
BEFORE INSERT ON products
FOR EACH ROW
BEGIN
    SELECT seq_products.NEXTVAL INTO :NEW.id FROM dual;
END;
/

CREATE OR REPLACE TRIGGER trg_orders_pk
BEFORE INSERT ON orders
FOR EACH ROW
BEGIN
    SELECT seq_orders.NEXTVAL INTO :NEW.id FROM dual;
END;
/

CREATE OR REPLACE TRIGGER trg_users_pk
BEFORE INSERT ON users
FOR EACH ROW
BEGIN
    SELECT seq_users.NEXTVAL INTO :NEW.id FROM dual;
END;
/

CREATE OR REPLACE TRIGGER trg_transactions_pk
BEFORE INSERT ON transactions
FOR EACH ROW
BEGIN
    SELECT seq_transactions.NEXTVAL INTO :NEW.id FROM dual;
END;
/

CREATE OR REPLACE TRIGGER trg_tasks_pk
BEFORE INSERT ON tasks
FOR EACH ROW
BEGIN
    SELECT seq_tasks.NEXTVAL INTO :NEW.id FROM dual;
END;
/
