Code Reference

Hello World

SQL · Reference cheat sheet

Hello World

SQL · Reference cheat sheet


📋 Overview

SQL Hello World is usually a SELECT that returns a constant, or creating a one-column table and reading it back. It proves your client can connect and run statements.

🔧 Core concepts

PieceRole
SELECTRead data / expressions
ASAlias a column name in the result
StatementOne SQL command (often ends with ;)
Result setTable-like output of a query

Many tools (sqlite3, psql, GUI clients) show results as a grid.

💡 Examples

Constant select:

SELECT 'Hello, World!' AS greeting;

Math and aliases:

SELECT 2 + 2 AS four;
SELECT 'Ada' AS name, 1815 AS birth_year;

Round-trip with a table (SQLite-friendly):

CREATE TABLE hello (
  id INTEGER PRIMARY KEY,
  message TEXT NOT NULL
);

INSERT INTO hello (message) VALUES ('Hello, World!');
SELECT message FROM hello;

Current time (Postgres example):

SELECT NOW() AS right_now;

⚠️ Pitfalls

  • Forgetting ; in interactive clients that require it.
  • Connecting to the wrong database/schema and thinking the query “failed.”
  • SELECT * is fine for learning; be specific in real apps.
  • Dialect functions differ (NOW(), datetime('now'), GETDATE()).

On this page