Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Command line logon to SQL Server 7.0

Status
Not open for further replies.

spittingfire

Technical User
Feb 6, 2002
18
CA
Hi All,

I'm new to the world of MSSQL and I would like to know how to log on to MSSQL Server using the command line.

Can one of you point me in the right direction? I just want the command the I would use to log on to the server from the command prompt.

I can access it from the GUI but I also want to do it from the command prompt.

Thanks for your help in advance.
 
OSQL is a command line utility that is provided with SQL Server. It is documented in SQL Books Online.

However, I'm not sure this answers your question. What do you mean by login to SQL Server from the command line? Do you have a tool in mind? What do you want to do when you login from the command line? Terry L. Broadbent - DBA
Computing Links:
faq183-874 contains "Suggestions for Getting Quick and Appropriate Answers" to your questions.
 
What I want to do is to be able to use the command line to log into the SQL and be able to create my Databases instead of doing it through the GUI. I can do it easily using the GUI.

I've used MYSQL in the past where I just log on to the server using the command line and entering my credentials and then I can do what I want from there.

I tried both ISQL and OSQL and all that I'm give is the following prompt 1>

I don't know what I should do from here. I tried running some simple commands for listing database or creating but it just gives another prompt 2> or 3> etc...

From the 1> prompt how will I access an existing database or create one? I'm not asking for a lesson in SQL Server - all I want to do is just be able to get to the point where I can connect or create to a database at command prompt.

Thanks for your response.

 
If you want to create databases from a command line program, use OSQL. If you don't know how to use it, open SQL Books Online (SQL BOL) and read about the OSQL utility. If you are unfamiliar with SQL BOL, read faq183-689, "What are SQL Books Online & Where Can I Find Them?"

The following is a simple example that connects to the server named server1 using NT authentication (trusted connection), opens the HR database and selects a row from the Employees table.

osql -E -Sserver1 -DHR
1>Select * From Employees Where EmpID=2557
2>Go
1>quit

Note the 'Go.' Go terminates the batch and causes SQL Server to execute the statement(s). You can include multiple SQL statements in a batch. Terry L. Broadbent - DBA
Computing Links:
faq183-874 contains "Suggestions for Getting Quick and Appropriate Answers" to your questions.
 
Thanks - this is exactly what I was looking for.

You have been a tremendous help!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top