Bemærk
Adgang til denne side kræver godkendelse. Du kan prøve at logge på eller ændre mapper.
Adgang til denne side kræver godkendelse. Du kan prøve at ændre mapper.
The Schema Designer in the MSSQL extension for Visual Studio Code provides a graphical environment for visualizing, designing, and managing database schemas without writing Transact-SQL (T-SQL) statements.
Features
Schema designer offers these features:
- Visualize database structure with interactive diagrams.
- Create or edit tables, foreign keys, primary keys, and constraints.
- Search, drag and drop, filter, zoom, use a mini-map, and autoarrange diagrams for efficient navigation and customization.
- Export schema diagrams for documentation or sharing.
- Automatically generate and view read-only T-SQL scripts representing your schema changes.
- Review and apply changes to the database with the Publish Changes feature.
Open schema designer
Right-click on the database in the object explorer and select Design Schema from the menu. This action opens the schema designer view, which then allows you to see the visual database diagram.
Once inside the schema designer, you find a canvas with various navigation capabilities. Here's how to get around:
Pan and zoom: Select and drag anywhere on the canvas to pan across the diagram. Use your mouse scroll wheel or trackpad gestures to zoom in and out for a closer or broader view.
Mini-map: Use the built-in mini-map (located in the bottom right corner of the designer) for quick navigation across large or complex schemas.
Drag and drop: Rearrange tables and relationships by dragging elements on the canvas. This option helps you create a layout that makes sense to you or your team.
Search and filter: Use the search box (Ctrl+F or Cmd+F) to locate specific tables or columns. Apply filters to focus on certain parts of the schema or hide irrelevant elements.
Auto-arrange: The diagram is automatically arranged in a readable layout by default. If you manually reposition tables and want to reset the view, select the Autoarrange button to reorganize the tables.
Understand table structure and relationships
When you enter the schema designer view, you see the visualization of your database tables. Each table displays its schema and table name, columns, data types, and primary keys shown as a key icon.
Foreign key relationships are shown with connecting arrows between columns. For example, in the previous diagram, the AddressID column in the CustomerAddress table references the AddressID column in the Address table, visually representing the relationship between them.
Add or edit tables
Select Add Table in the top toolbar to add a new table. Select the pencil icon on a table in the diagram to edit that table.
This action opens the Table tab in the Table Editor in a side panel. You can:
- Select or change the schema
- Define the table name
- Add new columns with name, data type, default value, and constraints
- Mark one or more columns as primary keys
- Delete or update existing columns as needed
Select Save to apply your changes. The diagram updates to reflect your changes. For more advanced table editing capabilities, such as creating indexes or setting up constraint rules, use the Table designer in the MSSQL extension for Visual Studio Code.
Add or edit foreign key relationships
To manage foreign key relationships, select the ellipsis (...) on a table in the diagram and select Manage Relationships.
This option opens the Foreign Keys tab in the Table Editor side panel, where you can:
- Add new foreign key relationships by referencing primary keys in other tables
- Define the foreign key name
- Edit existing foreign keys to update or correct relationships
Changes automatically appear in the visual diagram, with arrows showing the direction of each relationship.
Alternatively, you can create a relationship by dragging an arrow from one column to another directly in the diagram. This method defines a one-to-one relationship between the selected columns.
View schema definition in script pane
From the ribbon toolbar, select the View Code button to open the bottom pane. This pane shows the read-only T-SQL script that displays actions performed on the schema designer in real time.
Review and publish your changes
When you finish editing tables or relationships, select Publish Changes in the top toolbar. This action generates a change summary report that lists all pending modifications to your schema.
Review the report carefully. Check the confirmation box to acknowledge and accept any potential risks associated with applying the changes. This process uses DacFX (Data-tier Application Framework) to deploy your schema updates.
GitHub Copilot integration
The Schema Designer supports GitHub Copilot for AI-assisted schema design. You can use natural language to create schemas, modify existing schemas, review changes through a diff view, and import external artifacts. Changes are reflected in the visual diagram and T-SQL script.
For detailed instructions on using GitHub Copilot within the Schema Designer, see GitHub Copilot integration in Schema Designer (preview).
Feedback and support
If you have ideas, feedback, or want to engage with the community, join the discussion at https://aka.ms/vscode-mssql-discussions. To report a bug, visit https://aka.ms/vscode-mssql-bug. To request a new feature, go to https://aka.ms/vscode-mssql-feature-request.
Related content
- Quickstart: Connect to and query a database with the MSSQL extension for Visual Studio Code
- GitHub Copilot integration in Schema Designer (preview)
- GitHub Copilot for MSSQL extension for Visual Studio Code
- Schema Compare
- Data-tier Application (DACPAC and BACPAC) import and export
- Visual Studio Code documentation
- MSSQL extension for Visual Studio Code repository on GitHub