Connect to SQL Server from command prompt - list tables and database

Connect to SQL Server from command prompt - list tables and database

To connect to an SQL Server database from the command prompt and list the tables and database, you can use the sqlcmd utility.

sqlcmd is a command-line utility that allows you to execute SQL commands and queries against an SQL Server database. It is available with the SQL Server client tools or as a standalone download from the Microsoft website.

To use sqlcmd to connect to an SQL Server database and list the tables and database, follow these steps:

  1. Open the command prompt and navigate to the directory where the sqlcmd utility is installed. By default, this is C:\Program Files\Microsoft SQL Server\Client SDK\ODBC\110\Tools\Binn on a 64-bit system, or C:\Program Files (x86)\Microsoft SQL Server\Client SDK\ODBC\110\Tools\Binn on a 32-bit system.

  2. Type the following command to connect to the SQL Server database, replacing server_name, database_name, and username with the appropriate values for your system:

refer to‮tual:‬turi.com
sqlcmd -S server_name -d database_name -U username -P password

This will connect to the SQL Server database on server_name with the database_name database and the specified username and password.

  1. Once connected, you can use the SELECT statement to list the tables and database in the database. For example:
SELECT * FROM sys.tables

This will list all the tables in the database.

SELECT * FROM sys.databases

This will list all the databases on the server.

For more information about using sqlcmd and executing SQL commands and queries, you can refer to the sqlcmd documentation or search online for tutorials and examples.

Created Time:2017-10-28 14:02:23  Author:lautturi