Sdílet prostřednictvím


Rychlý start: Použití Průzkumníka schémat a návrháře

V tomto rychlém startu se dozvíte, jak GitHub Copilot pomáhá vývojářům navrhovat, rozumět a vyvíjet schémata databáze pomocí návrhů s podporou kontextu. Ať už stavíte od nuly nebo reverzně konstruujete existující tabulky, GitHub Copilot zjednodušuje proces napříč SQL a ORM frameworky, což činí práci se schématy rychlejší, chytřejší a snadněji udržovatelnou.

Tato část popisuje vytváření nových schémat od začátku i práci s existujícími databázemi. Pomocí GitHub Copilotu můžete vygenerovat definice schémat na základě kódu, aktualizovat objekty nebo provést zpětnou analýzu a prozkoumat existující databáze.

Vytvoření schématu

Vytvoření základního schématu

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.

Úprava schématu

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

Vytvoření schématu s relacemi a omezeními

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.

Vytvoření skriptu migrace pro přidání sloupce

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

Zpětná analýza existující databáze

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

Shrnutí struktury tabulky

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

Generování modelu Pythonu

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

Generování kontextu a modelů Entity Framework Core

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

Vytvořte definici modelu a asociace

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

Generování entity z tabulky

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

Vygenerování skriptu migrace pro vytvoření nové tabulky

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

Definování relací

Definování relačního skriptu s odkazy na cizí klíč

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

Přidání tabulky do schématu s odkazy na cizí klíč

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

Aktualizace databáze pro přidání tabulky a aktualizace sloupců

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.

Identifikace relací cizího klíče pro tabulku

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

Nahraďte cizí klíč relací mnoho k mnoha

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.

Vytvoření mapování mezi dvěma tabulkami

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

Aktualizace datového modelu

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

Ověřování schématu

Navrhnout omezení pro citlivá data

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

Ověření omezení datového typu

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

Ověřte omezení primárního klíče

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

Ověření záznamů auditu tabulek

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

Definování modelu a zahrnutí logiky ověření

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

Přidání datových poznámek pro ověření formátu

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

Podělte se o své zkušenosti

Pokud nám chcete pomoct upřesnit a vylepšit GitHub Copilot pro rozšíření MSSQL, odešlete zpětnou vazbu pomocí následující šablony problému Na GitHubu: Váš názor na GitHub Copilot

Při odesílání zpětné vazby zvažte následující:

  • Otestované scénáře – Dejte nám vědět, na které oblasti jste se zaměřili, například na vytváření schématu, generování dotazů, zabezpečení, lokalizaci.

  • Co dobře fungovalo – popište všechny zážitky, které se cítily hladce, užitečné nebo překročily vaše očekávání.

  • Problémy nebo chyby – Zahrňte všechny problémy, nekonzistence nebo matoucí chování. Snímky obrazovky nebo nahrávky obrazovky jsou užitečné hlavně.

  • Návrhy ke zlepšení – Sdílejte nápady na zlepšení použitelnosti, rozšíření pokrytí nebo vylepšení odpovědí GitHub Copilotu.