You are on page 1of 14

Part A

1. List and explain three uses of databases.


What is Data?
In simple words, data can be facts related to any object in consideration. For example, your
name, age, height, weight, etc. are some data related to you. A picture, image, file, pdf, etc. can
also be considered data

What is Database?

A database is a systematic collection of data. They support electronic storage and manipulation
of data. Databases make data management easy.

Let us discuss a database example: An online telephone directory uses a database to store data of
people, phone numbers, and other contact details. Your electricity service provider uses a
database to manage billing, client-related issues, handle fault data, etc.

Databases are useful in many different scenarios for storing data. It is typical to use a database when
different sets of data needs to be linked together, such as:

Pupils in a school and their grades

Customer records and sales information

Patients’ and doctors’ records

Transactions between different bank accounts

Taxpayers and income tax payments

The three main advantages that databases have over other, simpler data storage systems (such as text
files and spreadsheets) are access, integrity, and security.

Uses for database systems

Uses for database systems include:

They store data and provide facilities (tools) to search for specific records in a given set of data.

They store special information used to manage the data. This information is called metadata and it is not
shown to all the people looking at the data.

They can solve cases where many users want to access (and possibly change) the same entries of data.

They manage access rights (who is allowed to see the data, who can change it)
When there are many users asking questions to the database, the questions must be answered faster. In
this way, the last person to ask a question can get an answer in a reasonable time.

Certain attributes are more important than others and can be used to find other data. This is called
indexing. An index contains all the important data and can be used to find other data.

They ensure that the data always has context. There are a lot of different rules that can be added to tell
the database system if the data makes sense. One of the rules might say November has 30 days. This
means if someone wants to enter November 31 as a date, this change will be rejected.

Databases are used for storing, maintaining and accessing any sort of data. They collect
information on people, places or things. That information is gathered in one place so that it can
be observed and analyzed. Databases can be thought of as an organized collection of
information.

2. In databases, users input different kinds of data. Give any 5 datatypes and

explain the type of data they accept

Data type is an attribute associated with a piece of data that tells a computer system how to interpret its
value. Understanding data types ensures that data is collected in the preferred format and the value of
each property is as expected.

A data type, in programming, is a classification that specifies which type of value a variable has and what
type of mathematical, relational or logical operations can be applied to it without causing an error. A
string, for example, is a data type that is used to classify text and an integer is a data type used to
classify whole numbers.

A data type is a classification of data which tells the compiler or interpreter how the programmer
intends to use the data. Most programming languages support various types of data, including integer,
real, character or string, and Boolean

The data type defines which operations can safely be performed to create,


transform and use the variable in another computation. When a program
language requires a variable to only be used in ways that respect its data
type, that language is said to be strongly typed. This prevents errors, because
while it is logical to ask the computer to multiply a float by an integer (1.5 x 5),
it is illogical to ask the computer to multiply a float by a string (1.5 x Alice).
When a programming language allows a variable of one data type to be used
as if it were a value of another data type, the language is said to be weakly
typed.
Common data types

Integer (int)

It is the most common numeric data type used to store numbers without a fractional component (-707,
0, 707).
Floating Point (float)

It is also a numeric data type used to store numbers that may have a fractional component like
monetary values do (707.07, 0.7, 707.00).

Please note that number is often used as a data type that includes both int and float types.

Character (char)

It is used to store a single letter, digit, punctuation mark, symbol, or blank space.

String (str or text)

It is a sequence of characters and the most commonly used data type to store text. Additionally, a string
can also include digits and symbols, however, it is always treated as text.

A phone number is usually stored as a string (+1-999-666-3333) but can also be stored as an integer
(9996663333).

Boolean (bool)

It represents the values true and false. When working with the boolean data type, it is helpful to keep in
mind that sometimes a boolean value is also represented as 0 (for false) and 1 (for true).

Enumerated type (enum)

It contains a small set of predefined unique values (also known as elements or enumerators) that can be
compared and assigned to a variable of enumerated data type.

The values of an enumerated type can be text-based or numerical. In fact, the boolean data type is a
pre-defined enumeration of the values true and false.

For example, if rock and jazz are the enumerators, an enumerated type variable genre can be assigned
either of the two values, but not both.

Assuming that you are asked to fill in your preferences on a music app and are asked to choose either
one of the two genres via a dropdown menu, the variable genre will store either rock or jazz.

With enumerated type, values can be stored and retrieved as numeric indices (0, 1, 2) or strings.

Array

Also known as a list, an array is a data type that stores a number of elements in a specific order, typically
all of the same type.

Since an array stores multiple elements or values, the structure of data stored by an array is referred to
as an array data structure.

Each element of an array can be retrieved using an integer index (0, 1, 2,…), and the total number of
elements in an array represents the length of an array.
For example, an array variable genre can store one or more of the elements rock, jazz, and blues. The
indices of the three values are 0 (rock), 1 (jazz), and 2 (blues), and the length of the array is 3 (since it
contains three elements).

