Wednesday, 16 November 2016

Queries Etc

Parameters

When running a query it is useful for at least one parameter to be used so that the query is more meaningful. A parameter is literally the search criteria for the query. It means that when the query is ran, a result that matches the parameter will be given.
E.g., in a database with names, searching Bob (based on first name) will mean the query brings up everyone called Bob.
E.g, in a database with names, searching bobjones@outlook.com will find the person with that email address in the database.
The definition of parameter: The value that is used by a query to select the records.
Parameters are not limited to a single criteria and can be used to search for records within a range.
Wildcards are used to search for things even if you don’t know the exact thing that you are searching for. An asterisk (*) is used to denote a wildcard.

Simple Queries

A Simple Query may search through all the fields in a table using a single parameter. It may also only use the necessary fields, but again it will still only use one parameter.

Complex Queries

A complex query is a query that uses more than one parameter.
For example, it may be an AND query. An AND query is used when two parameters are required (e.g. when first name = Bob AND age = 55). This is used when the name and the age must be the same for the record to be returned.
In addition, an OR query may be used. This is where the record can contain either, but does not have to contain both. (e.g. when first name = Bob OR email = bobjones@outlook.com)
There is also the NOT query. This requires an example to explain. With a list of events in a database, you may want to find all events that are not a doctor’s appointment. In this case, the parameter would be doctor’s appointment (gpappointment). This means it will find every event that is not (gpappointment)/doctor’s appointment.

Static Queries

A static query is where the parameter has been hard coded into the query. This means that the parameter cannot be changed at a later date.

Dynamic Queries

Dynamic queries are the opposite to static queries. The parameter is not hard coded and therefore can be changed. This is useful because the database user may want to find different things each time. For example, it would be used to search for a customer by their last name or email. This is because not every customer is going to have the same last name or email and therefore it brings up the people being searched for in the database every time rather than someone who may only need to be searched once.


No comments:

Post a Comment