How do you execute a .sql file in MS SQL Query Analyzer

Posted on 2006-07-18
Last Modified: 2008-01-09

I have a file called "test.sql" that is located on my C: Drive.  I opened up MS SQL and opened Query Analyzer.  How do I tell the Query Analyzer to execute the file "test.sql"?  I tried entering "C:\test.sql" in the analyzer but I got the error message: Syntax error at \.

Can anyone help?
Question by:jollykh
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
LVL 14

Expert Comment

ID: 17134856

run c:\test.sql
LVL 18

Expert Comment

ID: 17134857

open Query Analyzer, open the sql file and execute...

good luck.


Author Comment

ID: 17134908
I tried both methods and neither worked.

RUN C:\test.sql
gives me the error message "Syntax error at \"

When I attempted to open the file, it gave me all the SQL commands but all the commands started with the box-character.
LVL 18

Accepted Solution

rbrooker earned 250 total points
ID: 17135110

have you tried File -> Open and opened the sql file that way?
or you can open the sql file in notepad and copy and paste the contents.

LVL 25

Expert Comment

ID: 17135120
It sounds like you have a corrupt file.  Maybe a tool lke TEXTPAD can read it successfully.

I do think you will have to open the file in Query Analzyer and run it.  The @script or run c:\script... are correct for Oracle, but I didn't think it worked in Query Analyzer.

Featured Post

Percona Live Europe 2017 | Sep 25 - 27, 2017

The Percona Live Open Source Database Conference Europe 2017 is the premier event for the diverse and active European open source database community, as well as businesses that develop and use open source database software.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Never store passwords in plain text or just their hash: it seems a no-brainier, but there are still plenty of people doing that. I present the why and how on this subject, offering my own real life solution that you can implement right away, bringin…
Recently I was talking with Tim Sharp, one of my colleagues from our Technical Account Manager team about MongoDB’s scalability. While doing some quick training with some of the Percona team, Tim brought something to my attention...
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

622 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