Database
DB – DataBase
AB – Andme Baas(id)
DB – Databases
DBMS – Database Management Systems
Main tasks of the database
- Ensuring that all necessary information is stored in the database
- Ensuring the ability to obtain data for all necessary requests.
- Reduce data redundancy and duplication
- Ensuring data integrity: eliminating inconsistencies in data content.
Data types
- Numeric –
int, smallint, tinyint, decimal(4,1) – 1 decimal place, 4 – in total - Text or symbol –
varchar(10) where 10 is the max. number of characters
char(11) – only 11 characters
TEXT - Logic –
boolean, bool, bit, true/false - Temporary –
date
time
datetime
interval – to store a time interval
Row = Record
Columns = Fields
Table = Entity/Ole
SQL – Structured Query Language
Query – Request – Päring
DDL – Data Definition Language – creating and defining tables
CREATE TABLE, DROP TABLE, ALTER TABLE
DML – Data Manipulation Language – adding, deleting and editing a database
INSERT, UPDATE, SELECT
creates tables
123456 | CREATE TABLE opilane( opilaneID int PRIMARY KEY AUTO_INCREMENT, eesnimi varchar (20) not null , perenimi varchar (30) not null , isikukood char (11), synniaeg date ) |
adds data to the table
1 | INSERT INTO `opilane` (`opilaneID`, `eesnimi`, `perenimi`, `isikukood`, `synniaeg`) VALUES ( NULL , 'Yarik' , 'Yekasov' , '50511190683' , '2005-11-19' ); |
adds a column with place of birth
1 | ALTER TABLE opilane ADD COLUMN synnikoht varchar (20) |
updates place of birth by ID
12 | UPDATE opilane SET synnikoht= 'Tallinn' WHERE opilaneID=1; SELECT * FROM opilane; |
Primary KEY – PK – attribute / or a set of them that uniquely defines a row; there are no two identical primary key values. AUTO_INCREMENT – automatic filling of the key field with increasing values 1,2,…
Foreign KEY – FK – Secondary key – relationship between tables. The secondary key contains a reference to the PK of another table
123456 | CREATE TABLE hindamine( hindamineID int primary key AUTO_INCREMENT, opilaneID int , foreign key (opilaneID) references opilane(opilaneID), oppaine varchar (12), hinne int ) |

1 | ALTER TABLE opilane ADD ryhmID int |
1 | UPDATEopilane SETryhmID= |
1 | ALTER TABLE opilane ADD CONSTRAINT fk_ryhm2 FOREIGN KEY (ryhmID) REFERENCES ryhm(ryhmID) |












Test2

