次の方法で共有


クイック スタート: スキーマ エクスプローラーとデザイナーを使用する

このクイック スタートでは、GitHub Copilot がコンテキスト対応の提案を使用してデータベース スキーマの設計、理解、および進化を行う開発者を支援する方法について説明します。 GitHub Copilot は、ゼロから構築する場合でも、既存のテーブルをリバース エンジニアリングする場合でも、SQL およびオブジェクト リレーショナル マッピング (ORM) フレームワーク全体でプロセスを効率化し、スキーマの作業をより迅速かつスマートに、保守しやすくします。

このセクションでは、新しいスキーマを最初から作成する方法と、既存のデータベースを操作する方法の両方について説明します。 GitHub Copilot を使用して、コード優先のスキーマ定義の生成、オブジェクトの更新、または既存のデータベースのリバース エンジニアリングと探索を行うことができます。

スキーマの作成

基本的なスキーマを作成する

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.

スキーマの変更

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

リレーションシップと制約を使用してスキーマを作成する

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.

列を追加する移行スクリプトを作成する

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

既存のデータベースをリバース エンジニアリングする

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

テーブル構造を集計する

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

Python モデルを生成する

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

Entity Framework Core コンテキストとモデルを生成する

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

モデル定義と関連付けを作成する

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

テーブルからエンティティを生成する

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

新しいテーブルを作成するための移行スクリプトを生成する

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

リレーションシップを定義する

外部キー参照を使用してリレーショナル スクリプトを定義する

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

外部キー参照を使用してスキーマにテーブルを追加する

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

データベースを更新してテーブルを追加し、列を更新する

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.

テーブルの外部キー リレーションシップを識別する

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

外部キーを多対多のリレーションに置き換える

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.

2 つのテーブル間のマッピングを生成する

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

データ モデルを更新する

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

スキーマの検証

機密データの制約を提案する

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

データ型の制約を検証する

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

主キー制約を検証する

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

テーブルの監査レコードを検証する

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

モデルを定義し、検証ロジックを含める

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

形式検証用のデータ注釈を追加する

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

感想をお聞かせください

MSSQL 拡張機能の GitHub Copilot を改良および改善するために、次の GitHub 問題テンプレートを使用してフィードバックを送信します。 GitHub Copilot フィードバック

フィードバックを送信する場合は、次の内容を検討してください。

  • テスト済みのシナリオ – スキーマの作成、クエリの生成、セキュリティ、ローカライズなど、どの領域に重点を置いたかをお知らせください。

  • うまくいったこと - スムーズで役に立ち、期待を超えた経験について説明します。

  • 問題またはバグ – 問題、不整合、または混乱を招く動作を含めます。 スクリーンショットや画面の記録は特に役立ちます。

  • 改善の提案 – 使いやすさの向上、カバレッジの拡大、GitHub Copilot の応答の強化に関するアイデアを共有します。