In previous blog posts in this series, we looked at connecting to a Microsoft SQL Server and getting familiar with the features in Rider to work with SQL databases. In this blog post, we will look at how to work with a database to create tables and indexes.
This post is part of a series around working with databases and data in Rider:
- Configuring SQL Server 2017 for Rider
- Getting started with database support in Rider
- Working with Tables and Indexes in Rider
- Working with Data in Rider
(Note: we’ll use the Visual Studio keymap on Windows throughout this post – check the web help for Mac OS X and other keyboard schemes)
Creating/Modifying a Table
To create or work with existing tables in your database, you will need to open the View | Tools Windows | Database menu selection to view the details of your database or use Ctrl+T or a double Shift and then type “database” to get the window.
Expand the tables view in the Database window and right click to create a new table.
The Create New Table dialog will be presented to work in the new table.
You can create the columns, keys (including primary), indices and foreign keys by using the tabs and commands on the right border. The Action of the dialog with either allows the table to be immediately created in the connected database or to return the SQL script for the created table back in the Database Console. To finally create the table, execute the SQL script in the console.
Working with an existing table is through right-clicking the table in the Database windows or use the Ctrl+F6 keyboard shortcut.
In the Modify Table dialog, to edit a column double-click the row.
After changing the table, you can either immediately update the table or save the script back to the Database Console just like when creating a new table.
Deleting a Table
Deleting or dropping a table from your database is performed by right-clicking the table and performing the Drop command or pressing the Delete key.
Working with Primary and Foreign Keys
The column that identifies your primary key in your table is set up through the Modify or Create New Table dialogs. Checking the Primary key checkbox and then executing will identify the column as the unique key for the table.
Working with foreign keys is also performed through the Modify or Create New dialogs. The list of foreign keys is on the Foreign Keys tab. Creating a new one through the Add command or Ctrl+N.
You are then able to create the name of foreign key, identify the target table, choose your update and delete rule types and finally, the keys to join in the target table from the table.
Working with Indexes
Working with Indexes or Indices of a table is performed in Indices tabs. Notice that there could be an index if you have created a primary key in the table. Create a new index using the Add command or Ctrl+N.
After creating a new index, you can update the name, the uniqueness and the column(s) with sorting on each column in the index.
Generating a Database Diagram
To view the Database Diagram while you are working with your database, perform the keyboard shortcut Ctrl+Alt+U.
Rider has a very rich and powerful set of data features that we have reviewed in this third part of the series. In our next post, we will look at how to use Rider to work with the data inside your tables, and other advanced topics.
Download Rider 2017.3 and give it a go! We’d love to hear your feedback!