Use CREATE TABLE when an application needs a new database table with a defined structure. The statement names the table and specifies each column’s data type and rules. section 8.2.4
CREATE TABLE users (
username VARCHAR(100) PRIMARY KEY,
password_hash VARCHAR(128)
);
This users table stores usernames and password hashes; VARCHAR limits text length, while PRIMARY KEY makes each username unique and required. section 8.2.4
Read each column specification as a compact design decision:
- VARCHAR(100) accepts variable-length text up to 100 characters; longer values produce an error. section 8.2.4
- PRIMARY KEY uniquely identifies rows and prevents duplicate or missing usernames. section 8.2.4
Check the result
Run the CREATE TABLE command in the PostgreSQL psql shell, then use \dt to list tables and confirm that users was created.





