Script files in SQL

  • Hi all,

    I have the follwing Code in a .sql file

    Declare @SQLStmt varchar(max)

    set @SQLStmt='insert into sa(last,first)values(1,2)'

    exec(@SQLStmt)

    The Requirement is as soon as I double click on this SQL file , it should insert a row in my table "SS" without clicking on the Execute button. Can any one tell me how can I achieve this?

  • you would need to create a batch file which calls SQLCMD passing in the .sql file and then run the batch file, the only way in SSMS is to press F5 or the execute button

  • Create .bat file:

    sqlcmd -S ServerName -E -d DatabaseName -Q "insert into sa(last,first)values(1,2)"

  • Thank you all for the replies..It worked..

Viewing 4 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic. Login to reply