Partilhar via


Início rápido: Use o explorador de esquemas e o designer

Neste guia de início rápido, você aprenderá como o GitHub Copilot ajuda os desenvolvedores a projetar, entender e evoluir esquemas de banco de dados com sugestões sensíveis ao contexto. Quer esteja a construir do zero ou a fazer engenharia inversa de tabelas existentes, o GitHub Copilot simplifica o processo através de frameworks SQL e de mapeamento objeto-relacional (ORM), tornando o trabalho de esquema mais rápido, inteligente e fácil de manter.

Esta seção aborda a criação de novos esquemas do zero e o trabalho com bancos de dados existentes. Você pode usar o GitHub Copilot para gerar definições de esquema code-first, atualizar objetos ou fazer engenharia reversa e explorar bancos de dados existentes.

Criação de esquema

Criar esquema básico

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.

Modificar o esquema

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

Criar esquema com relações e restrições

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.

Criar script de migração para adicionar uma coluna

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

Engenharia inversa de uma base de dados existente

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

Resumir uma estrutura de tabela

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

Gerar um modelo Python

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

Gerar contexto e modelos do Entity Framework Core

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

Criar definição de modelos e associações

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

Gerar uma entidade a partir de uma tabela

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

Gerar um script de migração para criar uma nova tabela

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

Definir relações

Defina um script relacional com referências de chave estrangeira

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

Adicionar uma tabela a um esquema com referências de chave estrangeira

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

Atualizar uma base de dados para adicionar uma tabela e atualizar colunas

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.

Identificar relações de chave estrangeira para uma tabela

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

Substitua uma chave estrangeira por uma relação de muitos-para-muitos

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.

Gerar mapeamento entre duas tabelas

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

Atualizar um modelo de dados

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

Validação de esquemas

Sugira restrições para dados sensíveis

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

Validar restrições de tipos de dados

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

Validar restrições de chave primária

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

Validar registos de auditoria para tabelas

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

Defina um modelo e inclua lógica de validação

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

Adicionar anotações de dados para validação de formatos

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

Partilhar a sua experiência

Para nos ajudar a refinar e melhorar o Copilot do GitHub para a extensão MSSQL, use o seguinte modelo de problema do GitHub para enviar seus comentários: Feedback do Copiloto do GitHub

Ao enviar comentários, considere incluir:

  • Cenários testados – Diga-nos em quais áreas você se focou, por exemplo, criação de esquema, geração de consultas, segurança, localização.

  • O que funcionou bem – Descreva todas as experiências que foram suaves, úteis ou que excederam as suas expectativas.

  • Problemas ou bugs – Inclua quaisquer problemas, inconsistências ou comportamentos confusos. Capturas de tela ou gravações de tela são especialmente úteis.

  • Sugestões de melhoria – Compartilhe ideias para melhorar a usabilidade, expandir a cobertura ou melhorar as respostas do Copiloto do GitHub.