The sql-surge repository aims to provide a good reference to students,
teachers and database enthusiasts who would like to prepare, review, and get
fantastic challenges in SQL and RDBMS.
Most of the examples and challenges are written to comply with PostgreSQL,
however, you could try this on any of the RDBMS that support SQL syntaxes.
Note: Sometimes, small modification might be needed to run with different SQL servers. For example
MySQLdo not supportSERIALcolumns, so we need to change it toINTEGER AUTOINCREMENTcolumn type.
The reference basically contains the following resources:
- Notes: This section provides introduction to specific topics.
- Examples: This section provides some examples to get started with SQL.
- Challenges: This section provides you challenges to get prepared.
- Projects: This section will show you some real-world projects for starting projects.
Install your favorite code editor. This repository suggests you to use vscode, which you can install from https://code.visualstudio.com/.
After installing vscode, you can install extensions suggested by the project settings which is defined inside the file .vscode/extensions.json.
If you prefer using a SQLserver of your choice, then you may install it
otherwise, a docker compose file is provided to you to install PostgreSQL
server.
To do that, first install docker if it is not
already installed in your system. After installing docker, you can easily run
docker compose up command to start your postgresql server.
# to run all the services defined inside the `docker-compose.yml` file
docker compose up
# to run the those services in background, (daemonize)
docker compose up -d
# to run specific service in background, eg: postgres
docker compose up -d postgresIntroduction and examples sometime needs some common database tables, which is defined inside common/ directory.
Please run SQL scripts tagged with up and seed tags so that you would be
able to test those scripts. For example
common/star-wars/001-up.sql.
If your database becomes corrupt, or you want to start over, you can run down
scripts. For example
common/star-wars/000-down.sql.
Table of contents
Note: This repository is constantly evolving and might not have every topics listed out below.
Please check
examplessection for examples directly for those sections that do not have notes yet.
-
- 2.1. Numeric data types
- 2.2. Boolean data type
- 2.3. Character types
- 2.4. Date/time types
- 2.5. UUID type
- 2.6. Array
-
- 3.1. Database CRUD Operations
- 3.2. TABLE CRUD Operations
- 3.3. Populating a table with rows
- 3.4. Querying a table
- 3.5. Foreign Keys
- 3.6. Joins Between Tables
- 3.7. Transactions
- 3.8. Aggregation
-
- 4.1 PostgreSQL installation
- 4.2 The
psqlcommand line application - 4.3 Database CRUD operations with
psql - 4.4 User CRUD operations with
psql - 4.5 Granting permissions to different users with
psql