SQL PORTABILITY / CHOOSE THE RIGHT VARIANT

The core patterns are reusable, not a claim that one string runs on every DBMS.
Practice Q10 uses PostgreSQL because Unit 3 explicitly names PostgreSQL. Replace
identifiers/literals for other tables; check that engine's supported syntax.

Auto-numbered primary key:
  PostgreSQL: id INTEGER GENERATED ALWAYS AS IDENTITY PRIMARY KEY
  PostgreSQL legacy shorthand: id SERIAL PRIMARY KEY
  MySQL: id INT AUTO_INCREMENT PRIMARY KEY
  SQLite: id INTEGER PRIMARY KEY
    AUTOINCREMENT is optional with different reuse/cost semantics; not generic SQL.
  SQL Server: id INT IDENTITY(1,1) PRIMARY KEY
  Oracle 12c+: id NUMBER GENERATED ALWAYS AS IDENTITY PRIMARY KEY
A generated ID does not promise gap-free numbering. Identity still needs a PK or
UNIQUE constraint if uniqueness is a requirement.

Limit rows:
  PostgreSQL/MySQL/SQLite: SELECT * FROM t ORDER BY id LIMIT 5;
  Standard-style/PostgreSQL/Oracle modern versions:
    SELECT * FROM t ORDER BY id FETCH FIRST 5 ROWS ONLY;
  SQL Server: SELECT TOP (5) * FROM t ORDER BY id;
Pagination:
  PostgreSQL/MySQL/SQLite: ... ORDER BY id LIMIT 5 OFFSET 10;
  SQL Server: ... ORDER BY id OFFSET 10 ROWS FETCH NEXT 5 ROWS ONLY;
Always define ordering when a deterministic first/top/nth result matters.

Use/connect database:
  MySQL/SQL Server: USE database_name;
  PostgreSQL psql client: \c database_name (a client command, not SQL)
  SQLite: open the database file; ATTACH DATABASE attaches an additional file.

Type-change syntax:
  PostgreSQL: ALTER TABLE t ALTER COLUMN c TYPE TEXT;
  MySQL: ALTER TABLE t MODIFY COLUMN c VARCHAR(100);
  SQL Server: ALTER TABLE t ALTER COLUMN c VARCHAR(100);
  SQLite: limited ALTER; many changes require rebuilding/copying the table.

Text and case:
  String values use single quotes; 'Mumbai' is data. Identifier quoting differs:
  SQL-standard/PostgreSQL double quotes; MySQL commonly backticks; SQL Server also
  square brackets. Don't confuse string delimiters with identifier delimiters.
  SQL keywords are normally case-insensitive, but data comparisons depend on
  types/collation. PostgreSQL unquoted identifiers fold lowercase; quoted names
  preserve case. Do not claim that SQL string values are universally case-insensitive.
  PostgreSQL ILIKE is not universal. LOWER(column) LIKE LOWER(pattern) is a common
  cross-engine pattern with indexing, locale and collation implications.

Concatenation:
  PostgreSQL/SQLite/standard-style: first_name || ' ' || last_name
  MySQL: CONCAT(first_name, ' ', last_name)
  SQL Server: CONCAT(first_name, ' ', last_name) or + with its own null/type rules.

NULL:
  Use IS NULL and IS NOT NULL. COALESCE is widely supported. NOT IN can be unknown
  if its list/subquery contains NULL. Prefer NOT EXISTS for a missing-row query.
  Empty string is distinct from NULL in PostgreSQL; Oracle commonly treats an
  empty character string as NULL. 'Cannot be empty' needs more than NOT NULL
  on engines that distinguish them: CHECK (TRIM(name) <> '') plus NOT NULL.

Joins:
  INNER/LEFT/CROSS are broadly available. PostgreSQL supports RIGHT/FULL OUTER.
  MySQL has no native FULL OUTER JOIN; emulate carefully with LEFT JOIN plus an
  unmatched reverse LEFT JOIN combined with UNION ALL. Older SQLite versions
  also differ from current versions. NATURAL JOIN depends on all shared column
  names and is fragile when a schema changes; explicit ON is clearer.

Transactions and DDL:
  PostgreSQL can roll back many DDL operations and TRUNCATE; CREATE DATABASE is
  outside a transaction block. MySQL has implicit commits for many DDL operations;
  storage engines matter. SQLite has no TRUNCATE or GRANT/REVOKE roles system.
  Never generalize PostgreSQL rollback/sequence behaviour to every engine.

Upsert:
  PostgreSQL: INSERT ... ON CONFLICT (...) DO UPDATE ...
  SQLite: supports its own ON CONFLICT UPSERT syntax on supported versions.
  MySQL: INSERT ... ON DUPLICATE KEY UPDATE ...
  MERGE syntax/support varies; it is not a drop-in universal upsert.

Parameters:
  Bind values through your DB driver's parameter API; do not concatenate user
  strings into SQL. psycopg commonly uses %s, sqlite3 commonly ?, and other
  drivers use named/numbered forms. Identifiers need identifier-composition APIs,
  not ordinary value parameters. The examples here are displayed, never executed.

Question interpretation checklist:
1. Identify the table, required output columns and exact threshold (> vs >=).
2. Identify row filters (WHERE), join keys, and whether empty parents must remain.
3. Choose COUNT(*) versus COUNT(child.id); choose inner versus left join.
4. For per-city/category totals use GROUP BY; aggregate filters use HAVING.
5. For modifications confirm WHERE, FK prerequisites and transaction needs.
6. For create-table questions choose the engine's identity syntax, keys, types,
   NOT NULL, empty-string checks and intended ON DELETE behaviour.
7. 'Increase by 20' means +20; 'increase by 20%' means value * 1.20.
8. Textbook examples are independent unless explicitly described as a sequence.

Sources:
https://www.postgresql.org/docs/current/sql.html
https://www.postgresql.org/docs/current/sql-createtable.html
https://www.postgresql.org/docs/current/tutorial-transactions.html
https://dev.mysql.com/doc/refman/8.4/en/example-auto-increment.html
https://www.sqlite.org/lang.html
https://learn.microsoft.com/en-us/sql/t-sql/statements/create-table-transact-sql-identity-property
