Data Processing Year 11 2nd Term Note
Data Processing Year 11 2nd Term Note
Relation Database
The standard user and application program interface to a relationaldatabase is the structured
query language (SQL).
A relational database is a set of tables containing data fitted intopredefined categories. Each
table (which is sometimes called a relation)contains one or more data categories in columns.
Each row contains aunique instance of data for the categories defined by the
columns.Forexample, a typical business order entry database would include a tablethat
described a customer with columns for name,address,phonenumber, and so forth. Another table
would describe an order: product,customer, date, sales price, and so forth.
A user of the database could obtain a view of the database that fitted theuser's needs. For
example, a branch office manager might like a view orreport on all customers that had bought
products after a certain date. Afinancial services manager in the same company could, from the
sametables, obtain a report on accounts that needed to be paid.
SQL Statements
Most of the actions you need to perform on a database are done with SQLstatements.
The following SQL statement selects all the records in the "Customers"table:
Example
SELECT column_name,column_name
FROM table_name;
and
CONTENT
An integrity constraint (IC) is a condition specified on a database schemaand restricts the data
that can be stored in an instance of the database. If adatabase instance satisfies all the integrity
constraints specifies on thedatabase schema, it is a legal instance. A DBMS permits only
legalinstances to be stored in the database.
Integrity is usually expressed in terms of constraints, which are consistencyrules that the
database is not permitted to violate.
Constraints may apply to each attribute or they may apply to relationshipsbetween tables.
Integrity constraints ensure that changes (update deletion, inserion) madeto the database by
authorized users do not result in a loss of dataconsistency. Thus, integrity constraints guard
against accidental damage tothe database.
1.Domain Integrity
4.Key Constraints
1.Domain Integrity-Domain integrity means the definition of a valid set ofvalues for an attribute.
You define data type, length or size, is null valueallowed, is the value unique or not for an
attribute,the default value, therange (values in between) and/or specific values for the attribute.
2. Entity Integrity Constraint-This rule states that in any database relationvalue of attribute of a
primary key can't be null.
EXAMPLE-Consider a relation "STUDENT" Where "Stu_id" is a primary keyand it must not contain
any null value whereas other attributes may contain null value e.g "Branch" in the following
relation contains one nullvalue.
3.Referential Integrity Constraint-It states that if a foreign key exists in arelation then either the
foreign key value must match a primary key valueof some tuple in its home relation or the
foreign key value must be null.
4.Key Constraints-A Key Constraint is a statement/condition that acertain minimal subset of the
fields of a relation is a unique identifier for atuple.
1. Candidate key.
2.Super key
3.Primary key
4.Foreign key
WEEK:5
CONTENT
Why MS-Access?
A number of RDBMS vendors provide a GUI to aid their users in developingqueries. These can
be particularly helpful to novice users as it enablesthem to learn the overarching concepts
involved in query developmentwithout getting bogged down in syntax details. For this reason,
we willstart the course with Microsoft Access, which provides perhaps the mostuser-friendly
interface.
Throughout this lesson, we'll use a database of baseball statistics to helpdemonstrate the
basics of SLECT queries.
One part of the Access interface that you'll use frequently is the"Navigation Pane," which is
situated on the left side of the applicationwindow. The top of the Navigation Pane is just
beneath the "Ribbon" (thestrip of controls that runs horizontally along the top of the window).
The Navigation Pane provides access to the objects stored in the database,such as tables,
queries, forms and reports. When you first open thebaseball_stats.accdb database, the
Navigation Pane should appear withthe word Tables at the top, indicating that it is listing the
tables stored inthe database (PLAYERS, STATS and TEAMS).
·Double-click on a table's name in the Navigation Pane to open it.Open all three tables and
review the content. Note that the STATStable contains an ID foreach player rather than his name.
The namesassociated with the IDs are stored in the PLAYERS table.
With our first query we'll retrieve data from selected fields in the STATStable.
1. Click on the Create tab near the top of the application window.
2. Next, click on the Query Design button (found on the left side of theCreate Ribbon in the
group of commands labeled as Queries).
3. In the Show Table dialog, double-click on the STATS table to add it tothe query and click
Close, (when you do this in Access 2010 theribbon switches to the Design ribbon).
4.Double-click on PLAYER_ID in the list of fields in the STATS table toadd that field to the design
grid below.
· At any time, you can view the SQL that's created by your GUI settingsby accessing the View
drop-down list on the far-left side of DesignRibbon, (it is also available when you have the Home
tab selected, asshown below).
As you go through the next steps look at the SQL that corresponds toqueries you are building.
1. From the same View drop-down list, select Design View to return tothe query design GUI.
2. In the design grid, set the Criteria value for the RBI field to >99.
3. Test the query by clicking on the red exclamation point, (it shouldreturn 103 records).
2. In the design grid click in the Sort cell under the RBI column andselect Descending from the
drop-down list. This will sort the recordsfrom highest RBI total to lowest.
1.Return to Design View and set the Criteria value for the YEAR fieldto >1989. This will limit the
results to seasons of over 100 RBI since1990.
3. Return to Design View and modify the Criteria value for the YEARfield to >1989 And<2000,
which will further limit the results to just the1990s.
5. Return to Design View and change the Criteria value for the YEARfield back to>1989,beneath
that cell (in the :or cell) add <1960.
As you should be able to guess, I'm asking you to write a query that
the WHERE line in the SQL view. Instead, it would return 100-RBI
seasons since 1989 and all seasons prior to 1960 (not just the 100-RBI
the >99 criterion in the RBI field's :or cell,check the SQL view to see
the change.
You've probably recognized by now that the output from these queries isnot particularly human
friendly. In the next part of the lesson we'll see howto use a join between the two tables to add
the names of the players to thequery output.