About Linux FAQ

Browse More FAQs:

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

Posted by Vivek on Monday December 18, 06 @11:25 pm

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:

Discussion on This FAQ

  1. Suman Says:

    How do i connect from sql server query analyzer of one server to query analyzer of another server using sql server command

  2. Telly B Says:

    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.

  3. suman Says:

    hi ,
    how can we know all the tables in a single database in sql 2000.

  4. Balaji Vinu Says:

    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

  5. Praveen Says:

    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

  6. Rakesh Kumar Says:

    select * from syscolumns where id in (select id from sysobjects where name = ‘Employee’)

  7. awadhesh Says:

    how can we know all the tables in a single database in sql 2000.

  8. avn Says:

    how to connect sql server from dos command prompt

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!

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

*
To prove you're a person (not a spam script), type the security word shown in the picture. Click on the picture to hear an audio file of the word.
Click to hear an audio file of the anti-spam word

~ Last updated on: December 18, 2006

Copyright © 2006-2008 nixCraft. All rights reserved - TOS/Disclaimer - Privacy policy - Sitemap - Powered by Open source software.