Simple CRUD
1. Open the PostgreSQL CLI
Launch
psqlin your terminal:psql -U postgresConnect to your database (replace
your_databasewith the name of your database):\c your_database
2. Create the City Table
City TableExecute the following SQL to create the table:
CREATE TABLE City (
id SERIAL PRIMARY KEY,
name VARCHAR(255) NOT NULL,
country VARCHAR(255) NOT NULL,
population INTEGER
);3. Insert Data (CREATE)
Insert some sample data into the City table:
4. Read Data (READ)
Retrieve all records:
Retrieve specific records:
5. Update Data (UPDATE)
Update the population of a city:
Verify the update:
6. Delete Data (DELETE)
Delete a record:
Verify the deletion:
7. Drop the Table (Optional)
If you want to remove the City table:
Last updated