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
blogfor 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
LastModifiedof typedatetimeto thePoststable in theblogschema. 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
Prismaschema for a blog application using my current database. The schema should define a new database schema namedblogand include tables forposts,authors, andcomments, with appropriate relationships and constraints. - Generate a
Prismamigration to add a column calledLastModified(datetime) to thePosttable. - Reverse engineer the current database and generate
CREATE TABLEstatements for all tables in theSalesLTschema. - Summarize the structure of the
SalesLT.Producttable in natural language. - Generate a
models.py(Django) file that reflects the structure of theSalesLT.Customertable. - Generate an
Entity Framework CoreDbContext and model classes for theSalesLTschema. - Create a Sequelize model definition for the
SalesLT.ProductandSalesLT.Categorytables with appropriate associations. - Generate a
TypeORMentity for theSalesLT.Customertable, including primary key and indexed fields. - Generate a
knex.jsmigration script to create theSalesLT.SalesOrderHeadertable withOrderDate,CustomerID, andTotalDuecolumns.
Define relationships
- Write SQL to define a one-to-many relationship between
UsersandPostsin theblogschema. Ensure the foreign key inPostsreferencesUsers(UserId). - Add a
Categoriestable to theblogschema and update thePoststable to include a nullable foreign key referencingCategories(CategoryId). - Write SQL to update the
Userstable to include aRoleIdcolumn and create a newRolestable. 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.SalesOrderHeadertable. - Write a SQL script that removes a foreign key between
PostsandCategoriesin theblogschema and replaces it with a many-to-many relationship using a new join table. - Write
Prismarelation mappings betweenCustomer,SalesOrderHeader, andSalesOrderDetail. - Update a Sequelize model to include a
hasManyandbelongsTorelationship betweenCustomerandOrder.
Schema validation
- Suggest constraints for a table storing user passwords (for example, special characters and length limits).
- Confirm that the
Namecolumn inSalesLT.ProductCategorydoesn't usenvarchar(max)and has a reasonable maximum length constraint. - Check whether the
SalesLT.Addresstable has a primary key and all required fields defined. - Generate a SQL script to validate that all tables in the
SalesLTschema include aCreatedDateorModifiedDatecolumn. - Define a SQLAlchemy model for the
Customertable and include validation logic using Pydantic or custom Python validators before inserting into the database. - Add
Data Annotationsin anEntity Frameworkmodel to ensure fields likeEmailandPhoneNumberfollow 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