
Connecting to SQL Server Express
When you connect to a SQL Server Express server, you must specify the server name and, if SQL Server Express is installed in a named instance, the instance name. By default, sqlcmd uses Windows Authentication. If you are connecting to the SQL Server Express server by using SQL Server Authentication, you must also provide the logon information for connecting to the SQL Server Express server. For example, if you are connecting to a default installation of SQL Server Express on a server named server1, you might use the following arguments:
sqlcmd -S server1\SQLExpress -U SqlUserAccount -P SqlPassword
Note: |
|---|
|
If you use the -P argument, your password appears in plain text at your command prompt. If you omit the -P argument, you will be prompted to enter your password. The text you enter will be hidden. |
If you are logged on with a user account that is trusted on the server that is running SQL Server Express, you can omit the -U and -P arguments:
sqlcmd -S server1\SQLExpress
Note: |
|---|
|
The -E argument specifies a trusted connection. This is the default setting for sqlcmd, and so the -E argument can be omitted. |
Example
The following example shows how to use the sqlcmd utility to connect to an instance of SQL Server Express, named SqlExpress, on a server named SqlServer1:
Sqlcmd -S SqlServer1\SqlExpress
After you are connected, you can issue other commands to manage the instance. For example, the following commands will display all currently installed databases. This is a convenient way to find the logical name of an attached SQL Server Express database:
SELECT name from sys.databases
Go