Solved

How to load sql files from command line

Posted on 2011-09-21
14
209 Views
Last Modified: 2012-05-12
How can I load .sql files via command line into a sql db?
0
Comment
Question by:goretailpro
[X]
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
  • 5
  • 4
  • 4
  • +1
14 Comments
 
LVL 6

Expert Comment

by:effes
ID: 36576975
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
 
LVL 75

Expert Comment

by:Anthony Perkins
ID: 36577781
You are looking for the -i parameter when using SQLCmd.
0
 
LVL 10

Accepted Solution

by:
sqlservr earned 500 total points
ID: 36579313
parameter is as below


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

0
Free eBook: Backup on AWS

Everything you need to know about backup and disaster recovery with AWS, for FREE!

 
LVL 10

Assisted Solution

by:sqlservr
sqlservr earned 500 total points
ID: 36579316
sqlcmd -E -S
.\SQLEXPRESS   server name
-i Restore_And_Create_User _Script.sql   sqlscript
 -o RestoreDB.log   logfile to write the result
0
 
LVL 10

Expert Comment

by:sqlservr
ID: 36580540
0
 
LVL 10

Expert Comment

by:sqlservr
ID: 36580548
just rename the txt file to a batch name (.bat)
user.txt
0
 

Author Comment

by:goretailpro
ID: 36588599
Is there a way to have this done as a wild card with any SQL scripts?
0
 

Author Comment

by:goretailpro
ID: 36589286
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
 
LVL 75

Expert Comment

by:Anthony Perkins
ID: 36590676
>>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
 

Author Comment

by:goretailpro
ID: 36601893
Do you know of a 3rd party software that can look at a folder and load all SQL files into a db?
0
 
LVL 75

Expert Comment

by:Anthony Perkins
ID: 36650332
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
 

Author Comment

by:goretailpro
ID: 36717187
Any suggestions on these templates that can start me in the correct direct?

http://msftisprodsamples.codeplex.com/
0
 
LVL 75

Expert Comment

by:Anthony Perkins
ID: 36718872
I am afraid I have no idea.
0
 

Author Comment

by:goretailpro
ID: 36903081
Do you know of a place online that is good for getting bids for this project?
0

Featured Post

Ransomware: The New Cyber Threat & How to Stop It

This infographic explains ransomware, type of malware that blocks access to your files or your systems and holds them hostage until a ransom is paid. It also examines the different types of ransomware and explains what you can do to thwart this sinister online threat.  

Question has a verified solution.

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

Use this article to create a batch file to backup a Microsoft SQL Server database to a Windows folder.  The folder can be on the local hard drive or on a network share.  This batch file will query the SQL server to get the current date & time and wi…
When you see single cell contains number and text, and you have to get any date out of it seems like cracking our heads.
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

740 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