Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
In this quickstart, you learn how GitHub Copilot assists developers in designing, understanding, and evolving database schemas with context-aware suggestions. Whether you're building from scratch or reverse-engineering existing tables, GitHub Copilot streamlines the process across SQL and ORM (Object-Relational Mapping) frameworks, making schema work faster, smarter, and easier to maintain.
This section covers both creating new schemas from scratch and working with existing databases. You can use GitHub Copilot to generate code-first schema definitions, update objects, or reverse-engineer and explore existing databases.
Schema creation
- Write a SQL script to create a new schema named
blog
for a blog application. The schema should include three tables:Posts
,Comments
, andUsers
. 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 typedatetime
to thePosts
table in theblog
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
.
- 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
- Generate a
Prisma
schema for a blog application using my current database. The schema should define a new database schema namedblog
and include tables forposts
,authors
, andcomments
, with appropriate relationships and constraints. - Generate a
Prisma
migration to add a column calledLastModified
(datetime
) to thePost
table. - Reverse engineer the current database and generate
CREATE TABLE
statements for all tables in theSalesLT
schema. - Summarize the structure of the
SalesLT.Product
table in natural language. - Generate a
models.py
(Django
) file that reflects the structure of theSalesLT.Customer
table. - Generate an
Entity Framework Core
DbContext and model classes for theSalesLT
schema. - Create a Sequelize model definition for the
SalesLT.Product
andSalesLT.Category
tables with appropriate associations. - Generate a
TypeORM
entity for theSalesLT.Customer
table, including primary key and indexed fields. - Generate a
knex.js
migration script to create theSalesLT.SalesOrderHeader
table withOrderDate
,CustomerID
, andTotalDue
columns.
Define relationships
- Write SQL to define a one-to-many relationship between
Users
andPosts
in theblog
schema. Ensure the foreign key inPosts
referencesUsers(UserId)
. - Add a
Categories
table to theblog
schema and update thePosts
table to include a nullable foreign key referencingCategories(CategoryId)
. - Write SQL to update the
Users
table to include aRoleId
column and create a newRoles
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
andCategories
in theblog
schema and replaces it with a many-to-many relationship using a new join table. - Write
Prisma
relation mappings betweenCustomer
,SalesOrderHeader
, andSalesOrderDetail
. - Update a Sequelize model to include a
hasMany
andbelongsTo
relationship betweenCustomer
andOrder
.
Schema validation
- Suggest constraints for a table storing user passwords (for example, special characters and length limits).
- Confirm that the
Name
column inSalesLT.ProductCategory
doesn't usenvarchar(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 aCreatedDate
orModifiedDate
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 anEntity Framework
model to ensure fields likeEmail
andPhoneNumber
follow specific formats.
Feedback: Schema Explorer & Designer
To help us refine and improve GitHub Copilot for the MSSQL extension, use the following GitHub issue template to submit your feedback: GitHub Copilot Feedback
When submitting feedback, consider including:
Scenarios tested – Let us know which areas you focused on, for example, schema creation, query generation, security, localization.
What worked well – Describe any experiences that felt smooth, helpful, or exceeded your expectations.
Issues or bugs – Include any problems, inconsistencies, or confusing behaviors. Screenshots or screen recordings are especially helpful.
Suggestions for improvement – Share ideas for improving usability, expanding coverage, or enhancing the GitHub Copilot's responses.
Related content
- GitHub Copilot for MSSQL extension for Visual Studio Code
- Quickstart: Use Chat and inline GitHub Copilot suggestions (Preview)
- Quickstart: Generate code (Preview)
- Quickstart: Use the Smart Query Builder (Preview)
- Quickstart: Query Optimizer Assistant (Preview)
- Quickstart: Use the Business Logic Explainer (Preview)
- Quickstart: Security Analyzer (Preview)
- Quickstart: Localization & Formatting Helper (Preview)
- Quickstart: Generate data for testing and mocking (Preview)
- Limitations and Known Issues