How to change file type from binary to text for .sql file


I've added a sql file via TortoiseHg to my Mercurial repository and it went in a a binary file rather than text.

1) Can I change it to text so that I can see revision changes through the web interface like all my other source files?

2) Was there something I missed when adding which caused this?

Thank you.

3 answers

1 accepted

The problem turns out to be that the file was created in unicode rather than ansi text encoding by SQL Server Management Studio. It was a default option on the export task.

Mercurial does not play nicely with it and adds it to the repository as a binary file which will not allow previewing or diffs from TortoiseHg or the web interface.

So, to answer my original question of how to change it after it has been added, I opened it in notepad and saved it as an ANSI file. Now it works.

0 vote
Jason Worley Atlassian Team Feb 22, 2013


SQL files, like images (.jpg, etc) are generally transferred over SSH, FTP and SCP in binary (BIN) format.

The standard approach would be to load the SQL file into a local DB such as MySQL and from there you can select data as well as export data.

If you really want to convert the data to text format, most likely your best bet is to research/find/download a 3rd party application or you might get lucky by using wordpad or other word editors.

For 3rd party solutions, I just did a google search and found several hits, for example:

I hope this response was helpful.

Jason | Atlassian

In case someone who runs across this has a lot of these files, like I did, you could run this PowerShell script to update all of your .SQL files at once.

Get-ChildItem -Recurse *.sql | foreach {
$FileName = $_.FullName;
[System.Io.File]::ReadAllText($FileName) | Out-File -FilePath $FileName -Encoding UTF8;

Suggest an answer

Log in or Sign up to answer
Atlassian Community Anniversary

Happy Anniversary, Atlassian Community!

This community is celebrating its one-year anniversary and Atlassian co-founder Mike Cannon-Brookes has all the feels.

Read more
Community showcase
Piotr Plewa
Published Dec 27, 2017 in Bitbucket

Recipe: Deploying AWS Lambda functions with Bitbucket Pipelines

Bitbucket Pipelines helps me manage and automate a number of serverless deployments to AWS Lambda and this is how I do it. I'm building Node.js Lambda functions using node-lambda&nbsp...

2,001 views 1 5
Read article

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you