Ch 3 · PostgreSQL Introduction and Setup · PostgreSQL
Topic 3 of 3 in PostgreSQL — Complete Tutorial (Beginner) — 4 lessons.
Getting Started with PostgreSQL
Get started with PostgreSQL: connect, create databases, and run your first queries. PostgreSQL is a powerful, free, open-source relational database. You will use psql, its command-line tool, to create a database, build a table with a SERIAL ID that numbers itself, add some rows and query them. These first steps are the foundation for everything else you do with Postgres.
Getting Started with PostgreSQL in Code
This walkthrough goes from an empty server to your first results. You open psql in your terminal, create a database, switch to it with \c (a psql meta-command, not SQL), then build a users table. Look at SERIAL, PostgreSQL's way of numbering rows, and DEFAULT NOW(), which records when each row was created. Finally you insert two users and read them back.
Practice: Getting Started with PostgreSQL
Your turn to set something up from scratch. You will create a products table, add three products and then query them all. A correct answer gives each product an automatic SERIAL ID, chooses sensible types for the name and price, marks required columns NOT NULL, and ends with a SELECT that returns every row you inserted.
Solution & Challenge: Getting Started with PostgreSQL
Check your table against the worked solution, including how it stops a product having a zero or negative price. The challenge then asks for a complete blog schema: users, posts, comments, tags and a post_tags table linking posts to tags. A good answer uses SERIAL primary keys, foreign keys with ON DELETE rules, and CHECK and UNIQUE constraints.