EDINBURGH (Reuters) - The Scottish government will start preparing the legislation required for a new referendum on independence from the United Kingdom in case it is needed, First Minister Nicola Sturgeon told the Scottish parliament on Tuesday.

Last week Sturgeon said her party would start a survey to test support for secession, questioning at least two million Scots just as Britain negotiates its exit from the European Union.

The bill would then be ready for "immediate" introduction if it becomes clear that there was voter support for Scottish independence, Sturgeon said, without giving a timeframe.

Polls indicate that a slim majority still prefer remaining a part of the United Kingdom, although many Scots are unhappy about leaving the EU because Scotland itself voted to stay in.

"We will consult on a draft referendum Bill so that it is ready for immediate introduction if we conclude that independence is the best or only way to protect Scotland," she told parliament.

Sturgeon argues that Britain's June vote to leave the EU, dragging Scotland with it, had shifted the debate dramatically just two years after Scots voted by 10 percentage points to reject independence.

She has pledged to honor Scotland's vote to retain EU membership by whatever means possible, including via a possible new independence vote.

Scottish Conservatives' leader Ruth Davidson accused Sturgeon and her party of lacking the vision to take Scotland forward.

"The Scottish National Party cupboard is bare, except for the only idea they ever had, to split up the UK," she said.

Sturgeon has a de facto majority in Scotland's parliament regarding independence because the Scottish Greens support her on that issue.

The 2014 Scottish referendum was agreed between Edinburgh and Britain's national government, but it was a political agreement rather than a court ruling, said Professor Michael Keating, Director of the Centre on Constitutional Change thinktank.

It is therefore unclear what the legal process for a fresh vote on the issue would be, and whether Prime Minister Theresa May would block it.

"No legal precedent has been set for a next time, if there is one," Keating said.

(Reporting By Elisabeth O'Leary; Editing by Angus MacSwan)