0

I have a large .sql file in Persian Language. The file is exported from sqlite db browser and has no N prefix for unicode fields. How can I reuse it in Sql Server?

This is sample of insert query in original file:

insert into `words` (id,word) values ('1','2','فارسی');

But I need this

insert into `words` (id,word) values ('1','2',N'فارسی');

I can not use find/replace to replace ,' with ,N' because there are some ,' which represent number fields and has no need to N prefix.

I think I will need some conversion between multiple software (perhaps Microsoft access?) but I have no idea where to start?

  • can you provide the .sql flat file so others can peek into it to get an idea? – Biju jose Dec 23 '18 at 8:17
  • I have added some details to question @Bijujose – Ali Sheikhpour Dec 23 '18 at 8:47
  • are these lines aligned? – Biju jose Dec 23 '18 at 8:54
  • 1
    how about do a replace on every thing as you mentioned like ,' to ,N' and store it into staging table then do a convert and import the required ones. I think that will be the cheapest way to do this. – Biju jose Dec 23 '18 at 8:57
  • Sorry what do you mean from aligned? @Bijujose – Ali Sheikhpour Dec 23 '18 at 8:57
0

Just adding an answer based on the below layout.

CREATE TABLE dbo.words(id NVARCHAR(1000),id2 NVARCHAR(1000),word NVARCHAR(max))


INSERT into dbo.words (id,word) values ('1','2','فارسی');
INSERT into dbo.words (id,word) values ('1','2','فارسی');
INSERT into dbo.words (id,word) values ('1','2','فارسی');
INSERT into dbo.words (id,word) values ('1','2','فارسی');
INSERT into dbo.words (id,word) values ('1','2','فارسی');
INSERT into dbo.words (id,word) values ('1','2','فارسی');
INSERT into dbo.words (id,word) values ('1','2','فارسی');
INSERT into dbo.words (id,word) values ('1','2','فارسی');
INSERT into dbo.words (id,word) values ('1','2','فارسی');
INSERT into dbo.words (id,word) values ('1','2','فارسی');
INSERT into dbo.words (id,word) values ('1','2','فارسی');
INSERT into dbo.words (id,word) values ('1','2','فارسی');

**Do replace all for ,' --> ,N'**

will become

CREATE TABLE dbo.words(id NVARCHAR(1000),id2 NVARCHAR(1000),word NVARCHAR(max))


INSERT into dbo.words (id,word) values ('1',N'2',N'فارسی');
INSERT into dbo.words (id,word) values ('1',N'2',N'فارسی');
INSERT into dbo.words (id,word) values ('1',N'2',N'فارسی');
INSERT into dbo.words (id,word) values ('1',N'2',N'فارسی');
INSERT into dbo.words (id,word) values ('1',N'2',N'فارسی');
INSERT into dbo.words (id,word) values ('1',N'2',N'فارسی');
INSERT into dbo.words (id,word) values ('1',N'2',N'فارسی');
INSERT into dbo.words (id,word) values ('1',N'2',N'فارسی');
INSERT into dbo.words (id,word) values ('1',N'2',N'فارسی');
INSERT into dbo.words (id,word) values ('1',N'2',N'فارسی');
INSERT into dbo.words (id,word) values ('1',N'2',N'فارسی');
INSERT into dbo.words (id,word) values ('1',N'2',N'فارسی');

The only downside is you have to change all column definition to NVARCHAR(). But worth a try if there are not much tables. Also try to separate the tables and insert code to a seperate file to work out.

NB:Also regarding the alignment. If the insert layout is aligned we can press Alt+shift+down arrow will enable a vertical select which is quite useful.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.