HiveBrain v1.2.0
Get Started
← Back to all entries
snippetMinor

How to modify a stored procedure using SQLCMD for MS SQL?

Submitted by: @import:stackexchange-dba··
0
Viewed 0 times
storedsqlprocedureusingsqlcmdhowformodify

Problem

Suppose a stored procedure as follows have been created using the Microsoft SQL Management Studio.

use testbase
go
create procedure testtable_pricesmaller
    @pricelimit money
as
select * from testtable where price = @pricelimit;
go


Is it possible to modify a stored procedure using SQLCMD for MS SQL?

Solution

Assuming that you have the permission to do so then there should be no reason why you could not. The following example assumes that you are using Windows Authentication:

sqlcmd -E -S computer\instance -d database

alter procedure testtable_pricesmaller 
@pricelimit money
as
select * from testtable where price = @pricelimit;
go


Alternatively if you have an existing script file that has the command you want to run you could use the -i option to run that file:

sqlcmd -E -S computer\instance -d database -i file.sql


Here is some more information on the sqlcmd utility that you should find helpful:

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

I hope this helps you.

Code Snippets

sqlcmd -E -S computer\instance -d database

alter procedure testtable_pricesmaller 
@pricelimit money
as
select * from testtable where price = @pricelimit;
go
sqlcmd -E -S computer\instance -d database -i file.sql

Context

StackExchange Database Administrators Q#23992, answer score: 5

Revisions (0)

No revisions yet.