</>
Skip to content
PostgreSQL lessons (7/38)

PostgreSQL — Tables

Create Table

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

List Tables

SELECT table_name FROM information_schema.tables 
WHERE table_schema = 'public';

Or psql: \dt

Describe Table

\d users

Or:

SELECT column_name, data_type 
FROM information_schema.columns 
WHERE table_name = 'users';

Alter Table

-- Add column
ALTER TABLE users ADD COLUMN age INTEGER;

-- Drop column
ALTER TABLE users DROP COLUMN age;

-- Rename column
ALTER TABLE users RENAME COLUMN name TO full_name;

-- Change type
ALTER TABLE users ALTER COLUMN age TYPE SMALLINT;

Drop Table

DROP TABLE users;
DROP TABLE IF EXISTS users;

Mini Practice

  1. Create a table
  2. List all tables
  3. Describe table structure
  4. Alter table

Up Next

Continue with Create Table — creating tables.

Related Topics

Frequently Asked Questions about Tables

What is Tables in PostgreSQL?

Tables is a fundamental concept in PostgreSQL. This lesson explains it step by step with clear examples, making it easy for beginners to understand.

How do I learn Tables?

Start by reading the explanation above, then try the code examples. Practice by modifying the examples and experimenting with different values. Hands-on practice is the best way to learn Tables.

Why is Tables important in PostgreSQL?

Tables is essential for PostgreSQL development. Understanding this concept will help you write better code and solve real-world problems more effectively.