Beruflich Dokumente
Kultur Dokumente
What is a database?
Database is an electronic administration system that has to handle
large amounts of data efficiently, without contradiction, permanently and can
represent logical relationships digitally.
Data sets can be collocated from various subsets and displayed as
required for application programs and their users.
For example, the different user groups of the databases convert data into
delivery notes
customer data
billing information
create, edit or remove.
Database
(DB)
ER model
The Entity ReIationship model (ER model for short) describes data as
entities, relationships and attributes.
An entity represents a clearly identifiable object or concept from the
real world, e.g. a product or an employee, which is described in the
database.
An attribute represents a property that further executes the Entity 1 relation Entity 2
description of an entity, for example, the name or salary level of the
employee.
A relationship between two or more entities represents a relationship
between the entities, for example, a working relationship between an attribute attribute
employee and a project.
attributes
One differentiates between compound or simple (atomic) attributes.
Composite attributes can be broken down into smaller parts that represent
more basic attributes with independent meanings. For example, an attribute
"Address" of the Employee entity can be divided into the attributes "Street",
"House number" and "City".
Employee
relationships
A relationship describes the relationship between two entity types. For
example, an employee works in a department.
A relationship type can also have attributes. In our example, this could be
the beginning of the employment relationship as a date. Relationship types
usually have certain restrictions that limit the possible combinations of Employee relation department
entities that can participate in the corresponding set of relationships.
cardinality relationship
There are different forms of notation for the cardinality relationship of two
entity types. We will limit ourselves to the so-called Min-Max notation.
The min-max notation consists of two numbers, which indicate for each
entity type how many times that entity type must (first number) and may
(second number) enter at least one relationship with another entity type.
cardinality relationship
An important restriction for the entities of an entity type is the key or
uniqueness restriction for attributes. An entity type usually has an attribute
whose values differ for each individual entity in the collection. Such an Address
attribute is called a key attribute and each entity can be uniquely identified
by its values.
Employee SvNr
For example, the Name attribute is a key for the entity type Company
because no two companies can have the same name. For the entity type
Person, the social insurance number (SvNr.) is a typical key attribute. name
Sometimes several attributes together form a key, which means that the
combination of attribute values of each entity must be different. If such a
key cannot be generated from the given attributes or if the circumstances
require it, a key can also be generated artificially. This is then often a
unique identification number (ID) in the relation. (1:n) consists (1:1)
firm department
In the ER model, each key attribute is represented as an oval with its of
underlined name.
A company consists of at least one department, but can have n many departments
include. A department belongs to exactly one company.
employees
department
ID department name
… …
5 Safety and security
… …
ID ID LevelId
earns
Department (1:1) (0:n)
FirstName Salary
Name
LastName
Address
Works
in
(0:n) (1:1) Department
SalaryLevel
SQL
Now that a database has been designed, it is time to work with it, i.e.
create tables, enter data records into it, query or remove them from it. The
Structured Query Language (SQL) is available for these operations.
Database system
(DBS)
The SQL language is considered one of the most important reasons for the
success of relational databases in the commercial world. Because it has Database Database
become the standard for relational databases, users are less concerned Management application
about migrating their database applications from database system types,
such as network or hierarchical systems, to relational systems. Another System (DBMS) (DBA)
advantage of such a standard: Users can write statements in a database
application program that accesses data stored in two or more relational
DBMSs without having to change the database language (SQL) if both
relational DBMSs support the SQL standard. Database
(DB)
...
data type designation PRIMARY KEY(id),
FOREIGN KEY(Department) REFERENCES departments(ID),
INTEGER or INT integer
...
DECIMAL(x,y) X-digit number, with y decimal places
The first command sets the employee ID as the primary key. This must, of
CHAR(n) Character string of fixed length n course, be clear. The second command specifies the Department column of
our table as a foreign key and refers (REFERENCES) to the relation that
VARCHAR(n) variable string with up to n characters contains the values (Department table, ID column).
DATE Date (year, month, day) Of course, the relation department must also be present when we refer to
it. For this reason, the tables for departments and salary levels are
TIME Time (hour, minute, second)
created analogously.
BLOB Binary Large Object. large, binary objects such as
image or audio files
Insert data
The tables can be filled with corresponding contents.
In the simplest form, the command is used to insert a single tuple into a
relation. The values should be listed in the same order in which the
corresponding attributes were specified in the Create command.
retrieve data
data records can be determined from the tables with query (select) SELECT FirstName, LastName
commands. FROM Employees
The basic form of the Select statement, also known as a mapping or WHERE Department = 5;
SELECT-FROM-WHERE block, consists of the three clauses SELECT, FirstName LastName
FROM, and WHERE. Victor Almost
The attribute list is a list of attribute names (columns) whose values are
generated when the query is executed. The table list is a list with the names
of the relations accessed for the execution of the query and the condition
describes a conditional expression that qualifies the tuples to be processed
SELECT FirstName, LastName
with the query.
FROM Employees
Several conditions can also be queried in the WHERE clause of the query. WHERE Department = 5 AND FirstName = "Victor";
These are connected by the keywords AND, OR, NOT. FirstName LastName
Victor Almost
LastName, Erikahof 80
Blum
77761 Schiltach
Address AS CareOf
FROM Geiststr. 90
Mitchell
94255 Böbrach
Employees
WHERE Florentine-Eichler-Str. 189
Obermüller
67297 Marnheim, Germany
Department = 3;
COUNT(*) Counts all the entries in a column and outputs a result relation,
which shows the department and the respective number of
of your employees.
SELECT Department amount
Department, 1 4
COUNT(*) AS amount 2 4
FROM 3 3
Employees
4 3
GROUP BY
Department; 5 3
6 3
...displays the first and last names of all employees whose first name is Helen brack
exactly 5 characters long and has an "n" as the third letter. Liam bluebottle
Delete data
The DELETE command removes tuples from a relation. It contains a
WHERE clause, similar to the one in the SQL query, to select the tuples to
be deleted. Tuples are explicitly deleted from only one table at a time.
This removes all tuples from the relation, which are used as surnames.
"Grimes" have.
A missing WHERE clause indicates that all tuples in the relation are to be
deleted. However, the table remains in the database as an empty table.
The DROP TABLE command is available to finally delete a table. So in
our example this would be:
SELECT
FirstName Surname department
Employees.FirstName,
name
Employees.LastName,
Victor Almost Security
Departments.DepartmentName
FROM anastasia houses Security
Employees, Sonya poppy Security
Departments
WHERE
DepartmentName = 'Security'
AND Employees.Department = Departments.id;
The JOIN operator is very extensive. Besides the INNER JOIN there is
also the OUTER JOIN, which can be divided into FULL OUTER JOIN, FirstName LastName DepartmentName
LEFT JOIN and RIGHT JOIN.
Victor Almost Security
anastasia houses Security
Sonya poppy Security