running a sql server management studio express query from a script


I have a .sql file that I have to run on a database each day. When I make a new query on the database in sql server management studio express and paste in the contents of my .sql file it runs perfectly.

The question is, can this process be run automatically by a script or similar?
Who is Participating?
shlafrockConnect With a Mentor Commented:
You're using SQL on a database, not on managment studio, so yes SQL syntax is the same in both.

Create a bat file with something like :
sqlcmd -i file.sql        // i'm not sure about syntax - try the link below

To run a script every day use Task Scheduler
Have you tried to use SQLCMD in your script?

programm is somwhere in Tools\Binn in  MSSQL folder
bergsprekkenAuthor Commented:
Havent tried SQLCMD yet, is that compatible with the same sql syntax that worked in managementstudio?
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.