Prima Formă Normală

Crearea bazelor de date PostgreSQL

Darryl Reeves

Industry Assistant Professor, New York University

Exemplu: gestionarea înregistrărilor studenților

CREATE TABLE student (
    id SERIAL PRIMARY KEY,
    name VARCHAR(50) NOT NULL,
    courses VARCHAR(50) NOT NULL,
    home_room SMALLINT NOT NULL
);
  • Erori de actualizare
  • Erori de inserție
  • Erori de ștergere
Crearea bazelor de date PostgreSQL

Exemplu: date duplicate după actualizare

id name courses home_room
122 Susan Roth Algebra I, Physics, Spanish II 101
413 Robert Cruz History, Geometry, Biology 204
613 Thomas Wright English III, Chemistry, Algebra II 102
Crearea bazelor de date PostgreSQL

Exemplu: date duplicate după actualizare

id name courses home_room
122 Susan Roth Algebra I, Chemistry, Spanish II 101
413 Robert Cruz History, Geometry, Biology 204
613 Thomas Wright English III, Chemistry, Algebra II 102
Crearea bazelor de date PostgreSQL

Exemplu: date duplicate după actualizare

id name courses home_room
122 Susan Roth Algebra I, Chemistry, Spanish II, Chemistry 101
413 Robert Cruz History, Geometry, Biology 204
613 Thomas Wright English III, Chemistry, Algebra II 102
Crearea bazelor de date PostgreSQL

Exemplu: inserții cu restricții de coloană

CREATE TABLE student (
    id SERIAL PRIMARY KEY,
    name VARCHAR(50) NOT NULL,
    courses VARCHAR(50) NOT NULL,
    home_room SMALLINT NOT NULL
);
id name courses home_room
122 Susan Roth Algebra I, Physics, Spanish II 101
413 Robert Cruz History, Geometry, Biology 204
613 Thomas Wright English III, Chemistry, Algebra II 102
Crearea bazelor de date PostgreSQL

Exemplu: inserții cu restricții de coloană

CREATE TABLE student (
    id SERIAL PRIMARY KEY,
    name VARCHAR(50) NOT NULL,
    courses VARCHAR(50) NOT NULL,
    home_room SMALLINT NOT NULL
);
id name courses home_room
122 Susan Roth Algebra I, Physics, Spanish II 101
413 Robert Cruz History, Geometry, Biology, French Literature 204
613 Thomas Wright English III, Chemistry, Algebra II 102
Crearea bazelor de date PostgreSQL

Exemplu: integritatea datelor afectată de ștergerea înregistrărilor

id name courses home_room
122 Susan Roth Algebra I, Physics, Spanish II 101
413 Robert Cruz History, Geometry, Biology 204
613 Thomas Wright English III, Chemistry, Algebra II 102
Crearea bazelor de date PostgreSQL

Exemplu: integritatea datelor afectată de ștergerea înregistrărilor

id name courses home_room
122 Susan Roth Algebra I, Physics, Spanish II 101
413 Robert Cruz History, Geometry, Biology 204
613 Thomas Wright ??? 102
Crearea bazelor de date PostgreSQL

Satisfacerea Primei Forme Normale (1NF)

  • Cerință 1NF:
    • Valorile din tabel trebuie să fie atomice
Crearea bazelor de date PostgreSQL

Exemplu: tabelul student satisface 1NF

CREATE TABLE student (
    id SERIAL PRIMARY KEY,
    name VARCHAR(50) NOT NULL,
    courses VARCHAR(50) NOT NULL,
    home_room SMALLINT NOT NULL
);
Crearea bazelor de date PostgreSQL

Exemplu: tabelul student satisface 1NF

CREATE TABLE student (
    id INTEGER,
    name VARCHAR(50) NOT NULL,
    courses VARCHAR(50) NOT NULL,
    home_room SMALLINT NOT NULL
);
Crearea bazelor de date PostgreSQL

Exemplu: tabelul student satisface 1NF

CREATE TABLE student (
    id INTEGER,
    name VARCHAR(50) NOT NULL,
    course VARCHAR(50) NOT NULL,
    home_room SMALLINT NOT NULL
);
Crearea bazelor de date PostgreSQL

Exemplu: tabelul student satisface 1NF

id name course home_room
122 Susan Roth Algebra I 101
122 Susan Roth Physics 101
122 Susan Roth Spanish II 101
413 Robert Cruz History 204
413 Robert Cruz Geometry 204
413 Robert Cruz Biology 204
Crearea bazelor de date PostgreSQL

Exemplu: tabelul student satisface 1NF

CREATE TABLE student (
    id INTEGER,
    name VARCHAR(50) NOT NULL,
    course VARCHAR(50) NOT NULL,
    home_room SMALLINT NOT NULL
);
Crearea bazelor de date PostgreSQL

Exemplu: tabelul student satisface 1NF

CREATE TABLE student (
    student_id INTEGER,
    first_name VARCHAR(50) NOT NULL,
    last_name VARCHAR(50) NOT NULL,
    course VARCHAR(50) NOT NULL,
    home_room SMALLINT NOT NULL
);
Crearea bazelor de date PostgreSQL

Exemplu: tabelul student satisface 1NF

id first_name last_name course home_room
122 Susan Roth Algebra I 101
122 Susan Roth Physics 101
122 Susan Roth Spanish II 101
413 Robert Cruz History 204
413 Robert Cruz Geometry 204
413 Robert Cruz Biology 204
Crearea bazelor de date PostgreSQL

Să exersăm!

Crearea bazelor de date PostgreSQL

Preparing Video For Download...