intermediate-database-connectivity-sql-query
Version 1.1 by marijn on 2022/05/17 08:52
SQL Query
In this microlearning, we will learn the basics of SQL queries. With the help of this information, you can start writing the correct queries to retrieve and write data from and to a database.Should you have any questions, please get in touch with academy@emagiz.com.- Last update: September 7th, 2021
- Required reading time: 6 minutes
1. Prerequisites
- Basic knowledge of the eMagiz platform
2. Key concepts
Each type of external database will need specific queries to perform actions on the database level. Mostly we see that SQL queries are needed; therefore, we focus on them in this microlearning. In terms of CRUD operations on the database, the SQL language defines the following:- INSERT = Create
- SELECT = Read
- UPDATE = Update
- DELETE = Delete
3. SQL Query
In this microlearning, we will learn the basics of SQL queries. With the help of this information, you can start writing the correct queries to retrieve and write data from and to a database. Just as with REST web services, the CRUD operations are represented within the SQL language. They are described as follows:- INSERT = Create
- SELECT = Read
- UPDATE = Update
- DELETE = Delete
3.1 INSERT
With an insert statement, you create a new record in the database. Within an insert statement, you define the following:- The table name (mytable)
- The column names (id, created date, contents)
- The value per column (:headers[id], :headers[timestamp], :payload)
3.2 SELECT
With a select statement, you read one or more records from the database. Within a select statement, you define the following:- The columns you want to be returned (\* in case of all columns)
- The table from which to read
- Optional: A condition (WHERE x=x)
3.3 UPDATE
With an update statement, you update one or more records in the database. Within an update statement, you define the following:- The table name
- What you want to change (SET x to y)
- Optional: A condition (WHERE x=x)
3.4 DELETE
With an update statement, you delete one or more records in the database. Within a delete statement, you define the following:- The table name
- Optional: A condition (WHERE x=x)
Practice
4. Assignment
See if you can find any database implementation within the projects you can access. This assignment can be completed with the help of the (Academy) project that you have created/used in the previous assignment.5. Key takeaways
- These examples cover the basics of the SQL language
- The SQL language has its form of CRUD operations
- You can dynamically fill the values of the SQL properties with the help of SpEL expressions
- Other types of databases might require other queries