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:
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.
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:
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.
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.