Solved

How to load sql files from command line

Posted on 2011-09-21
14
208 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
Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

 
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

VMware Disaster Recovery and Data Protection

In this expert guide, you’ll learn about the components of a Modern Data Center. You will use cases for the value-added capabilities of Veeam®, including combining backup and replication for VMware disaster recovery and using replication for data center migration.

Question has a verified solution.

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

SQL Server engine let you use a Windows account or a SQL Server account to connect to a SQL Server instance. This can be configured immediatly during the SQL Server installation or after in the Server Authentication section in the Server properties …
Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backup…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…

792 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