Connect to SQL Server from command prompt - list tables and database
Q. How do I connect to Microsoft SQL Server from command prompt? I just wanted to see list of tables and database.
A. MS- SQL Server is relational database management system.
Its primary query language is Transact-SQL, an implementation of the ANSI/ISO standard Structured Query Language (SQL) used by both Microsoft and Sybase.
There is command line tool available and it is called as sqlcmd. you need to enter the word GO after every command.
On the Start menu click Run. In the Open box type cmd, and then click OK to open a Command Prompt window.
At the command prompt, type sqlcmd.
Press ENTER.
Let us say your username is vivek and password is foo, use:
C:> sqlcmd -U vivek -P foo
Once connected you should see 1> prompt. Type following command to use database called sales:
use sales
GO
To list tables type:
sp_help
OR
select * from SYSOBJECTS where TYPE = 'U' order by NAME
To List all the databases on the server:
sp_databases
To list fields in a table called foo:
sp_help tablename
sp_help foo
Subscribe to our free e-mail newsletter or RSS feed to get all updates.
You can Email this page to a friend.
Related Linux / UNIX FAQ:
- MySQL command to show list of databases on server
- MySQL empty database / delete all tables
- Create a mysql database, tables and insert data
- How to access MySQL database using Perl
- Mysql user creation - setting up a MySQL new user account
Discussion on This FAQ
Leave a Reply
We encourage your comments, and suggestions. But please stay on topic, be polite, and avoid spam. Please do not use the comment form to ask for help / question. Ask your question on the excellent Linux tech support forum. Thank you very much for stopping by our site!
~ Last updated on: December 18, 2006


January 11th, 2007 at 7:18 am
How do i connect from sql server query analyzer of one server to query analyzer of another server using sql server command
March 16th, 2007 at 4:58 pm
I Just want to say thanks for having this answer on this article. I did not want to drag each table 1 by 1 in SSMS.
May 24th, 2007 at 10:49 am
hi ,
how can we know all the tables in a single database in sql 2000.
July 9th, 2007 at 6:35 am
Hi ,
How can i connect to informix database using unix testbox.
please let me know the command and the environmental changes that i have to make.
Thanks and Regards
Balaji Vinu
February 10th, 2008 at 1:42 pm
Hi
How to get the column names from a table.
e.g. Select Emp_Id, Emp_Name from Employee.
I know that i have the table Employee. I have to query and get the column names using those column name i want to do a select query.
Kindly let me know
Regards
March 24th, 2008 at 9:21 am
select * from syscolumns where id in (select id from sysobjects where name = ‘Employee’)
March 27th, 2008 at 10:43 am
how can we know all the tables in a single database in sql 2000.
April 23rd, 2008 (4 weeks ago) at 7:01 am
how to connect sql server from dos command prompt