Insert Data in SQL Server 2017

How to insert data into a SQL Server 2017 database using SQL Operations Studio (now called Azure Data Studio).

There are many ways to insert data into a database. The method you use will largely depend on the type of data, as well as the context with which it's being inserted. Let's start off by inserting data using a SQL script.

Insert Data by SQL Script

You can run a script that contains all data to be inserted. This is made possible with the SQL INSERT statement.

Run the following script against the Music database that we created earlier:

The above script inserts data into the Artists table. It inserts a new row for each artist.

Now run the following statement:

That statement returns the contents of the Artists table:

Screenshot of the results.

You'll see that the ArtistId column contains data even though we didn't actually add any data to that column. This is because ArtistId is an identity column (we used IDENTITY(1,1) in the table definition when we created the column). The identity column automatically inserts an incrementing value with each row, so we don't need to insert a value for that column — SQL Server does that for us. We also set this column to be the primary key when we created it, so each value is sure to be unique.

Now run the following script:

That script inserts data into the other two tables so that we'll have some data to work with later when we run some queries.

Direct Input

Some GUI tools allow you to enter data directly into the table via the interface. Like this:

  1. Open Table in Edit Mode

    Navigate to the table you want to enter data into.

    Right-click on the table and select Edit Data (or whatever your GUI tool calls it — SSMS calls it Edit Top 200 Rows).

    Screenshot of inserting data directly into a table via the SQLOPS GUI.
  2. Enter Data

    The table will open, allowing you to type data directly into the cells.

    Screenshot of inserting data directly into a table via the SQLOPS GUI.

Other Methods

Here are some other methods that can be used to populate a database with data. Whether or not you're able to do these will depend on your database management tools and/or environment.