Share via


Quickstart: Schema Explorer en designer gebruiken

In deze quickstart leert u hoe GitHub Copilot ontwikkelaars helpt bij het ontwerpen, begrijpen en ontwikkelen van databaseschema's met contextbewuste suggesties. Of u nu nieuwe tabellen vanaf nul bouwt of bestaande tabellen reverse-engineert, GitHub Copilot stroomlijnt het proces binnen SQL- en object-relationele toewijzingsframeworks (ORM), waardoor het werken met schema's sneller, slimmer en eenvoudiger te onderhouden is.

In deze sectie worden zowel het maken van nieuwe schema's als het werken met bestaande databases beschreven. U kunt GitHub Copilot gebruiken om code-first schemadefinities te genereren, objecten bij te werken of reverse-engineeren en bestaande databases te verkennen.

Schema maken

Basisschema maken

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 wijzigen

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`.

Schema maken met relaties en beperkingen

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.

Migratiescript maken om een kolom toe te voegen

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

Een bestaande database reverse-engineeren

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

Een tabelstructuur samenvatten

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

Een Python-model genereren

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

Entity Framework Core-context en modellen genereren

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

Modeldefinitie en -koppelingen maken

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

Een entiteit genereren op basis van een tabel

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

Een migratiescript genereren om een nieuwe tabel te maken

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

Relaties definiëren

Een relationeel script definiëren met vreemde sleutels

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)`.

Een tabel met vreemde-sleutelverwijzingen toevoegen aan een schema

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

Een database bijwerken om een tabel toe te voegen en kolommen bij te werken

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.

Vreemde-sleutelrelaties voor een tabel identificeren

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

Een vreemde sleutel vervangen door een veel-op-veel-relatie

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.

Toewijzing tussen twee tabellen genereren

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

Een gegevensmodel bijwerken

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

Schemavalidatie

Beperkingen voor gevoelige gegevens voorstellen

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

Beperkingen voor gegevenstypen valideren

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

Beperkingen voor primaire sleutels valideren

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

Controlerecords voor tabellen valideren

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

Een model definiëren en validatielogica opnemen

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

Gegevensaantekeningen toevoegen voor opmaakvalidatie

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

Uw ervaring delen

Om ons te helpen GitHub Copilot voor de MSSQL-extensie te verfijnen en te verbeteren, gebruikt u de volgende GitHub-probleemsjabloon om uw feedback te verzenden: GitHub Copilot-feedback

Overweeg het volgende bij het indienen van feedback:

  • Geteste scenario's : laat ons weten op welke gebieden u zich richt, bijvoorbeeld het maken van schema's, het genereren van query's, beveiliging, lokalisatie.

  • Wat goed werkte – Beschrijf ervaringen die soepel aanvoelden, behulpzaam waren of uw verwachtingen overtroffen.

  • Problemen of bugs : neem eventuele problemen, inconsistenties of verwarrend gedrag op. Screenshots of schermopnamen zijn vooral nuttig.

  • Suggesties voor verbetering : deel ideeën voor het verbeteren van bruikbaarheid, het uitbreiden van de dekking of het verbeteren van de reacties van GitHub Copilot.