Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 .sql file

Author  Topic 

modraj
Starting Member

1 Post

Posted - 2009-07-20 : 15:54:53
How can I run a program1.sql file stored under my local directory c:\db\prog. The script contains certain select statement and a table creation script.

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2009-07-20 : 16:45:02
You can use sqlcmd to execute a saved script. You could also just open the file in SSMS and hit F5.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog

"Let's begin with the premise that everything you've done up until this point is wrong."
Go to Top of Page

Mangal Pardeshi
Posting Yak Master

110 Posts

Posted - 2009-07-21 : 02:29:05
As suggested by Tara, you can use sqlcmd or just open the file in management studio and run it.
here example using sqlcmd

Using sql authentication

xp_cmdshell 'Sqlcmd -S Servername -U suername -P password -i C:\filename.sql'

for using windows authentication replace -U and -P with E
see http://msdn.microsoft.com/en-us/library/ms162773.aspx

Mangal Pardeshi
http://mangalpardeshi.blogspot.com
Go to Top of Page
   

- Advertisement -