Solved

running a sql server management studio express query from a script

Posted on 2010-09-08
4
737 Views
Last Modified: 2012-05-10
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?
0
Comment
Question by:bergsprekken
  • 2
4 Comments
 
LVL 1

Expert Comment

by:shlafrock
Comment Utility
Have you tried to use SQLCMD in your script?

SQLCMD /?
programm is somwhere in Tools\Binn in  MSSQL folder
0
 

Author Comment

by:bergsprekken
Comment Utility
Havent tried SQLCMD yet, is that compatible with the same sql syntax that worked in managementstudio?
0
 
LVL 7

Expert Comment

by:rashmi_vaghela
Comment Utility
0
 
LVL 1

Accepted Solution

by:
shlafrock earned 500 total points
Comment Utility
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

Featured Post

Control application downtime with dependency maps

Visualize the interdependencies between application components better with Applications Manager's automated application discovery and dependency mapping feature. Resolve performance issues faster by quickly isolating problematic components.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Having clause with Case 2 30
Trigger for audit 26 48
sql sERVER PARSE DATA BY HOURS AND COLUMNS 2 30
SQL Select * from 6 29
I've encountered valid database schemas that do not have a primary key.  For example, I use LogParser from Microsoft to push IIS logs into a SQL database table for processing and analysis.  However, occasionally due to user error or a scheduled task…
So every once in a while at work I am asked to export data from one table and insert it into another on a different server.  I hate doing this.  There's so many different tables and data types.  Some column data needs quoted and some doesn't.  What …
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now