• Tidak ada hasil yang ditemukan

Intro to Database PPT

N/A
N/A
Abdullah Khedr

Academic year: 2023

Membagikan "Intro to Database PPT"

Copied!
21
0
0

Teks penuh

(1)

Intro to Database

Prof. Ali Eldesouki

Dr. Mohamed Abd Elfattah

(2)

What is a Database?

A database is a set of data stored in a computer. This data is

usually structured in a way that makes the data easily accessible.

What is a Relational Database?

A relational database is a type of

database. It uses a structure that

allows us to identify and access data

in relation to another piece of data

in the database. Often, data in a

relational database is organized into

tables.

(3)

Tables: Rows and Columns

Tables can have hundreds, thousands, sometimes even millions of rows of data. These rows are often called records.

Tables can also have many columns of data. Columns are labeled with a descriptive name (say, age for example) and have a specific data type.

P.K ??

Degree ??

Domain ??

Tuples ??

(4)

What is table/Relation?

Everything in a relational database is stored in the form of relations. The RDBMS database uses tables to store data. A table is a collection of related data entries and contains rows and columns to store data. Each table represents some real-world objects such as person, place, or event about which information is collected. The organized collection of data into a relational table is known as the logical view of the database.

Properties of a Relation:

•Each relation has a unique name by which it is identified in the database.

•Relation does not contain duplicate tuples.

•The tuples of a relation have no specific order.

•All attributes in a relation are atomic, i.e., each cell of a relation contains exactly one value.

(5)

Degree:

The total number of attributes that comprise a relation is known as the degree of the table.

ID Name AGE COURSE

1 Ajeet 24 B.Tech

2 aryan 20 C.A

3 Mahesh 21 BCA

4 Ratan 22 MCA

5 Vimal 26 BSC

Cardinality:

The total number of tuples at any one time in a relation is known as the table's cardinality. The relation whose cardinality is 0 is called an empty table.

Domain:

The domain refers to the possible values each attribute can contain. It can be specified using standard data types such as integers, floating numbers, etc

NULL Values

The NULL value of the table specifies that the field has been left blank during record creation. It is different from the value filled with zero or a field that contains space.

(6)

Data Integrity

There are the following categories of data integrity exist with each RDBMS:

Entity integrity: It specifies that there should be no duplicate rows in a table.

Domain integrity: It enforces valid entries for a given column by restricting the type, the format, or the range of values.

Referential integrity specifies that rows cannot be deleted, which are used by other records.

User-defined integrity: It enforces some specific business rules defined by users. These rules are different from the entity, domain, or referential integrity.

(7)

Data Types

When defining the fields in a database table, we must give each field a data type. For example, the field Birth Year is a year, so it will be a number, while First Name will be text.

Most modern databases allow for several different data types to be stored. Some of the more common data types are listed here:

Text: for storing non-numeric data that is brief, generally under 256 characters. The database designer can identify the maximum length of the text.

Number: for storing numbers. There are usually a few different number types that can be selected, depending on how large the largest number will be.

Yes/No: a special form of the number data type that is (usually) one byte long, with a 0 for “No” or

“False” and a 1 for “Yes” or “True”.

Date/Time: a special form of the number data type that can be interpreted as a number or a time.

Currency: a special form of the number data type that formats all values with a currency indicator and two decimal places.

Paragraph Text: this data type allows for text longer than 256 characters.

Object: this data type allows for the storage of data that cannot be entered via keyboard, such as an image or a music file.

(8)

A superkey is a set of one or more attributes that, taken collectively, allow us to identify uniquely a tuple in the relation. A superkey may contain extraneous attributes. For example, the combination of ID and name is a superkey for the relation instructor.

Candidate keys are superkeys for which no proper subset is a superkey, Such minimal superkeys. It is possible that several distinct sets of attributes could serve as a candidate key.

The primary key The candidate key that is selected to identify tuples uniquely within the relation

The candidate keys that are not selected to be the primary key are called alternate keys.

Ex2:

Ex1:

(9)

A referential integrity constraint; requires that the values appearing in specified attributes of any tuple in the referencing relation also appear in specified attributes of at least one tuple in the referenced relation.

(10)

Representing Relational Database Schemas

(11)

Instance of the Dream Home rental database.

(12)
(13)
(14)

Integrity Constraints

Represents a value for an attribute that is currently unknown or is not applicable for this tuple.

Null

A null can be taken to mean the logical value “unknown.” It can mean that a value is not applicable to a particular tuple, or it could merely mean that no value has yet been supplied. Nulls are a way to deal with incomplete or exceptional data.

the comment attribute may be undefined until the potential renter has visited the property and returned his or her comment to the agency. Without nulls, it becomes necessary to introduce false data to represent this state or to add additional attributes that may not be meaningful to the user

(15)

Entity Integrity

In a base relation, no attribute of a primary key can be null

By definition, a primary key is a minimal identifier that is used to identify tuples uniquely. This means that no subset of the primary key is sufficient to provide unique identification of tuples

Referential Integrity

If a foreign key exists in a relation, either the foreign key value must match a candidate key value of some tuple in its home relation or the foreign key value must be wholly null.

(16)

For example, branchNo in the Staff relation is a foreign key targeting the

branchNo attribute in the home relation, Branch. It should not be possible to create a staff record with branch number B025, for example, unless there is already a record for branch number B025 in the Branch relation. However, we should be able to create a new staff record with a null branch number to allow for the situation where a new member of staff has joined the company but has not yet been

assigned to a particular branch office.

foreign key Primary key

(17)

General Constraints

Additional rules specified by the users or database administrators of a database that define or constrain some aspect of the enterprise.

Terminology Meaning

Base relation A named relation corresponding to an entity in the conceptual schema, whose tuples are physically stored in the database.

View

The dynamic result of one or more relational operations operating on the base relations to produce another relation. A view is a

virtual relation that does not necessarily exist in the database but can be produced upon request by a particular user, at the time of request.

(18)

The view mechanism is desirable for several reasons:

• It provides a powerful and flexible security mechanism by hiding parts of the database from certain users. Users are not aware of the existence of any attributes or tuples that are missing from the view.

• It permits users to access data in a way that is customized to their needs, so that the same data can be seen by different users in different ways, at the same time.

• It can simplify complex operations on the base relations. For example, if a view is defined as a combination (join) of two relations , users may

now perform more simple operations on the view, which will be translated by the DBMS into equivalent operations on the join.

(19)

Relational Algebra and

Relational Calculus

(20)
(21)

Selection operation

Result

Referensi

Dokumen terkait