Compartilhar via


Cenários para Copilot no SQL Server Management Studio

O Copilot no SSMS é uma ferramenta avançada de IA projetada para ajudar os usuários do SSMS (SQL Server Management Studio) a gerenciar e desenvolver bancos de dados SQL. Seja você um administrador de banco de dados, desenvolvedor de banco de dados, administrador de aplicativos, analista de negócios ou em algum lugar no meio, o Copilot no SSMS pode economizar tempo e ajudá-lo a se tornar mais eficiente em seu fluxo de trabalho.

Use o Copilot no SSMS para responder perguntas sobre bancos de dados no SQL Server, banco de dados SQL do Azure, Instância Gerenciada de SQL do Azure ou Banco de Dados SQL no Fabric. Você também pode solicitar assistência para escrever consultas Transact-SQL (T-SQL) usando linguagem natural (NL2SQL). O Copilot também pode ajudar com mensagens de erro, documentando, explicando e corrigindo consultas T-SQL.

Exploração de banco de dados e ambiente

Faça qualquer pergunta a Copilot, em qualquer ordem, no bate-papo sidecar. Por exemplo:

  • What version of SQL is this?
  • List the databases on this instance.
  • List server configuration settings that have been changed from the default in table format with the setting and current value
  • How do I find out who is connected to this database?
  • What is the compatibility mode for the database?
  • hat's the largest table in the database?
  • What columns store email addresses?
  • How many customers do we have and where are they located?
  • Have any SQL Agent jobs have failed in the last week and if so, which ones?

Experiência de várias voltas

Faça a Copilot uma série de perguntas, com cada pergunta subsequente relacionada ou em resposta a uma resposta anterior. Por exemplo:

  • What is the compatibility mode for this database?
  • What is the latest compatibility mode available for this version of SQL?
  • How do I change the compatibility mode?
  • How will this change affect query performance?
  • Give me step-by-step instructions for testing a change in compatibility mode for a query without changing the compatibility mode for the entire database.

Experiência de interações múltiplas com script

Ao fazer uma série de perguntas ao Copilot, você também pode pedir que ele crie consultas relacionadas ao tópico.

  • What is a database backup?
  • What is the difference between a full and log backup?
  • How do I create a database backup?
  • Does my database need a transaction log backup?
  • How do I create a transaction log backup?
  • Create the script to backup the database
  • How do I automate backups?
  • What should my backup schedule be if the RPO is 30 minutes?
  • Create the script to create SQL Agent jobs for the recommended backup schedule

Use Copilot para obter ajuda com Transact-SQL

O Copilot no SSMS tem contexto baseado na conexão do editor de consultas, mas atualmente não tem acesso direto ao editor de consultas. Especificamente, digitar em um editor em branco não invoca a assistência do Copilot. Além disso, atualmente, ele não pode ler diretamente do editor (caso você tenha algo destacado) nem copiar algo para lá.

Gravar Transact-SQL

O Copilot pode ajudar na gravação do T-SQL usando o prompt que você fornece (linguagem natural para T-SQL ou NLtoSQL) dentro do chat sidecar.

  • Write a query to return sales information for the last week
  • Write a query to find all the customers who placed orders in July 2024 that totaled more than $1000 and order based on total descending
  • Write the query to change the ReferenceID column in the Tickets table from an INT to a VARCHAR(25)
  • Give me the query to find how much space is being used in tempdb
  • Give me the query to find all open transactions

Obtenha ajuda para escrever consultas T-SQL como uma experiência interativa de múltiplas etapas.

Além de pedir ajuda ao Copilot para escrever uma consulta, você pode pedir ajuda com o desenvolvimento de consultas no chat, da mesma forma que você mesmo pode escrever a consulta.

  • How many customers spent over $100000 in 2023?
  • Give me the query you ran to find that information
  • Take the inner query and change it to select customer ID, customer name, and total spent and order it by total spent descending
  • I forgot I want to include the state where the company is located in the output, please update the query to add that

Aprovar consultas para que o Copilot execute

Por padrão, o Copilot é executado em um modo somente leitura. O Copilot executa apenas consultas que leem dados. No entanto, você pode alterar o modo para Leitura/Gravação com Aprovação usando o /rwa comando no chat.

  1. Altere o modo:

    /rwa

  2. Peça ao Copilot para atualizar estatísticas que estão desatualizadas:

    Update statistics that are out of date

  3. Forneça mais detalhes ao Copilot para que ele possa executar a análise correta:

    List the name of statistics that haven't been updated in over a week that have more than 10% data changed for all tables in the database

  4. Copilot lista as estatísticas e pergunta se você deseja atualizá-las. Se ele não perguntar, você pode pedir que atualize as estatísticas.

  5. O Copilot fornece o T-SQL para a atualização e oferece a opção de selecionar Executar ou Cancelar.

  6. Selecione Executar para ter estatísticas de atualização do Copilot.

Usar Copilot para desenvolvimento de banco de dados

O Copilot pode ajudá-lo a desenvolver rapidamente objetos em seu banco de dados no modo de leitura/gravação . Para habilitar o modo de leitura/gravação , use o /rw comando.

  1. Altere o modo:

    /rw

  2. Peça ao Copilot para criar um conjunto de tabelas para o banco de dados:

    We're designing a database for a fictional company called Contoso Wireless. They are similar to existing wireless companies in the sense that they sell cell phones, accessories, phone plans, chargers, headsets, and more. Can you suggest some tables that will support my application? This application will support browsing a website, creating orders, paying bills, tracking customer activity, tracking usage, etc. Please provide scripts to create all the tables you see fit and make sure each table has a clustered index for the primary key.

  3. Peça ao Copilot para criar índices:

    Are there any indexes you think I need based on the kinds of queries that we will run to find data?

  4. Peça ao Copilot para criar dados de exemplo:

    We need to generate data for each of the tables. Each table should have 100-1000 rows. The data needs to be realistic (we can't repeat names, products, etc.). Can you help generate scripts for that? It's ok if the scripts are long. Variability in the data is more important than having a short script. For the customers table, use a combination of 50 first names and 50 last names and also use 30 different city/state combinations.

Outros exemplos

Você pode fazer qualquer pergunta ao Copilot sobre SQL ou gravação de T-SQL. Sempre examine scripts antes da execução, pois a IA pode cometer erros.

  • List the 10 largest tables in the database based on row count in a bulleted list

  • What are the file sizes for this database, their file growth settings, and how much free space do they have?

  • What are the worst performing queries for the last hour?

  • What queries executed most frequently in the last two hours?

  • List all employes and their email address in comma delimited format

  • What are the top 5 products ordered the most in 2024?

  • Calculate the total number of orders for each company in 2023

  • Create a table named Offices in the Sales schema. It should have the columns officeID, office name, address, city, state, zip code, and office manager ID which is foreign key to the People table.