0Pricing
Advanced PostgreSQL: Indexing, Partitioning, Replication · Lektion

Indizes erstellen und löschen

Lernen Sie die SQL-Befehle zum Erstellen, Überprüfen und Löschen von Indizes sowie Best Practices für deren Verwaltung kennen.

Indizes erstellen und löschen ist eine kostenlose Advanced PostgreSQL: Indexing, Partitioning, Replication-Lektion auf CoddyKit. Dies ist Lektion 3 von 4. Du kannst die komplette Lektion unten kostenlos lesen – dann übst du sie direkt im Browser mit einem integrierten Code-Editor und einem KI-Tutor rund um die Uhr. Sie ist Teil des Advanced PostgreSQL: Indexing, Partitioning, Replication-Lernpfads, und dein Fortschritt wird über Web und CoddyKit-App synchronisiert. Der Advanced PostgreSQL: Indexing, Partitioning, Replication-Kurs umfasst insgesamt 4 Lektionen.

Teile dieser Lektion wurden noch nicht übersetzt und werden auf Englisch angezeigt.

Index Management: The Basics

Time to get hands-on. This lesson covers the practical SQL to create, verify, and drop indexes — the everyday tools of index management.

Setting Up Our Table

First, let's build a small users table with a few rows to experiment on. Run the code to create and populate it.

CREATE TABLE users (
  id SERIAL PRIMARY KEY,
  name VARCHAR(100),
  email VARCHAR(100) UNIQUE,
  city VARCHAR(100)
);

INSERT INTO users (name, email, city) VALUES
  ('Alice Smith', 'alice@example.com', 'New York'),
  ('Bob Johnson', 'bob@example.com', 'Los Angeles'),
  ('Charlie Brown', 'charlie@example.com', 'New York'),
  ('Diana Prince', 'diana@example.com', 'London');

The CREATE INDEX Command

CREATE INDEX name ON table (column) builds an index to speed up queries. PostgreSQL makes it a B-tree by default — no USING BTREE needed.

Creating Your First Index

Let's index the city column so filtering by city gets much faster as the table grows. Run the command below.

CREATE INDEX idx_users_city ON users (city);

Verifying Existing Indexes

Did it work? PostgreSQL's pg_indexes system view lists every index in your database — query it to inspect what you just built.

Example: Listing Indexes

Query pg_indexes filtered to the users table to confirm your new index exists. Run it and check the output.

SELECT indexname, tablename, indexdef
FROM pg_indexes
WHERE tablename = 'users';

Composite Indexes

When queries filter on several columns, use a composite index spanning them. Column order matters — match your typical WHERE clause order.

Creating a Composite Index

Here we build a composite index on city and name — handy when you often search by both at once. Then re-run the pg_indexes query.

CREATE INDEX idx_users_city_name ON users (city, name);

The DROP INDEX Command

Drop an index when it's unused, slowing writes, or being replaced. The syntax is simple: DROP INDEX index_name.

Example: Dropping an Index

Let's remove the idx_users_city index by name with DROP INDEX, then verify it's gone with the pg_indexes query.

DROP INDEX idx_users_city;

Quick Check: Index Commands

Consider a table named products with columns product_id, category, and price.

Recap: Index Management

That's index management: CREATE INDEX to add, pg_indexes to verify, DROP INDEX to remove. Next up: more advanced index types.

Häufig gestellte Fragen

Ist die Lektion „Indizes erstellen und löschen“ kostenlos?

Ja — der vollständige Text von „Indizes erstellen und löschen“ ist hier im Web kostenlos zu lesen. Um sie interaktiv zu üben (integrierter Code-Editor und 24/7 KI-Tutor) und den Rest des Advanced PostgreSQL: Indexing, Partitioning, Replication-Kurses freizuschalten, upgrade auf CoddyKit PRO. Der Advanced PostgreSQL: Indexing, Partitioning, Replication-Kurs umfasst insgesamt 4 Lektionen.

Was lerne ich in „Indizes erstellen und löschen“?

Lernen Sie die SQL-Befehle zum Erstellen, Überprüfen und Löschen von Indizes sowie Best Practices für deren Verwaltung kennen. Du übst Advanced PostgreSQL: Indexing, Partitioning, Replication mit praktischem Code, den du direkt im Browser ausführst, und ein 24/7 KI-Tutor beantwortet deine Fragen während du die Lektion bearbeitest.

Brauche ich Erfahrung, um Advanced PostgreSQL: Indexing, Partitioning, Replication zu starten?

Keine Vorkenntnisse erforderlich. Advanced PostgreSQL: Indexing, Partitioning, Replication auf CoddyKit ist für Anfänger bis fortgeschrittene Lernende strukturiert, sodass du hier starten oder von Anfang an beginnen und in deinem eigenen Tempo voranschreiten kannst. Dies ist Lektion 3 von 4.

Wie lange dauert die Lektion „Indizes erstellen und löschen“?

Die meisten CoddyKit-Lektionen dauern etwa 5–10 Minuten. Jede ist kompakt und interaktiv, sodass du stetig Fortschritte machst und genau dort weitermachst, wo du aufgehört hast – im Web und in der App.

Kann ich in dieser Advanced PostgreSQL: Indexing, Partitioning, Replication-Lektion Code schreiben und ausführen?

Ja. Jede Advanced PostgreSQL: Indexing, Partitioning, Replication-Lektion enthält einen integrierten Code-Editor, sodass du echten Code direkt in deinem Browser schreibst und ausführst und sofort KI-Feedback erhältst — ohne lokale Einrichtung erforderlich.

Alle Lektionen in diesem Kurs

  1. Warum Indizes wichtig sind
  2. Grundlagen von B-Tree-Indizes
  3. Indizes erstellen und löschen
  4. Indizes für Unique- und Primärschlüssel
← Zurück zu Advanced PostgreSQL: Indexing, Partitioning, Replication