database: collection of data with
Why not in files? There's no query language, a weak logical structure, no efficient access, almost no protection from data loss, no parallel access control.
ANSI SPARC architecture stores data in three levels:
view and logical levels are data representations in relations/tables
a row is a tuple record. the order of the elements of the tuples doesn't matter.
a database instance is a 'snapshot' of a database at a certain point in time.
the database schema is the structure of the database - the relations and constraints.
constraints:
customer(id, name, street, city)
)account(depository → customer, accountnr)
)create an entity relationship model in UML:
then translate that into relations
database management system (DBMS) allows:
multiple users, concurrent access. transactions have ACID properties:
DBMS have data independence and duplication avoidance.
SQL is declarative data manipulation language. The user says which conditions the retrieved data has to fulfill.
It's more concise than imperative languages, thus easier to maintain and cheaper to develop programs in it.
Users usually don't have to think about efficiency, the DBMS will manage that.
Creating a table with constraints:
CREATE TABLE solved (
id INT AUTO_INCREMENT,
name VARCHAR(40) NOT NULL,
homework NUMERIC(2) NOT NULL,
points NUMERIC(2) NOT NULL CHECK (points <= 10),
PRIMARY KEY (id)
);
Creating a view:
CREATE VIEW solved_homework AS
SELECT id, name, homework FROM solved;