Execute stored procedure from cmd.exe?

北慕城南 提交于 2019-12-21 05:01:05

问题


Is there anyway to run a stored proc from cmd.exe ?

p.s.
I know how to create exec file c# and to run it.

I'm asking without any code :

Just me and cmd.exe.

edit

me and cmd.exe : meaning I don't want to write any code. Internal SQL Server help exe files of sql is fine !

sorry for not clarifying this !


回答1:


Try using the SQLCMD Utility :

An example:

sqlcmd -E -S server_name -d database_name -Q "EXEC schema.storedprocedure parameter01, parameter02"

If you'd like to explore other options I'd like to share this link:

Command Prompt Utilities: Applicable for SQL Server 2005




回答2:


  • For sql server 2005+ use its SQLCMD utility, as @Nonim answered
  • for versions prior to 2005 use its OSQL utility, its usage is similar to SQLCMD

Wrap it into the .cmd file and you're in! No needs to write something, just click'n'go! 8-)




回答3:


C# files are not executable. But the compiled program from them is.

CMD is not C# parser neither SQL client. From the CMD you call a program that serves a file. You and CMD can navigate to drive A: to execute file there, to delete files and so on. CMD is emulated environment of DOS, which is also OS - you need a program to execute the SQL queries. See this (Sqlcmd program of SQL Server):

http://msdn.microsoft.com/en-us/library/ms165702.aspx



来源:https://stackoverflow.com/questions/8688426/execute-stored-procedure-from-cmd-exe

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!