Continuing on the example of the music app, if you are asked to choose one or more of the three genres
and you happen to like all three (cheers to that), the variable genre will store all three elements (rock,
jazz, blues).

Date

Needs no explanation; typically stores a date in the YYYY-MM-DD format (ISO 8601 syntax).

Time

Stores a time in the hh:mm:ss format. Besides the time of the day, it can also be used to store the time
elapsed or the time interval between two events which could be more than 24 hours. For example, the
time elapsed since an event took place could be 72+ hours (72:00:59).

Datetime

Stores a value containing both date and time together in the YYYY-MM-DD hh:mm:ss format.

Data Type Used for Example

String Alphanumeric characters hello world, Alice,


Bob123
A sequence of characters

Integer Whole numbers 7, 12, 999

Float (floating point) Number with a decimal 3.15, 9.06, 00.13


point
floating point (real)
fractional numbers

Character Encoding text numerically 97 (in ASCII, 97 is a


lower case 'a')

Boolean Representing logical TRUE, FALSE


values

logical true or false

2. Explain a Query, and how to delete a query.

What Does Query Mean?


A query is a request for data or information from a database table or
combination of tables.

Query is another word for question. In fact, outside of computing terminology, the words "query" and
"question" can be used interchangeably. For example, if you need additional information from
someone, you might say, "I have a query for you." In computing, queries are also used to retrieve
information. However, computer queries are sent to a computer system and are processed by a
software program rather than a person.

One type of query, which many people perform multiple times a day, is a search query. Each time you
search for something using a search engine, you perform a search query. When you press Enter,
the keywords are sent to the search engine and are processed using an algorithm that retrieves
related results from the search index. The results of your query appear on a search engine results
page, or SERP.

Another common type of query is a database query. Databases store data in a structured format,


which can be accessed using queries. In fact, the structured query language (SQL) was designed
specifically for this purpose. Users can create SQL queries that retrieve specific information from a
database. For example, an human resources manager may perform a query on an employee database
that selects all employees in a specific department that were hired between 11 and 12 months ago.
The results might be used to provide the department head with current candidates for an annual
review.
While you may not always notice them, computer queries are happening all the time. For instance,
most dynamic websites query a database each time you visit a new page. Software applications often
contain background functions that perform queries based on your input. While many types of
computer queries exist, their basic purpose is the same — to receive an answer to a question.

NOTE: The word "query" can be used as either noun or a verb. For example, you can "perform a
search query" or "query a database." Both examples are correct uses of the word "query."

When you want to either quickly delete a lot of data or delete a set of data on a regular basis in an
Access desktop database, a delete or an update query might be useful because the queries make it
possible to specify criteria to quickly find and delete the data. Using a query can also be a timesaver
because you can reuse a saved query.

Note: Before you delete any data or run a delete query, make sure that you have a backup of your
Access desktop database.

If you want to only delete a few records, you don’t need a query. Just open the table in Datasheet view,
select the fields (columns) or records (rows) that you want to delete, and then press DELETE.

Choosing a query type


You can use either an update query or a delete query to
delete data from your database. Select a query based
on the details in the following table:
Type of When to use it Results
query
Use a To remove entire records (rows) from a Delete queries remove all the data in
delete table or from two related tables each field, including the key value
query simultaneously. that makes a record unique
Type of When to use it Results
query

Note: If the records reside on the "one" side


of a one-to-many relationship, you might
need to change the relationship before you
run the delete query. See the section
on deleting data from related tables.

Use an To delete individual field values from a Makes it easier to delete values by
update table. updating the existing values to
query either a null value (that is, no data)
or a zero-length string (a pair of
double quotation marks with no
space between them).

A DELETE query is an action query (SQL statement) that deletes a set of


records according to criteria (search conditions) you specify. It's a very
powerful feature and a fundamental part of relational databases since you
can remove multiple records at one time, and can specify which records to
delete by linking to data in another table.
Understanding and using Delete Queries improves the performance of your
applications (versus doing the same changes manually or in code), and
makes them easier to maintain.
From the Access designer, you can interactively create a query and specify
its type:

Delete Query Option when Designing Queries in MS Access 2013 and 2016
Delete Query Option when Designing Queries in MS Access 2007 and 2010
Delete Queries let you:
 Empty a table (delete all its records)
 Delete all records with a particular value in a field
 Delete all records with a range of values in a field
 Delete records based on criteria in multiple fields
 Delete records with matching values field(s) in a joined table

When you use a DELETE query, only the data is deleted; the table structure
and all of the table properties, such as field attributes and indexes, remain
intact.
You can use DELETE to remove records from tables that are in a one-to-
many relationship with other tables. Cascade delete operations cause the
records in tables that are on the many side of the relationship to be deleted
when the corresponding record in the one side of the relationship is deleted
in the query. For example, in the relationship between the Customers and
Orders tables, the Customers table is on the one side and the Orders table is
on the many side of the relationship. Deleting a record from Customers
results in the corresponding Orders records being deleted if the cascade
delete option is specified.
A DELETE query deletes entire records, not just data in specific fields. If you
want to delete values in a specific field, create an update query that changes
the values to Null.

