Solved

How to load sql files from command line

Posted on 2011-09-21
14
205 Views
Last Modified: 2012-05-12
How can I load .sql files via command line into a sql db?
0
Comment
Question by:goretailpro
  • 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
 
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
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 

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

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Not long ago I saw a question in the VB Script forum that I thought would not take much time. You can read that question (Question ID  (http://www.experts-exchange.com/Programming/Languages/Visual_Basic/VB_Script/Q_28455246.html)28455246) Here (http…
Occasionally there is a need to clean table columns, especially if you have inherited legacy data. There are obviously many ways to accomplish that, including elaborate UPDATE queries with anywhere from one to numerous REPLACE functions (even within…
This video discusses moving either the default database or any database to a new volume.
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

759 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now