Create a new table space on cmd

To create a new tablespace on a Windows command prompt, you'll need to use the SQL Server Management Studio (SSMS) or the SQL Server Command Line Tool (sqlcmd). Here are the steps:

Method 1: Using SQL Server Management Studio (SSMS)

  1. Open SSMS and connect to your SQL Server instance.
  2. In the Object Explorer, right-click on the "Databases" folder and select "New" > "Tablespace".
  3. In the "Create Tablespace" dialog box, enter the following information:
    • Name: Enter a name for your new tablespace (e.g., "MyNewTablespace").
    • Description: Enter a brief description of your tablespace (optional).
    • Filegroup: Select the filegroup where you want to create the tablespace (e.g., "PRIMARY").
    • Path: Enter the path where you want to store the tablespace files (e.g., "C:\MyTablespaces").
  4. Click "OK" to create the tablespace.

Method 2: Using the SQL Server Command Line Tool (sqlcmd)

  1. Open a Command Prompt window and navigate to the directory where your SQL Server installation is located (e.g., "C:\Program Files\Microsoft SQL Server\150\Tools\Binn").
  2. Run the following command to create a new tablespace:
    sqlcmd -S <your_server_name> -Q "CREATE TABLESPACE MyNewTablespace ON 'C:\MyTablespaces' FILEGROUP 'PRIMARY'"

    Replace <your_server_name> with the name of your SQL Server instance.

Note: Make sure to replace the file path and filegroup name with the desired values for your tablespace.

After creating the tablespace, you can verify its existence by running the following command:

sqlcmd -S <your_server_name> -Q "SELECT name FROM sys.tablespaces"

This should list all the tablespaces on your SQL Server instance, including the new one you created.