• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 217
  • Last Modified:

How to load sql files from command line

How can I load .sql files via command line into a sql db?
0
goretailpro
Asked:
goretailpro
  • 5
  • 4
  • 4
  • +1
2 Solutions
 
effesCommented:
Hi goretailpro,

SQL Server comes with a command line utility called "sqlcmd". You can read all about it's use here.

Hope that helps.
0
 
Anthony PerkinsCommented:
You are looking for the -i parameter when using SQLCmd.
0
 
Ramesh Babu VavillaCommented:
parameter is as below


sqlcmd -E -S .\SQLEXPRESS -i scriptfile.sql -o RestoreDB.log

0
Cloud Class® Course: Microsoft Exchange Server

The MCTS: Microsoft Exchange Server 2010 certification validates your skills in supporting the maintenance and administration of the Exchange servers in an enterprise environment. Learn everything you need to know with this course.

 
Ramesh Babu VavillaCommented:
sqlcmd -E -S
.\SQLEXPRESS   server name
-i Restore_And_Create_User _Script.sql   sqlscript
 -o RestoreDB.log   logfile to write the result
0
 
Ramesh Babu VavillaCommented:
0
 
Ramesh Babu VavillaCommented:
just rename the txt file to a batch name (.bat)
user.txt
0
 
goretailproAuthor Commented:
Is there a way to have this done as a wild card with any SQL scripts?
0
 
goretailproAuthor Commented:
right now Every xml files comes across like this "109000773.2011-08-12-12-37-28.f.sql"  the first digit's is always stay the same.  Any suggestions..
0
 
Anthony PerkinsCommented:
>>Is there a way to have this done as a wild card with any SQL scripts? <<
While the -i parameter does not accept wild cards there is nothing stoping you from using a batch file or a VBScript to fill them.  Alternatively you can list all the SQL queries one after the other as in:
-i file1.sql, file2.sql, file3.sql,...
0
 
goretailproAuthor Commented:
Do you know of a 3rd party software that can look at a folder and load all SQL files into a db?
0
 
Anthony PerkinsCommented:
No.  You can certainly do that with SSIS, it is just that you will have to roll up your sleaves and create an SSIS package to do it.  On the other hand if you are using SQL Express, than SSIS is not an option.
0
 
goretailproAuthor Commented:
Any suggestions on these templates that can start me in the correct direct?

http://msftisprodsamples.codeplex.com/
0
 
Anthony PerkinsCommented:
I am afraid I have no idea.
0
 
goretailproAuthor Commented:
Do you know of a place online that is good for getting bids for this project?
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.

Join & Write a Comment

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 5
  • 4
  • 4
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now