Important
 After you remove records using a delete query, you cannot undo the
operation. If you want to know which records were deleted, first
examine the results of a select query that uses the same criteria, and
then run the delete query.
 Maintain backup copies of your data at all times. If you delete the
wrong records, you can retrieve them from your backup copy.
Delete Queries
Definitely the most dangerous of all queries is a delete query, a query that
deletes a whole bunch of records at a time. Once you have deleted records using
a delete query, you cannot undo the resultsthe records are gone forever!

Creating a delete query is no different than creating a select querywith one very
important difference: While a select query displays the records that match your
criteria, a delete query deletes those records. For this reason, you should always
preview the results of a delete query in Datasheet View to see which records will
be deleted.

A delete query

Access asks you to confirm the query.

If you want to delete records from multiple tablesfor example, a customer and all
of that customer's ordersyou need to do a few things first:

 Define relationships between the tables.


 Establish referential integrity for the join(s) between the tables and turn on
the Cascade Delete Related Records option.

LeAnne Chang, one of North Shore Travel's managers, decides to open her own
competing travel agency across the street, and being the vindictive person she is,
takes all her customers with her. In this lesson you will create a delete query to
delete all the tours sold by LeAnne Chang.

1. From the Database window, click the Queries icon in the Objects bar and
click the New button.

The New Query dialog box appears.

2. Select Design View and click OK.

The query design window and Show Table dialog box both appear. You
have to select the tables and/or queries you want to use in the delete
query.

3. Click the tblEmployees table and click Add.

A field list for the tblEmployees table appears in the top half of the query
design window.

4. Add the tblCustomerTours table and tblTours table to the query.

When you have finished adding the tables and/or queries, you can close
the Show Table dialog box.

5. Click Close.

If the tables are related, Access automatically connects their common fields
with a join line. If the tables aren't related, you will have to manually join
them by dragging a field from one table's field list to the matching field in
the other table's field list.

You need to connect the tblEmployees table with the tblCustomerTours


table.
6. Click the EmployeeID field in the tblEmployees field list and drag and drop
it onto the Employee field in the tblCustomerTours field list.

Now you need to tell Access that this is a delete query.

7. Click the   Query Type button list arrow on the toolbar and select
Delete Query from the list.

Another way to change the type of query is to select Query from the menu
and select the type of query from the list.

Access converts the select query to a delete query and displays the Delete
row in the query design grid. Now you have to tell Access what you want
to delete.

8. Drag the asterisk (*) from the top of the tblCustomerTours field list into the
design grid.

Notice that From appears in the Delete cell for the asterisk field, indicating
that the records will be deleted from the tblCustomerTours table. Unless
you want the query to delete each and every record in the
tblCustomerTours table, you will need to add some limiting criteria. You
decide to use the last name Chang as the limiting criteria.

9. Drag the LastName field from the tblEmployees field list into the design
grid.

This time Where appears in the Delete cell for the LastName field,
indicating that the LastName field will be used as the criteria to select
which records will be deleted from the tblCustomerTours table.

10.Click the LastName column's Criteria row and type Chang.

Access will add the "quotation marks" around the text string Chang for
you, as shown in figure. That's all there is to creating a delete query.

Before you run a delete query, you should always preview the results in
Datasheet view first. Click the View button on the toolbar to display the
delete query in Datasheet view.
11.Click the View button on the toolbar to preview the results of the delete
query in Datasheet view.

The delete query displays the results of the delete query. Let's switch back
to Design view.

12.Click the View button on the toolbar to return to Design view.

Let's run the delete query and delete the selected records.

13.Click the Run button on the toolbar.

Ever-cautious Access asks if you really want the delete query to delete the
records, as shown in figure .

14.Click Yes.

Access silently deletes all 75 tour records for LeAnne Chang.

15.Close the query without saving your changes and open the
qryToursByName query.

Notice that all the tours for LeAnne Chang are gone.

16.Close the qryToursByName query.

To create a delete query:


1. in the database window, click the queries icon in the objects bar and click
the new button.
2. select design view and click ok.
3. add the appropriate tables and queries and click close.
4. connect any unrelated tables.
5. click the query type button list arrow on the toolbar and select delete
query.

or...

select query » delete query from the menu.


6. drag the table from which you want to delete records and the field you
want to use as the criteria onto the design grid.
7. click the view button to view the results of the delete query.
8. if you're satisfied that the appropriate records will be deleted, click the run
button on the toolbar and click yes to confirm the deletion.

Part B

Create a database table. The table should have 5 fields and 10 records. Collect data

of your choice. After creating the database.

Explain

a. The datatypes suitable for your fields

b. The relationship between the data you collected.

You might also like