S 2.134 Guidelines for database queries

Initiation responsibility: IT Security Officer, Head of IT

Implementation responsibility: Application Developer

The relational database language SQL (Structured Query Language) is a standardised international language for relational database systems (DBS) that is now widely used and is implemented in most database management systems (DBMS). The commands of the language are specified in regularly revised standards (ANSI SQL-92, ANSI SQL-99, or ANSI SQL-2003). SQL can be used to modify data (UPDATE, INSERT, DELETE), manipulate database objects (CREATE, ALTER, DROP) and request information (SELECT).

Guidelines for the efficient, maintainable, and understandable programming of database queries must be created and implemented when actually programming. The following basic principles should be described in this guideline:

The field "ID" is available in both tables, and for this reason, the corresponding table names must be specified explicitly in the database query. Otherwise, it is not possible to ensure the uniqueness of the selection, and the database query will be rejected with the issue of a corresponding error message.

All other fields can be allocated uniquely to the relevant tables in this case. SQL does not require an explicit specification of the related table name for each field. Nevertheless, the individual fields should be allocated to the tables, as shown above in the "Price" and "Designation" fields of table TabB. The addition of a "Designation" field to TabA would not lead to any problems in the example given above. However, this would not be the case if the SQL statement did not contain an explicit allocation of the fields to the tables. It would be impossible to determine if the "Designation" field in TabA or TabB should be selected since both tables would have a field with this name after changing TabA. The SQL statement would then be aborted with a corresponding error message.

Review questions: