?
Solved

How to load sql files from command line

Posted on 2011-09-21
14
Medium Priority
?
212 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:
Ramesh Babu Vavilla earned 2000 total points
ID: 36579313
parameter is as below


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

0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 10

Assisted Solution

by:Ramesh Babu Vavilla
Ramesh Babu Vavilla earned 2000 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:Ramesh Babu Vavilla
ID: 36580540
0
 
LVL 10

Expert Comment

by:Ramesh Babu Vavilla
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

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

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

This article is the result of a quest to better understand Task Scheduler 2.0 and all the newer objects available in vbscript in this version over  the limited options we had scripting in Task Scheduler 1.0.  As I started my journey of knowledge I f…
This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

765 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