cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
ebeery
Super User
Super User

Update db schema en masse, SQL Server Connector

In an existing .pbix file which contains many SQL Server connections, I can adapt to changes in server name or database name (e.g. tables I'm connected to are moved between servers or databases) quite easily for all queries in the file by just changing the source settings ("Data source settings" > "Change Source")

ebeery_0-1654828082074.png

However, if the schema of an object (or many objects) is changed, I'm not seeing any easy way to update that for all queries in my file, short of manually editing this line for each and every query.

ebeery_1-1654828215801.png

 

Is there a more efficient way to do this that I'm missing?  We're considering changing schema on a bunch of objects which are connected to many queries in many .pbix files across the company.

1 ACCEPTED SOLUTION
BA_Pete
Super User
Super User

Hi @ebeery ,

 

A couple of ideas:

 

1) To retrofit:

- Select all queries in Power Query that you want to change schema, copy, paste into your text editor of choice.

- In text editor, Find & Replace 'Schema="dbo"' with 'Schema="newSchema"'.

- Delete all selected queries from PQ.

- Select all in text editor and paste into PQ query pane.

 

2) To manage in future:

- In each new PBIX, create a query called 'schema' that is just '="dbo"'.

- For each new table you import that is likely to change schema, change 'Schema="dbo"' to 'Schema=schema'.

- You can now change the schema in all queries if required by changing the value in your new schema query.

 

Pete



Now accepting Kudos! If my post helped you, why not give it a thumbs-up?

Proud to be a Datanaut!




View solution in original post

7 REPLIES 7
BA_Pete
Super User
Super User

Hi @ebeery ,

 

A couple of ideas:

 

1) To retrofit:

- Select all queries in Power Query that you want to change schema, copy, paste into your text editor of choice.

- In text editor, Find & Replace 'Schema="dbo"' with 'Schema="newSchema"'.

- Delete all selected queries from PQ.

- Select all in text editor and paste into PQ query pane.

 

2) To manage in future:

- In each new PBIX, create a query called 'schema' that is just '="dbo"'.

- For each new table you import that is likely to change schema, change 'Schema="dbo"' to 'Schema=schema'.

- You can now change the schema in all queries if required by changing the value in your new schema query.

 

Pete



Now accepting Kudos! If my post helped you, why not give it a thumbs-up?

Proud to be a Datanaut!




Hi @BA_Pete ,

I'm testing this out now, and it doesn't quite seem to work as I envisioned.

Copying multiple queries out into a text editor works fine, but Power Query doesn't seem to accept a plain-text paste back into the Query pane.

ebeery_0-1656516022605.png

 

Hi @ebeery ,

 

Have you tried just clicking on the query pane then hitting Ctrl+V?

 

Also *might* work if you just paste the whole lot into a single new blank query. Something in my head is telling me that PQ is smart enough to split it all out into separate queries, but not able to test myself right now.

 

Pete



Now accepting Kudos! If my post helped you, why not give it a thumbs-up?

Proud to be a Datanaut!




Thanks @BA_Pete , both good suggestions. 

But I tried both and had no luck with either.  PQ didn't respond to Ctrl+V in the Query Pane, and pasting all in a blank query just lead to a "Expression.SynaxError:  Token Eof expected"

@ebeery ,

 

That's a bummer. I was sure PQ did something smart when copying multiple queries back in.

I guess a lot of the heavy lifting has already been done, so maybe just need to take the pain on the final step and copy each segment from the text file back into blank queries.

I know there's a way to read M code directly from a text file by using Expression.Evaluate, but I can't imagine you want to be holding all your queries remotely from your PBIX in text files.

 

Pete



Now accepting Kudos! If my post helped you, why not give it a thumbs-up?

Proud to be a Datanaut!




Thanks for looking at it anyways, this has given me some good ideas!

Thank you @BA_Pete !!  I did not know that just copying from the query pane into a text editor would transfer the m code, and vice versa.

 

That might be a workable solution to make the best of this messy situation.

Helpful resources

Announcements
Join Arun Ulag at MPPC23

Join Arun Ulag at MPPC23

Get a sneak peek into this year's Power Platform Conference Keynote.

PBI Sept Update Carousel

Power BI September 2023 Update

Take a look at the September 2023 Power BI update to learn more.

Learn Live

Learn Live: Event Series

Join Microsoft Reactor and learn from developers.

Dashboard in a day with date

Exclusive opportunity for Women!

Join us for a free, hands-on Microsoft workshop led by women trainers for women where you will learn how to build a Dashboard in a Day!

Top Solution Authors
Top Kudoed Authors