Compartilhar via


Início Rápido: Usar o gerenciador de esquemas e o designer

Neste início rápido, você aprenderá como o GitHub Copilot auxilia os desenvolvedores na criação, compreensão e evolução de esquemas de banco de dados com sugestões com reconhecimento de contexto. Se você estiver criando do zero ou criando tabelas existentes de engenharia reversa, o GitHub Copilot simplifica o processo entre estruturas de SQL e ORM (mapeamento relacional de objeto), fazendo com que o esquema funcione mais rápido, mais inteligente e mais 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 de primeiro código, 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 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 reversa de um banco 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 do Python

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

Gerar modelos e contexto do Entity Framework Core

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

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

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

Gerar uma entidade 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

Definir 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 um banco 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.

Substituir uma chave estrangeira por uma relação 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 esquema

Sugerir restrições para dados confidenciais

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

Validar restrições de tipo 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 registros de auditoria para tabelas

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

Definir um modelo e incluir a 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 formato

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

Compartilhar sua experiência

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

Ao enviar comentários, considere incluir:

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

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

  • Problemas ou bugs – inclua 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 aprimorar as respostas do GitHub Copilot.