# PostgreSQL Practice Exercises: Essential Techniques for Mastering the Framework

Here is a short practice for working with PostgreSQL:

1. Start by launching the “psql” command-line interface for interacting with the PostgreSQL database.
2. Create a new database named “mydatabase” by running the following command:
```sqlCopy code```CREATE DATABASE mydatabase;
``````
1. Connect to the “mydatabase” database by running the following command:
```rCopy code```\c mydatabase
``````
1. Create a new table named “employees” with the following columns:
```scssCopy code```id (integer)
name (varchar(50))
age (integer)
salary (numeric)
``````

by running the following SQL command:

```sqlCopy code```CREATE TABLE employees (
id integer,
name varchar(50),
age integer,
salary numeric
);
``````
1. Insert the following data into the “employees” table:
```pythonCopy code```1, 'John Doe', 32, 65000
2, 'Jane Doe', 28, 55000
3, 'Jim Smith', 40, 75000
``````

by running the following SQL command:

```sqlCopy code```INSERT INTO employees (id, name, age, salary) VALUES
(1, 'John Doe', 32, 65000),
(2, 'Jane Doe', 28, 55000),
(3, 'Jim Smith', 40, 75000);
``````
1. Retrieve all employees who are older than 35 years old by running the following SQL command:
```sqlCopy code```SELECT * FROM employees WHERE age > 35;
``````
1. Update the salary of all employees by 10% by running the following SQL command:
```sqlCopy code```UPDATE employees SET salary = salary * 1.1;
``````
1. Delete all employees with a salary of less than 60,000 by running the following SQL command:
```sqlCopy code```DELETE FROM employees WHERE salary < 60000;
``````

By practicing these steps, you will gain experience working with the basic SQL commands for inserting, retrieving, updating, and deleting data in a PostgreSQL database. Continue to practice these commands and work on more complex examples to improve your skills and become more proficient with PostgreSQL.

Tags: No tags