Linux下用sqlcmd创建SQL Server数据库及新手疑问咨询
Hey there! Let's work through your SQL Server questions step by step—no jargon, just clear, actionable steps.
> 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.
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
GOand 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
GOto run the query—you’ll see your database name listed if creation was successful.
Let’s walk through the entire process from start to finish on Linux:
- First, make sure SQL Server is running. Check its status with:
If it’s not active, start it with:systemctl status mssql-serversudo systemctl start mssql-server - Launch sqlcmd and log in as the SA (system administrator) account:
Note: Your SA password needs to meet SQL Server’s complexity rules—at least 8 characters, mixing letters, numbers, and symbols.sqlcmd -S localhost -U SA -P "YourStrongSA_Password123" - 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
EXITorQUITto leave the sqlcmd tool.
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




