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
🐧 38 comments so far... add one ↓
Category | List of Unix and Linux commands |
---|---|
File Management | cat |
Firewall | Alpine Awall • CentOS 8 • OpenSUSE • RHEL 8 • Ubuntu 16.04 • Ubuntu 18.04 • Ubuntu 20.04 |
Network Utilities | dig • host • ip • nmap |
OpenVPN | CentOS 7 • CentOS 8 • Debian 10 • Debian 8/9 • Ubuntu 18.04 • Ubuntu 20.04 |
Package Manager | apk • apt |
Processes Management | bg • chroot • cron • disown • fg • jobs • killall • kill • pidof • pstree • pwdx • time |
Searching | grep • whereis • which |
User Information | groups • id • lastcomm • last • lid/libuser-lid • logname • members • users • whoami • who • w |
WireGuard VPN | Alpine • CentOS 8 • Debian 10 • Firewall • Ubuntu 20.04 |
How do i connect from sql server query analyzer of one server to query analyzer of another server using sql server command
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.
hi ,
how can we know all the tables in a single database in sql 2000.
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
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
SP_HELP tablename
Above will give you column details of your table. You can use your mouse to select/copy the column name and paste it where ever you want
select * from syscolumns where id in (select id from sysobjects where name = ‘Employee’)
how can we know all the tables in a single database in sql 2000.
1- For all tables
SELECT * FROM SYS.TABLES
2- For all tables which contain a specific text
SELECT * FROM SYS.TABLES WHERE NAME LIKE ‘%Ramees%’
how to connect sql server from dos command prompt
sqlcmd -SCONFROOM-PC1\SQLEXPRESS -UBhagwati -PPal-Q”SELECT * FROM [DBO].[TableName]”
How to connect to another server using sqlcmd?
i have written a batch backup script to backup Cash register express data base
which is present in sql server which is remote.
how to run this batch file from command line
let me know how i can add 3 & 4 table in one table & how I can transfer data one table to another table ,if i want to include new colunm in a table how the value of that colunm insert predifined table & how we insert a colunm a particular place by using the alter command or other command .
how I can see the table in linux please tell me
how can i install it on system for database please tell me my boss will kill when he finds out I lied on my application for this job and have no ability to figure even the simplest things out for myself.
I have the connect to data base query,i reply to the please send to my e-mail id
horny hindu :) sounds like black-is-white :)
Hi,
Thanks for ur contribution, this page really helped me.
@Giridhari,
To connect to MS SQL Server (on your local machine), try a line like this one:
“C:\Program Files\Microsoft SQL Server\90\Tools\Binn\SQLCMD.exe” -Shostname\sqlservername -E
More information on the parameters for SQLCMD.exe here: http://www.databasejournal.com/features/mssql/article.php/3654176/SQL-Server-2005-Command-Line-Tool-SQLCMD–Part-I.htm
Ihow can retive database connect with sql server Connect by cmd
YOU CAN CONNECT WITH CMD PROMPT WITH THE FOLLOWING COMMAND TO SQL SERVER
c:\>sqlcmd -U <> -P <>
i.e.
c:\>sqlcmd -U sa -P aleem
hi sir/madam
if user deleted the existing (default) tables in the database, how to retrive emp table once agin, what is the command can u mail to my id,plsss
please can anybody send me the query for
Displaying Database from SQL and then list of tables of DYNAMICALLY selected Database?
please give attention over the word DYNAMICALLY selected……….
thanx plz mail me as soon as possible….
thanks………
Very useful! thanks!
how can i create tables and fields in SQL?
FIRST CONNECT WITH YOUR SQL SERVER I.E. 2005/2008
SELECT DATABASE <>
RIGHT CLICK ON <> TAB
CLICK ON “NEW TABLE” TAB
WINDOW TO START DESIGNING NEW TABLE OPEN
thanks..
This is a good article, but it is not good enough to how to connect SQL through command prompt?
thanks for the article. keep it up…:-)
We can also use like this:
osql /S ServerName /d databaseName /U Username /P password /i c:\test.sql(location of sql file)
Thank you
Hi. We had a batch with ISQLW command to run a query in the Query Analyzer of SQL Server 2000. After upgrading to SQL Server 2005 ISQLW cannot be used anymore so we changed it to the recommended command: SQLCMD. But now the query is run in MS-DOS mode and so its result is shown on a black-not-cool screen. Does anyone know how to obtain the result in a Server Management Studio window? Of course, opening the Server Management Studio and paste the query is not a valid answer. The query must be run from the batch. Thanks in advanced.
when i am trying to connect sql server through command prompt i am unable to connect it ….
I THINK YOU ARE USING YOUR OWN DESKTOP WHILE IT IS NECESSARY TO CONNECT USING REMOTE SERVER DESKTOP TO CONNECT PROPERLY IN SQL SERVER THROUGH COMMAND PROMPT
i should recall that after sp_…. you should use go command to run.for exapmle:
1>sp_help
2>go
Can you please mention SQLS*Plus – this is a great free command line tool. There is command there “show tables” that lists all tables.
I didn’t know that sp_databases as “SHOW DATABASE” ANSI SQL.
Thanks.
Matias Colli
Perito Judicial en Informática
how can i used sql through cmd
ZULFIQAR,
YOU CAN USE BY FOLLOWING SYNTAX :
C:\>sqlcmd -U -P
AFTER THIS, YOU ARE CONNECTED WITH YOUR HOSTED SQL SERVER AND YOU CAN DO EVERYTHING BY PASSING COMMAND OF SQL SERVER.
ALEEMUDDIN SIDDIQUI
SAP ADMINISTRATOR