Freigeben über


Schnellstart: Verwenden des Schema-Explorers und des Designers

In dieser Schnellstartanleitung erfahren Sie, wie GitHub Copilot Entwickler beim Entwerfen, Verstehen und Entwickeln von Datenbankschemas mit kontextfähigen Vorschlägen unterstützt. Ganz gleich, ob Sie vorhandene Tabellen von Grund auf neu erstellen oder reverse-engineering, GitHub Copilot optimiert den Prozess über SQL- und objektrelationale Zuordnungsframeworks (ORM), wodurch die Schemaarbeit schneller, intelligenter und einfacher zu verwalten ist.

In diesem Abschnitt werden sowohl das Erstellen neuer Schemas von Grund auf neu behandelt als auch das Arbeiten mit vorhandenen Datenbanken. Sie können GitHub Copilot verwenden, um Code-first-Schemadefinitionen zu generieren, Objekte zu aktualisieren oder Reverse Engineering zu erstellen und vorhandene Datenbanken zu erkunden.

Schemaerstellung

Erstellen eines einfachen Schemas

Write a SQL script to create a new schema named `blog` for a blog application. The schema should include three tables: `Posts`, `Comments`, and `Users`. Each table must have appropriate primary keys, and the necessary foreign key relationships and constraints should be defined.

Schema ändern

Add a new column named `LastModified` of type `datetime` to the `Posts` table in the `blog` schema. Generate the updated SQL script reflecting this change, including the full definition of the modified schema.

It isn't needed to create the schema, but it would be great if you could use the script generated and run it to validate the accuracy of the generated code. The following section continues using this new schema called `blog`.

Erstellen eines Schemas mit Beziehungen und Einschränkungen

Generate a Prisma schema for a blog application using my current database. The schema should define a new database schema named `blog` and include tables for `posts`, `authors`, and `comments`, with appropriate relationships and constraints.

Erstellen eines Migrationsskripts zum Hinzufügen einer Spalte

Generate a Prisma migration to add a column called `LastModified` (`datetime`) to the `Post` table.

Reverse Engineering einer vorhandenen Datenbank

Reverse engineer the current database and generate `CREATE TABLE` statements for all tables in the `SalesLT` schema.

Zusammenfassen einer Tabellenstruktur

Summarize the structure of the `SalesLT.Product` table in natural language.

Generieren eines Python-Modells

Generate a `models.py` (Django) file that reflects the structure of the `SalesLT.Customer` table.

Generieren von Entity Framework Core-Kontext und -Modellen

Generate an Entity Framework Core DbContext and model classes for the `SalesLT` schema.

Erstellen von Modelldefinitionen und Zuordnungen

Create a Sequelize model definition for the `SalesLT.Product` and `SalesLT.Category` tables with appropriate associations.

Generieren einer Entität aus einer Tabelle

Generate a TypeORM entity for the `SalesLT.Customer` table, including primary key and indexed fields.

Generieren eines Migrationsskripts zum Erstellen einer neuen Tabelle

Generate a `knex.js` migration script to create the `SalesLT.SalesOrderHeader` table with `OrderDate`, `CustomerID`, and `TotalDue` columns.

Definieren von Beziehungen

Definieren eines relationalen Skripts mit Fremdschlüsselbezügen

Write SQL to define a one-to-many relationship between `Users` and `Posts` in the `blog` schema. Ensure the foreign key in `Posts` references `Users(UserId)`.

Hinzufügen einer Tabelle zu einem Schema mit Fremdschlüsselbezügen

Add a `Categories` table to the `blog` schema and update the `Posts` table to include a nullable foreign key referencing `Categories(CategoryId)`.

Aktualisieren einer Datenbank zum Hinzufügen einer Tabelle und Aktualisieren von Spalten

Write SQL to update the `Users` table to include a `RoleId` column and create a new `Roles` table. Define a foreign key relationship and enforce that every user must have a role.

Identifizieren von Fremdschlüsselbeziehungen für eine Tabelle

Identify and describe all foreign key relationships that involve the `SalesLT.SalesOrderHeader` table.

Ersetzen eines Fremdschlüssels durch eine Viele-zu-Viele-Beziehung

Write a SQL script that removes a foreign key between `Posts` and `Categories` in the `blog` schema and replaces it with a many-to-many relationship using a new join table.

Erstellen einer Zuordnung zwischen zwei Tabellen

Write Prisma relation mappings between `Customer`, `SalesOrderHeader`, and `SalesOrderDetail`.

Aktualisieren eines Datenmodells

Update a Sequelize model to include a `hasMany` and `belongsTo` relationship between `Customer` and `Order`.

Schemavalidierung

Vorschlagen von Einschränkungen für vertrauliche Daten

Suggest constraints for a table storing user passwords (for example, special characters and length limits).

Überprüfen von Datentypeinschränkungen

Confirm that the `Name` column in `SalesLT.ProductCategory` doesn't use `nvarchar(max)` and has a reasonable maximum length constraint.

Überprüfen von Primärschlüsseleinschränkungen

Check whether the `SalesLT.Address` table has a primary key and all required fields defined.

Überprüfen von Überwachungsdatensätzen für Tabellen

Generate a SQL script to validate that all tables in the `SalesLT` schema include a `CreatedDate` or `ModifiedDate` column.

Definieren eines Modells und Einschließen der Validierungslogik

Define a SQLAlchemy model for the `Customer` table and include validation logic using Pydantic or custom Python validators before inserting into the database.

Hinzufügen von Datenanmerkungen zur Formatüberprüfung

Add data annotations in an Entity Framework model to ensure fields like `Email` and `PhoneNumber` follow specific formats.

Teilen von Erfahrungen

Um uns dabei zu helfen, GitHub Copilot für die MSSQL-Erweiterung zu verfeinern und zu verbessern, verwenden Sie die folgende GitHub-Problemvorlage, um Ihr Feedback zu übermitteln: GitHub Copilot Feedback

Berücksichtigen Sie bei der Übermittlung von Feedback Folgendes:

  • Getestete Szenarien – Teilen Sie uns mit, auf welche Bereiche Sie sich konzentrieren, z. B. Schemaerstellung, Abfragegenerierung, Sicherheit, Lokalisierung.

  • Was gut funktioniert hat – Beschreiben Sie alle Erfahrungen, die sich reibungslos, hilfreich fühlen oder Ihre Erwartungen überschritten haben.

  • Probleme oder Fehler – Schließen Sie alle Probleme, Inkonsistenzen oder verwirrende Verhaltensweisen ein. Screenshots oder Bildschirmaufzeichnungen sind besonders hilfreich.

  • Verbesserungsvorschläge – Teilen Sie Ideen zur Verbesserung der Benutzerfreundlichkeit, zur Erweiterung der Abdeckung oder zur Verbesserung der Antworten von GitHub Copilot.