Download databases - RealTechSupport

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project

Document related concepts

Microsoft SQL Server wikipedia , lookup

Relational algebra wikipedia , lookup

Encyclopedia of World Problems and Human Potential wikipedia , lookup

Microsoft Access wikipedia , lookup

Global serializability wikipedia , lookup

IMDb wikipedia , lookup

SQL wikipedia , lookup

Oracle Database wikipedia , lookup

Open Database Connectivity wikipedia , lookup

Entity–attribute–value model wikipedia , lookup

Microsoft Jet Database Engine wikipedia , lookup

Concurrency control wikipedia , lookup

Functional Database Model wikipedia , lookup

Ingres (database) wikipedia , lookup

Extensible Storage Engine wikipedia , lookup

Database wikipedia , lookup

Healthcare Cost and Utilization Project wikipedia , lookup

ContactPoint wikipedia , lookup

Clusterpoint wikipedia , lookup

Relational model wikipedia , lookup

Database model wikipedia , lookup

Transcript
DATABASES
(bases for your data)
Databases
A database is structured collection of data. Thus, card
indices, printed catalogs of archaeological artefacts
and telephone directories are all examples of
databases. Databases may be stored on a computer
and examined using a program. These programs are
often called `databases', but more strictly are database
management systems (DMS).
source: http://www.ucl.ac.uk/archaeology/cisp/database/manual/node1.html
Databases
Just as a card index or catalog has to be
constructed carefully in order to be useful, so
must a database on a computer.
Similarly, just as there are many ways that a
printed catalog can be organized, there are many
ways, or models, by which a computerized
database may be organized.
One of the most common and powerful models is
the `relational' model, and programs which use
this model are known as relational database
management systems (RDMS).
Databases
Computer-based databases are usually organized
into one or more tables.
A table stores data in a format similar to a
published table and consists of a series of rows
and columns.
Just as a published table will have a title at the
top of each column, so each column in a
database table will have a name, often called a
field name.
Each row in a table will represent one example of
the type of object about which data has been
collected.
Databases
Every row in a table in a relational database must
be unique, there must not be two identical rows.
One or more columns are therefore designated
the primary key (sometimes called the unique
identifier) for the items contained within it.
Foreign keys are columns in a table which provide
a link to another table.
Databases
Example:
database: water, table: watersamples
Primary key
color
taste
smell
temperature
1
blue
metallic
phosphorous
cold
2
red
none
none
warm
3
none
earthy
putrid
warm
4
white
chalky
none
warm
Databases
A common and powerful method for organizing
data for computerization is the relational data
model.
The crafting of a relational database requires one
to organize the data and break it into several
different tables.
This process of breaking data down into a series
of tables is called normalization and is the first
and most important step in designing a relational
database.
Databases
Normalization is the process of identifying entities
and their attributes, and defining the relationship
between the entities.
There are three types of relationship between
entities: one-to-one, one-to-many, and many-tomany.
Databases
One-to-one relationship:
This is the case where there is, for any one entity, only one
example of another related entity.
One-to-many relationship:
This is the case where there is, for any one entity, many
examples of another entity. Here the information about
each entity must be stored in separate tables.
Many-to-many relationship:
This is the case where an entity can have many examples
of another entity but this second entity can also have many
examples of the first. This type of relationship necessitates
the use of a third table, creating two one-to-many
relationships
Databases
PostgreSQL
PostgreSQL is an object-relational database
management system (ORDBMS) based on POSTGRES,
developed at the University of California at Berkeley
Computer Science Department. POSTGRES pioneered
many concepts that only became available in some
commercial database systems much later.
It is a large project. Convince yourself of this fact:
http://www.postgresql.org/docs/9.3/interactive/index.html
Databases
PostgreSQL
All database system share two main features:
the ability to allow one to enter data into the system and
to get / select data from the system.
Databases
Discovery:
psql -d databasename -U username
databasename=#
\l :List databases
\d :List tables in database
\d table-name :Describe table
select * from table-name :List table contents
Databases
Before you can select data, you have to have data
(and data containers.) The main data container of a
database is the table.
Create a table in PSQL:
CREATE TABLE mytable (
id serial NOT NULL PRIMARY KEY,
color VARCHAR (25),
smell VARCHAR (25)
);
Databases
Insert values into a table:
INSERT INTO mytable (color, smell) VALUES('red', 'gross');
Databases
PostgreSQL
Select data - general form:
SELECT color, smell, … FROM mytable
Select all entries from a table:
SELECT * FROM mytable;
Select only entries that are unique:
SELECT DISTINCT color FROM mytable;
Select and order:
SELECT DISTINCT ON color FROM mytable
ORDER BY datetime;
Databases
CREATE TABLE weather(
location varchar(40) NOT NULL,
sample_collected timestamp NOT NULL,
database_entered timestamp default now(),
.....
);
location
sample_collected
database_entered
barometer
rain
rainrate
outhumidity
outtemp
windgust
windgustdir
windspeed
| character varying(40)
| timestamp without time zone
| timestamp without time zone
| double precision
| double precision
| double precision
| integer
| double precision
| double precision
| double precision
| double precision
| not null
| not null
| default now()
Databases
Databases
Databases
CREATE TABLE weather(
location varchar(40) NOT NULL,
sample_collected timestamp NOT NULL,
database_entered timestamp default now(),
.....
);
location
sample_collected
database_entered
barometer
rain
rainrate
outhumidity
outtemp
windgust
windgustdir
windspeed
| character varying(40)
| timestamp without time zone
| timestamp without time zone
| double precision
| double precision
| double precision
| integer
| double precision
| double precision
| double precision
| double precision
| not null
| not null
| default now()
Databases