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

Hello,

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?
jollykhAsked:
Who is Participating?
 
rbrookerCommented:
Hi,

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.

:)
0
 
sathyagiriCommented:
@C:\Test.sql

or
run c:\test.sql
0
 
rbrookerCommented:
Hi,

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

good luck.

:)
0
 
jollykhAuthor Commented:
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.
0
 
jrb1Commented:
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.
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.