Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Administration
 sql cmd doubt

Author  Topic 

sunsanvin
Master Smack Fu Yak Hacker

1274 Posts

Posted - 2010-04-09 : 11:31:17
Hi All,
i've a sqlcmd statement need to execute from command prompt. after copying and paste at the command prompt, i entered Enter. then it is giving the numbers like
1>
2>
3>

not sure how to execute. help

Arnav
Even you learn 1%, Learn it with 100% confidence.

jackv
Master Smack Fu Yak Hacker

2179 Posts

Posted - 2010-04-09 : 11:42:05
at that point you need to enter some commands, for example , if you wanted the list of databases on the system , it would b something like:
1>use master
2>select name from sysdatabases
3>go



You can see other switches by :
SQLCMD -?


Jack Vamvas
--------------------
http://www.ITjobfeed.com
Go to Top of Page

sunsanvin
Master Smack Fu Yak Hacker

1274 Posts

Posted - 2010-04-09 : 11:45:39
Hi Jack,
below is the script (changed actual names)

sqlcmd -S abc\ddhhgg -E
:r "P:\adc\fkgsgd\Deployment\OneTime\CR\CR3334_Setup.sql"

in the request, no databse name is mentioned....
pls help

Arnav
Even you learn 1%, Learn it with 100% confidence.
Go to Top of Page

jackv
Master Smack Fu Yak Hacker

2179 Posts

Posted - 2010-04-09 : 15:15:10
Hi
If you want to run the script - for example - from your command line. Do :
SQLCMD -E -S abc\ddhhgg -d myDb -i "P:\adc\fkgsgd\Deployment\OneTime\CR\CR3334_Setup.sql"

In the example I've posted - this would run the script on the -i switch on the database mentioned on the -d switch.
Obviously , I don't know what you've got in the script , so I'm making some assumptions .


Jack Vamvas
--------------------
http://www.ITjobfeed.com
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2010-04-09 : 19:30:11
You can also specify the database inside your sql file with a USE statement. I almost always code it inside my sql file, but the -d switch works great too.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page
   

- Advertisement -