You need to enable JavaScript to run this app.
最新活动
大模型
产品
解决方案
定价
生态与合作
支持与服务
开发者
了解我们

Linux下用sqlcmd创建SQL Server数据库及新手疑问咨询

Hey there! Let's work through your SQL Server questions step by step—no jargon, just clear, actionable steps.

1. What's that > symbol you're seeing?

That > is the sqlcmd interactive prompt! It means you've successfully logged into the SQL Server command-line tool and it’s waiting for you to enter SQL commands or sqlcmd-specific commands.

If you ever see 2> instead, that’s a continuation prompt—it signals your previous line of SQL wasn’t finished (like starting a CREATE statement but not closing it), so sqlcmd is waiting for you to complete the command.

2. Basic Steps to Create a Database (Works Across Windows/Linux)

Once you’re at that > prompt, creating a database is straightforward:

  • Type the SQL command to define your database (replace the name with your preferred one):
    CREATE DATABASE YourNewDatabaseName;
    
  • Next, type GO and hit enter—this tells sqlcmd to execute the batch of commands you just wrote.
  • To confirm it worked, run this check query:
    SELECT name FROM sys.databases WHERE name = 'YourNewDatabaseName';
    
  • Again, type GO to run the query—you’ll see your database name listed if creation was successful.
3. Full Workflow for Creating a Database on Linux with sqlcmd

Let’s walk through the entire process from start to finish on Linux:

  • First, make sure SQL Server is running. Check its status with:
    systemctl status mssql-server
    
    If it’s not active, start it with:
    sudo systemctl start mssql-server
    
  • Launch sqlcmd and log in as the SA (system administrator) account:
    sqlcmd -S localhost -U SA -P "YourStrongSA_Password123"
    
    Note: Your SA password needs to meet SQL Server’s complexity rules—at least 8 characters, mixing letters, numbers, and symbols.
  • Once you see the > prompt, run the create database command:
    CREATE DATABASE MyLinuxDB;
    GO
    
  • Verify the database exists and check its creation date:
    SELECT name, create_date FROM sys.databases WHERE name = 'MyLinuxDB';
    GO
    
  • When you’re done, type EXIT or QUIT to leave the sqlcmd tool.
Quick Troubleshooting Tip

If you type a command at the > prompt and nothing happens, you probably forgot to type GO at the end. sqlcmd uses GO as the signal to execute your input—without it, it just waits for more commands!

内容的提问来源于stack exchange,提问作者sanlegas

火山引擎 最新活动