Solved

How to load sql files from command line

Posted on 2011-09-21
14
206 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
Zoho SalesIQ

Hassle-free live chat software re-imagined for business growth. 2 users, always free.

 

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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Programmatically signing Word macros 4 61
Update in Sql 7 30
Problem to With line 4 41
How to pass 2 IN parameters to a stored procedure using SQL Server 2008? 6 29
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…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
In this video I am going to show you how to back up and restore Office 365 mailboxes using CodeTwo Backup for Office 365. Learn more about the tool used in this video here: http://www.codetwo.com/backup-for-office-365/ (http://www.codetwo.com/ba…

910 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

24 Experts available now in Live!

Get 1:1 Help Now