September 23, 2015 at 3:24 pm
Hi experts,
How do I execute below scripts using CMD:
Please Note: SQL server 2008r2, default instance with window Authentication.
1. Select * from Adventurewoks2008.Person.Person where Id = 5
2. Exec usp_getemployee (with parameter Manager_id = 100)
3. I have a folder named 'MyFolder' which contains 3 store procedures (usp_A, usp_B and usp_C). How do I execute all 3 using CMD against AdventureWorks database.
September 23, 2015 at 5:53 pm
Tac11 (9/23/2015)
Hi experts,How do I execute below scripts using CMD:
Please Note: SQL server 2008r2, default instance with window Authentication.
1. Select * from Adventurewoks2008.Person.Person where Id = 5
2. Exec usp_getemployee (with parameter Manager_id = 100)
3. I have a folder named 'MyFolder' which contains 3 store procedures (usp_A, usp_B and usp_C). How do I execute all 3 using CMD against AdventureWorks database.
I have to first ask why you want to do these things from the Command Line.
--Jeff Moden
Change is inevitable... Change for the better is not.
September 24, 2015 at 6:40 am
Just some questions, with different scenario. Would appreciate if you post answer
September 24, 2015 at 6:54 am
Smells like a homework question to me. Have you looked at sqlcmd? If so, what have you tried? By the way, a folder contains subfolders and/or files. A database contains stored procedures. Please will you be more specific about what is in your folder in item 3?
John
September 24, 2015 at 6:56 am
sqlcmd or bcp are the two command line options.
bcp is designed for importing or exporting data, whereas sqlcmd can do both, but also execute commands;
i've used use sqlcmd to run backup commands, for example, on express instances that don't have SQL Agent and job capabilities.
if you are just executing the procedures, with no output, you'd use sqlcmd only.
it sounds more complex though, since your procs are files and not something already on the server, right?
Lowell
September 24, 2015 at 7:14 am
You can simply use the SQL Server command object from Powershell to make these calls. It's easy. Here are some examples.
"The credit belongs to the man who is actually in the arena, whose face is marred by dust and sweat and blood"
- Theodore Roosevelt
Author of:
SQL Server Execution Plans
SQL Server Query Performance Tuning
September 24, 2015 at 8:52 am
Wow. Just asked simple questions, no answer but too much noise!!!!
September 24, 2015 at 9:40 am
Tac11 (9/24/2015)
Wow. Just asked simple questions, no answer but too much noise!!!!
Not sure what you're looking for? The link I posted shows how to call stored procedures from the command line using Powershell. Done.
"The credit belongs to the man who is actually in the arena, whose face is marred by dust and sweat and blood"
- Theodore Roosevelt
Author of:
SQL Server Execution Plans
SQL Server Query Performance Tuning
September 24, 2015 at 10:34 am
and here's a basic example for the command line:
sqlcmd -S . -d master -E -Q "exec sp_who"
Lowell
September 24, 2015 at 4:42 pm
Thanks Lowell.
@Grant. I had posted my questions, I am not looking for Powershell script.
Server 'Myserver', 'default instance' with 'window Authentication'. I want below queries to execute on CMD.
1. Select * from Adventurewoks2008.Person.Person where Id = 5
2. Exec 'usp_getemployee' with parameter Manager_id = 100
3. I have a folder named in 'C:\MyFolder' which contains 3 store procedures (usp_A, usp_B and usp_C). How do I execute all 3 using CMD against AdventureWorks database. just need to execute don't need results.
Hope you understand my question.
September 24, 2015 at 7:02 pm
Tac11 (9/24/2015)
Wow. Just asked simple questions, no answer but too much noise!!!!
No problem. Moving on. 😉
--Jeff Moden
Change is inevitable... Change for the better is not.
September 24, 2015 at 8:49 pm
Tac11 (9/24/2015)
@Grant. I had posted my questions, I am not looking for Powershell script.
Powershell isn't run from the command line?
OK.
"The credit belongs to the man who is actually in the arena, whose face is marred by dust and sweat and blood"
- Theodore Roosevelt
Author of:
SQL Server Execution Plans
SQL Server Query Performance Tuning
September 25, 2015 at 5:57 am
there was a recent article that demonstrated how to run all *.sql files in a given folder.
that means the scripts contain commands that already have to have the parameters to call.
look at this article from not too long ago:
http://www.sqlservercentral.com/articles/sqlcmd+mode/129764/
Lowell
Viewing 13 posts - 1 through 13 (of 13 total)
You must be logged in to reply to this topic. Login to reply