Server-Side Scripting/SQL Databases

This lesson introduces SQL-based database processing.

Objectives and Skills
Objectives and skills for this lesson include:
 * Understand relational database concepts
 * Understand SQL data manipulation language
 * Use an SQL database with server-side scripts

Readings

 * 1)  Database
 * 2)  Relational database
 * 3)  SQL
 * 4)  SQL injection

Multimedia
Additional items may be contributed by course participants

Tutorials
Before trying to work with any database using a programming language, you should first be familiar with that database's command language. The following tutorials will be helpful in understanding how to use MySQL and/or SQLite.

MySQL

 * MySQL
 * MySQL Tutorial
 * W3Schools: SQL Tutorial

SQLite

 * SQLite
 * SQLite Tutorial
 * W3Schools: SQL Tutorial

SQLite
The following examples use SQLite as the SQL database. A similar approach would work for almost any SQL-based database. SQLite is used because it requires no server configuration or maintenance. Performance would be adequate for small-scale projects. Larger projects should use a server-based database such as MySQL.


 * /Go/
 * /Node.js (Express)/
 * /PHP/
 * /Python (FastAPI)/
 * /Python (Flask)/

MySQL
The following examples use MySQL as the SQL database. Note that MySQL databases require maintenance. Review MySQL maintenance best practices before using MySQL in a production environment.


 * Go
 * Node.js (Express)

Activities
Complete the following activities using HTML, CSS, and a server-side scripting language. Apply best practices for user interface design and your selected scripting language, including modules, comments, indentations, naming conventions, and constants. Use HTML forms and input elements for input, server-side scripts for processing, and HTML elements for output. Use separate functions for each type of processing. Avoid global variables by passing parameters and returning results. Add comments at the top of the code modules and include references to any resources used. Add the completed code to your website as.
 * 1) Create an application that allows the user to insert, update, and delete records in an SQL-based database. After each action, display the current records. Use any SQL database and data structure you like. Be sure to include date, text, and number field types in the data structure. If in doubt, any of the previous cyclone, earthquake, wildfire, or tsunami activities may be used as data examples.

Lesson Summary
Additional items may be contributed by course participants
 * A Database is a structured set of data held in a computer, especially one that is accessible in various ways.
 * SQL commands are instructions used to communicate with a database to perform tasks, functions, and queries with data.
 * SQLite is an open-source, zero-configuration, self-contained, stand-alone, transaction relational database engine designed to be embedded into an application.
 * SQL Server is a relational database management system, or RDBMS, developed and marketed by Microsoft.
 * SQLite has no standalone processes. It is linked in and becomes an integral part of an application. The application program uses SQLite’s functionality through simple function calls.
 * SQLite stores the entire database as a single file on a host machine.
 * SQLite is a widely used database engine. It can be found in Android and iPhone devices, used with Skype and iTunes, and several other popular applications.

Key Terms
Additional items may be contributed by course participants
 * CRUD (Create, Read Update, and Delete)
 * The four basic functions a data application performs:
 * Create - Insert a new record into the database
 * Read - Select a record and display it to the user
 * Update - Update or brings a change to a record in the database
 * Delete - Remove a record from the database


 * database query
 * A request to access data from a database to manipulate it or retrieve it.


 * normalization
 * The process of organizing data in a database. This includes creating tables and establishing relationships between those tables according to rules designed both to protect the data and to make the database more flexible by eliminating redundancy and inconsistent dependency.


 * NoSQL (No Structured Query Langauge)
 * Term used for non-relational databases, an example being MongoDB.


 * Structured Query Language (SQL)
 * Language used to communicate with a database.