Create a SQL Server Database with SQLOPS

UPDATE: SQL Operations Studio (SQLOPS) has since been renamed to Azure Data Studio. The steps in this article remain the same though. In any case, I’ve also rewritten these steps (and included the equivalent screenshots) specifically for Azure Data Studio . See Create a SQL Server Database with Azure Data Studio.

Here, I explain how to use SQL Operations Studio (SQLOPS) to create a database in SQL Server.

In my case, I’m running SQL Server on a Mac (via a Docker container), but these instructions are generic and should work exactly the same way on Linux and Windows.

This tutorial assumes you already have SQLOPS installed on your machine, and you’ve connected to your SQL Server instance. If you don’t have SQLOPS installed on your machine, here are instructions for installing it on a Mac and connecting to SQL Server via Docker.  The SQLOPS installation is pretty straightforward (you install it just like any other software), so if you’re on Linux or Windows, you shouldn’t have any issues.

To create a database in SQLOPS, you simply open a new query editor and run a CREATE DATABASE query.

Open a New Query Editor

In SQLOPS, there are several ways to open a new query editor. They are:

  • Right-click on an object in the left pane, then click on the New Query option from the contextual menu (pictured below).
  • Click on the New Query button on the Server Dashboard
  • Use a keyboard shortcut (on Windows this is Ctrl+N. On Mac it’s Cmd+N)

Here’s a screenshot of the first option:

Create a database - the New Query contextual menu

Create the Database

So, now that you’ve opened a new query editor, you can go ahead and enter your CREATE DATABASE statement.

  1. Enter your query. You can either type it all out, or copy and paste it.  Another option is to open a previously saved query by going to the File > Open menu option. Here’s the script that I used for this example:
    /* Create database */
    CREATE DATABASE Music;
    GO
    
    /* Change to the Music database */
    USE Music;
    GO
    
    /* Create tables */
    CREATE TABLE Artists (
        ArtistId int IDENTITY(1,1) NOT NULL PRIMARY KEY,
        ArtistName nvarchar(255) NOT NULL,
        ActiveFrom DATE NULL
    );
    
    CREATE TABLE Genres (
        GenreId int IDENTITY(1,1) NOT NULL PRIMARY KEY,
        Genre nvarchar(50) NOT NULL
    );
    
    CREATE TABLE Albums
     (
      AlbumId int IDENTITY(1,1) NOT NULL PRIMARY KEY,
      AlbumName nvarchar(255) NOT NULL,
      ReleaseDate date NOT NULL,
      ArtistId int NOT NULL,
      GenreId int NOT NULL
      
      CONSTRAINT FK_Albums_Artists FOREIGN KEY (ArtistId)     
        REFERENCES dbo.Artists (ArtistId)     
        ON DELETE NO ACTION    
        ON UPDATE NO ACTION    
    );
    GO
    
  2. Click the Run button at the top of the query editor.

View the Database

Now that you’ve run your query, you should be able to see the database in the left pane. If you don’t see it, you probably need to refresh it.

  1. Right-click on Databases in the left pane
  2. Click Refresh from the contextual menu The Refresh option in the contextual menu

 

You should now see your database appear under Databases (when it’s expanded):

A newly created database