How can I insert multiple lines once only using Sql?

Asked

Viewed 2,525 times

0

I exported a Sqlite data record to Sql Server with Dump. I need to take these records and insert them into a new table that I created to receive these records within my database in Sql server. The problem is that I have many lines to insert.There are over 1,000 lines and I wonder if there is a simpler way to do this than to repeat 1000 times the Insert into nameDaTable values...

ex:

INSERT INTO MyTable VALUES ("John", 123, "Lloyds Office");
INSERT INTO MyTable VALUES ("Jane", 124, "Lloyds Office");
INSERT INTO MyTable VALUES ("Billy", 125, "London Office");
INSERT INTO MyTable VALUES ("Miranda", 126, "Bristol Office");
INSERT INTO MyTable VALUES ("John", 123, "Lloyds Office");
INSERT INTO MyTable VALUES ("roger", 23, "Nuvens");
INSERT INTO MyTable VALUES ("jose", 500, "London Office");
INSERT INTO MyTable VALUES ("elanda", 126, "Paris");

Let’s imagine that these Insert have more than 1,000 Is there a way to make it easier without repeating 1,000 times?

here is a print of how the records are: inserir a descrição da imagem aqui

  • Don’t get it, you have the sql lite dump with the Insert or not?

  • Where does the information come from? Excel? Another table?

  • These records were in sqlite.We made a conversion to sql server. needed to create a database in sql server and save that data that was in Sqlite within Sql server. @rray

  • put how the data is currently, whether csv or xml

  • 2

    takes advantage that is in Notepad++ and makes a macro changing the text to your need, simpler...

  • @Rovannlinhalis a macro?? did not understand what is sorry rsrs.

  • Do you have sql management (ssms) installed? don’t just copy these paste Inserts and give an F5 to run them all at once?

  • got it...yes I could up but have to insert one more Covert(varbinary(max) to convert image so I did right not to have more work after.so I must do this for all lines

  • @rray I want to believe that this is the sqllite dump and is with structure other than sql server, it is not possible... rs Gladiador... use macros in np++ : https://www.youtube.com/watch?v=xQaxDeCwMRg

  • I can understand the problem better ... if you want to put this function on top of some value you can try using the np++ column mode or a little regex :D

  • @Rray saved my day man hahaha worth.

  • @Rovannlinhalis now understood what you meant by Macro on Notepad++ this also worked well that gives a little work.THANKS for helping, it was even worth!!

  • dispo. Do not forget to post how your problem was solved to close the issue

Show 8 more comments

3 answers

3

There are some simpler ways to copy this data:

Linked Server You can make a Linked server from the source server on the target server. This way you can make an Insert based on a select.

Data import You can import the data by Wizard sql server, right-clicking on the target database, go to tasks and import data, as in the following figure inserir a descrição da imagem aqui

Manually edit the records in the table There is still the possibility to right-click on the target table in the explorer Object and click on the item "Edit 200 rows higher". With this option the table will open as in excel. And it will be possible to paste the records if they are in the clipboard (either as source in a grid, select result or excel).

  • I’ll try to do it this way now I’ll tell you later. I’m grateful you responded :)

  • Data imports accept various types of source and data connections.

  • @Gladiator, did it work? If yes, mark the answer as a valid answer to the question.

1

Go to your sqlite and make a query that manages the querys:

select 'insert into ..... values ('+Campo+','..... from sua tabela....

The result must have the'load script'

Another option is to export the database structure using the Sqlite Browser, using the option Export to SQL.

EDIT

You can use the result of a select to include records in a table:

insert into tabela values select campos from tabela.....
  • this part of exporting the structure has already been done. And generated me a lot of Insert. Now you just need to insert this exported data into a new table in Sql.

0


So guys with your help I managed to solve this mystery. to replace in the right place, I had to use a regular expression by the site https://regex101.com/ test if he could find exactly where I should be doing my replace. My regular expression in my case was VALUES. *, ([0-9]{5}), 5 digits.' inserir a descrição da imagem aqui

After he found I just replaced it with values I wanted in a row and I used the Notepad++ macro as recommended by someone here to repeat the same action for all rows and then play sql and run the records and insert in the database.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.