Skip to main content

Nuova Tabella

Relazioni

  • posts.user_id 1-N users.id1-N
  • posts.id N-N tags.idN-N

SQL Generato

Tabelle3
Colonne11
Relazioni2
Righe SQL29
-- Schema generated by DB Schema Designer
-- Dialect: PostgreSQL
-- Generated: 2026-08-04T11:46:58.166Z

CREATE TABLE IF NOT EXISTS "users" (
  "id" SERIAL PRIMARY KEY,
  "username" VARCHAR(100) NOT NULL UNIQUE,
  "email" VARCHAR(255) NOT NULL UNIQUE,
  "created_at" TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP
);

CREATE TABLE IF NOT EXISTS "posts" (
  "id" SERIAL PRIMARY KEY,
  "user_id" INTEGER NOT NULL,
  "title" VARCHAR(255) NOT NULL,
  "body" TEXT,
  "published" BOOLEAN DEFAULT false,
  FOREIGN KEY ("user_id") REFERENCES "users"("id")
);

CREATE TABLE IF NOT EXISTS "tags" (
  "id" SERIAL PRIMARY KEY,
  "name" VARCHAR(50) NOT NULL UNIQUE
);

-- Junction table for N-N: posts <-> tags
CREATE TABLE IF NOT EXISTS "posts_tags" (
  "posts_id" INTEGER NOT NULL,
  "tags_id" INTEGER NOT NULL,
  PRIMARY KEY ("posts_id", "tags_id"),
  FOREIGN KEY ("posts_id") REFERENCES "posts"("id"),
  FOREIGN KEY ("tags_id") REFERENCES "tags"("id")
);

Come utilizzare Database Schema Designer

Add tables

Enter a table name and press "Add Table". Each new table comes with an auto-incrementing ID column as its primary key.

Define columns and constraints

For each table add columns by selecting data types (INTEGER, VARCHAR, DECIMAL, JSONB...) and constraints (PRIMARY KEY, NOT NULL, UNIQUE, DEFAULT, REFERENCES).

Connect tables with relationships

In the Relationships section, choose table and column source/destination and type (1-1, 1-N, N-N). For N-N relationships, the tool automatically generates a junction table.

Choose your dialect and copy SQL

Select PostgreSQL, MySQL or SQLite: generated DDL is updated in real-time. Copy to notes or download the .sql file.

Suggerimenti

  • Set always NOT NULL on mandatory columns before generating SQL - it's easier to correct now than after deployment.
  • Use the format "table.column" in the REFERENCES field to link a foreign key inline manually without going through the Relationships section.
  • For complex schemes, generate SQL first on SQLite for a quick local test, then move to production dialect (PostgreSQL/MySQL).

Domande frequenti

How are many-to-many relationships managed?

For each N-N relationship, the tool automatically generates a dedicated junction table with two external key columns (one for each involved table) and a composite primary key, eliminating the need to manually model it.

What differences are there between the types generated for PostgreSQL, MySQL and SQLite?

Data types differ between MySQL and SQLite.

Can I modify the preloaded example schema?

Yes, the example schema (users, posts, tags with 1-N and N-N relationships) is a starting point that can be modified: you can rename tables and columns freely, add or remove them as needed, or press "Reset" to start from scratch.

Does the tool validate complex reference integrity constraints?

No, generate the syntactically correct SQL DDL (CREATE TABLE, FOREIGN KEY) for the chosen dialect, but do not perform advanced semantic validation (e.g. dependency cycles, cascade policies): always verify the script before running it on a production database.