2. Normal Form

PostgreSQL Veritabanları Oluşturma

Darryl Reeves

Industry Assistant Professor, New York University

Örnek: okul ders kitapları

CREATE TABLE textbook (
    id SERIAL PRIMARY KEY,
    name VARCHAR(100) NOT NULL,
    publisher_name VARCHAR(100) NOT NULL,
    publisher_site VARCHAR(50),
    quantity SMALLINT NOT NULL DEFAULT 0
);
PostgreSQL Veritabanları Oluşturma

Örnek: okul ders kitapları

id title publisher_name publisher_site quantity
23 Introductory Algebra: 1st Edition ABC Publishing www.abc.com 32
74 Calculus Foundations ABC Publishing www.abc.com 27
112 Statistical Concepts Martin House www.mh.com 22
PostgreSQL Veritabanları Oluşturma

Örnek: URL güncellemesinden kaynaklanan tutarsızlık

id title publisher_name publisher_site quantity
23 Introductory Algebra: 1st Edition ABC Publishing www.abc.com 32
74 Calculus Foundations ABC Publishing www.abc.com 27
112 Statistical Concepts Martin House www.mh.com 22
PostgreSQL Veritabanları Oluşturma

Örnek: URL güncellemesinden kaynaklanan tutarsızlık

id title publisher_name publisher_site quantity
23 Introductory Algebra: 1st Edition ABC Publishing www.newabc.com 32
74 Calculus Foundations ABC Publishing www.abc.com 27
112 Statistical Concepts Martin House www.mh.com 22
PostgreSQL Veritabanları Oluşturma

Örnek: ders kitabı olmadan yayınevi ekleme

id title publisher_name publisher_site quantity
23 Introductory Algebra: 1st Edition ABC Publishing www.abc.com 32
74 Calculus Foundations ABC Publishing www.abc.com 27
112 Statistical Concepts Martin House www.mh.com 22
PostgreSQL Veritabanları Oluşturma

Örnek: ders kitabı olmadan yayınevi ekleme

id title publisher_name publisher_site quantity
23 Introductory Algebra: 1st Edition ABC Publishing www.abc.com 32
74 Calculus Foundations ABC Publishing www.abc.com 27
112 Statistical Concepts Martin House www.mh.com 22
?? ?? New Horizons www.nhorizon.com ??
PostgreSQL Veritabanları Oluşturma

Örnek: bir ders kitabını kaldırma

id title publisher_name publisher_site quantity
23 Introductory Algebra: 1st Edition ABC Publishing www.abc.com 32
74 Calculus Foundations ABC Publishing www.abc.com 27
112 Statistical Concepts Martin House www.mh.com 22
PostgreSQL Veritabanları Oluşturma

Örnek: bir ders kitabını kaldırma

id title publisher_name publisher_site quantity
23 Introductory Algebra: 1st Edition ABC Publishing www.abc.com 32
74 Calculus Foundations ABC Publishing www.abc.com 27
  • Yayınevi ayrı bir tablo gerektirir
  • Ekleme ve silmelerden veri anormallikleri oluşur
PostgreSQL Veritabanları Oluşturma

2. Normal Formu (2NF) sağlamak

  • 1NF sağlanır
  • Anahtar olmayan tüm sütunlar tablonun PRIMARY KEY alanına bağlıdır
PostgreSQL Veritabanları Oluşturma

Örnek: 2NF’de ders kitapları ve yayınevleri

CREATE TABLE textbook (
    id SERIAL PRIMARY KEY,
    name VARCHAR(100) NOT NULL,
    publisher_name VARCHAR(100) NOT NULL,
    publisher_site VARCHAR(50),
    quantity SMALLINT NOT NULL DEFAULT 0
);
PostgreSQL Veritabanları Oluşturma

Örnek: 2NF’de ders kitapları ve yayınevleri

CREATE TABLE textbook (
    id SERIAL PRIMARY KEY,
    name VARCHAR(100) NOT NULL,
    quantity SMALLINT NOT NULL DEFAULT 0,
);
CREATE TABLE publisher (
    id SERIAL PRIMARY KEY,
    name VARCHAR(100) NOT NULL,
    site VARCHAR(50)
);
PostgreSQL Veritabanları Oluşturma

Örnek: 2NF’de ders kitapları ve yayınevleri

CREATE TABLE textbook (
    id SERIAL PRIMARY KEY,
    name VARCHAR(100) NOT NULL,
    quantity SMALLINT NOT NULL DEFAULT 0,
    publisher_id INTEGER REFERENCES publisher(id)
);
CREATE TABLE publisher (
    id SERIAL PRIMARY KEY,
    name VARCHAR(100) NOT NULL,
    site VARCHAR(50)
);
PostgreSQL Veritabanları Oluşturma

Hadi pratik yapalım!

PostgreSQL Veritabanları Oluşturma

Preparing Video For Download...