0% found this document useful (0 votes)
16 views7 pages

Data Processing Year 11 2nd Term Note

The document provides an overview of relational databases, including their structure, the use of SQL for data manipulation, and the importance of integrity constraints. It explains various SQL commands for querying and modifying data, as well as types of integrity constraints that ensure data validity. Additionally, it introduces Microsoft Access as a user-friendly tool for querying databases, demonstrating how to create and refine SELECT queries.

Uploaded by

17010211083d
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16 views7 pages

Data Processing Year 11 2nd Term Note

The document provides an overview of relational databases, including their structure, the use of SQL for data manipulation, and the importance of integrity constraints. It explains various SQL commands for querying and modifying data, as well as types of integrity constraints that ensure data validity. Additionally, it introduces Microsoft Access as a user-friendly tool for querying databases, demonstrating how to create and refine SELECT queries.

Uploaded by

17010211083d
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

Week 1-2

Relation Database

A relational database is a collection of data items organized as a set offormally-described


tables from which data can be accessed orreassembled in many different ways without having
to reorganize thedatabase tables. The relational database was invented by E. F.Codd at IBMin
1970.

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.

Creating and modifying relations using SQL

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 * FROM Customers;

Some of The Most Important SQL Commands

·SELECT - extracts data from a database

· UPDATE - updates data in a database

·DELETE - deletes data from a database

·INSERT INTO - inserts new data into a database

·CREATE DATABASE- creates a new database


·ALTER DATABASE- modifies a database

· CREATE TABLE - creates a new table

·ALTER TABLE- modifies a table

· DROP TABLE - deletes a table

· CREATE INDEX - creates an index (search key)

·DROP INDEX- deletes an index

The SELECT statement is used to select data from a database.

The SQL SELECT Statement

The SELECT statement is used to select data from a database.

The result is stored in a result table, called the result-set.

SQL SELECT Syntax

SELECT column_name,column_name

FROM table_name;

and

SELECT *FROM table_name;


WEEK:3-4

TOPIC: Relational Database-Integrity Constraints

CONTENT

RELATIONAL MODEL- Integrity Constraints

Integrity Constraints over Relations

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.

Many kinds of integrity constraints can be specified in the relational model:

Database integrity refers to the validity and consistency of stored data.

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.

TYPES OF INTEGRITY CONSTRAINTS

Various types of integrity constraints are-

1.Domain Integrity

2.Entity Integrity Constraint

3. Referential Integrity Constraint

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.

There are 4 types of keyconstraints-

1. Candidate key.

2.Super key

3.Primary key

4.Foreign key
WEEK:5

TOPIC: Querying Relational Database

CONTENT

SELECT Query Basics

Print

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.

A. Download an Access database and review its tables

Throughout this lesson, we'll use a database of baseball statistics to helpdemonstrate the
basics of SLECT queries.

1. Open the database in MS-Access.

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.

B.Write a simple SELECT query

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.

5. Repeat this step to add the YEAR and RBI fields.

· 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.

C.Restrict the returned records to a desired subset

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).

D.Sort the returned records

1.Return to Design View.

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.

3.Test the query.

E. Add additional criteria to the selection

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.

2. Test the query, (it should return 53 records).

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.

4. Test the query, (it shoud return 34 records).

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

identifies 100-RBI seasonssince 1989 OR prior to 1960. However,the


query as written at this point doesn'tquite yield that result, look at

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

ones). To produce the desired result you need to repeat

the >99 criterion in the RBI field's :or cell,check the SQL view to see

the change.

·Test the query, (it should return 74 records).

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.

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy