How do I import a sql data file (the content of file are INSERT queries) into SQL Server? - sql

I have a .sql file with a content of insert queries for all tables of my database.
This file is 12 GB in size. I tried to open it with Notepad++, SQL Server Management Studio, and also with chrome browser, but the file is very long. I cant' open it.
How can I import it into my database directly without opening the file and execute the queries?
What is the proper way to do this?

you need to use sqlcmd , the documentation has a full explanation of how to use it but here is a quick sample how to use it, you need to install sqlcmd utility first then open up your cmd command prompt and type the command like this :
sqlcmd -S DBSERVER\TESTINSTANCE -d DATABASENAME -U USERNAME -P PASSWORD -i "D:/InsertData.sql"

Related

Unable to run .sql file in SQL Server

I have a .sql dump file 20 gb and I am trying to run it on Mysql workbench using run script and after successful execution, using SSMA I'll migrate the data from Mysql workbench to SQL Server. I have migrated the data this way many times successfully however for 20 gb file it seems very time-consuming. Please let me know if there is any alternate way to achieve this quickly. I have followed the following link:
Steps to migrate mysql tables to sql server using SSMA!
From your Title "unable to run .sql file in SSMS" and "I have a .sql dump file 20 gb" are you trying to open a 20GB .sql in SSMS? That's never going to work. SSMS is a 32bit application, so the maximum addressable memory is 2GB. If you want to run your .sql file, I suggest using sqlcmd.
Open up Powershell, and then run the command below replacing the appropriate parts:
sqlcmd -S {Server Name/ServerIP} -U {Your Login} -i {Your full path to your script}
You'll be prompted for your password and then you the file will be run. So, as an example, you might run:
sqlcmd -S svSQL2017 -U Larnu -i \\svFileServer\SQLShare\Scripts\BigBatchFile.sql
If you are using integrated security, then don't pass the -U parameter for the command.
Edit: This answer is no relevant to the OPs question, as they were using "SSMS" as a synonym for SQL Server, which it is not. I have left this here for the moment so the OP can review my comments, and I will likely remove this answer at a later point.

Is it possible to insert a sql code with batch file in xampp

I wrote a batch script that it creates a sql file for my database.
It will automatically write id and image file direction and idproduct but I don't know how to insert mysql code with using batch file to xampp phpmyadmin
Simply use the MySQL.exe tool in your batch:
mysql -u username -p password database_name < "c:\path\to\SqLfile.sql"

How to Insert million of Insert Command having in .sql file

I have .sql file which contains millions of Insert commands, and they are having insert statements to be inserted into different tables. When I am executing by opening in SQL SERVER MANAGEMENT it says
Insufficient memory to continue the execution of program
You can save the SQL in a file and execute it from the command line using sqlcmd. For example:
sqlcmd -S myServer\instanceName -i C:\myScript.sql
Please note: If your instance is a default instance (i.e. the instance name is MSSQLSERVER), then do not specify it as part of the sqlcmd parameters. To connect to the default instance, simply specify the server name. For example:
sqlcmd -S myServer -i C:\myScript.sql
I would suggest you try running the .sql from the command line (sqlcmd.exe) instead of loading it in SSMS.
SQLCMD - MSDN Link

How to run sql queries in SQL Developer or TOAD and extract result using bat file

Is there a way through which i can execute SQL query in SQL Developer/TOAD and extract the result in any format using .bat file.
I m working on a client machine so using any other software other than SQL Developer/TOAD is not a option.
Please suggest how to create a bat file for the same.
If SQL Developer is installed I venture to guess so is SQL Plus. SQL Developer is simply a graphic interface to the database connections. Try opening a command window, I assume you can since you would like to run .bat programs, and typing in sqlplus. If this comes back with version numbers and a prompt for a user name you should be able to use this for your script.
See this answer on Stack Overflow for more tips on how to run .bat programs from SQL Plus with native SQL Plus spooling.
What version of Toad? If the version of Toad you have has the Automation Designer then you can setup an action to export query results to many different formats. See my answer in this question for steps to export query results to XLS. In step #3 you can choose other formats. Your configured actions can be scheduled or executed by .bat file. Toad's help covers command line execution of these actions.
You can put the following types of sqlcmd statements into a batch file. After running the results are saved to a txt file. This example executes a SQL file already created and saves the results to a txt file.
Step 1: Create SQL file which you want to execute.
Step 2: Execute following sqlcmd command on prompt:
sqlcmd -i SQLFile.sql -S ServerLocation -E -o File.txt
If you are using username and password run following script
sqlcmd -i SQLFile.sql -S localhost -U username -P password -o File.txt
You can run something like this for SQL plus:
sqlplus user/pwd#mydb #SQLFile.sql > File.txt

How to run .sql file from a batch file?

I am running sql server 2008 express and i need to schedule some stored procedures to run nightly...so i have built out these .sql files which i would want to run from .bat file...i need to know the command to execute these .sql files one by one and store their results i guess...can anyone help me out?
I answered this in this other question:
You should invoke the sqlcmd command-line tool from your batch file. Assuming your sql file is "backup.sql", the command line would be something like:
sqlcmd -E -S yoursqlinstance -i backup.sql
-E uses trusted connection, replace with -U and -P if you need to specify a SQL username and password. See also this article with examples.
See the sqlcmd utility:
http://msdn.microsoft.com/en-us/library/ms165702.aspx
This allows you to run sql scripts from the command line
osql:
http://www.di-mgt.com.au/osqlUtility.htm
I don't use SQL Server, but a batch file is just a list of DOS commands. So whatever you use to execute SQL files from the commandline can be used in a batch file.
A quick google search turns up:
sqlcmd -i <inputfile> -o <outputfile>
Hope this helps you :
sqlplus UserName/Password#DataBase #C:\sqlFolder\sqlFile.sql
P.S : Don't forget to add the command "commit;" at the end of sql file (sqlFile.sql), this command order Oracle to save performed changes in database