running a sql server management studio express query from a script

Hi

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?
bergsprekkenAsked:
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

http://www.databasejournal.com/features/mssql/article.php/3654176/SQL-Server-2005-Command-Line-Tool-SQLCMD--Part-I.htm
0
 
shlafrockCommented:
Have you tried to use SQLCMD in your script?

SQLCMD /?
programm is somwhere in Tools\Binn in  MSSQL folder
0
 
bergsprekkenAuthor Commented:
Havent tried SQLCMD yet, is that compatible with the same sql syntax that worked in managementstudio?
0
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.