Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Script backup and restore with view #3778

Closed
OpenMessageCoder opened this issue Apr 15, 2023 · 1 comment
Closed

Script backup and restore with view #3778

OpenMessageCoder opened this issue Apr 15, 2023 · 1 comment

Comments

@OpenMessageCoder
Copy link

I'm backing up my database with SCRIPT TO ....
When I run the script to restore, everything works except one of my views.
When I look in INFORMATION_SCHEMA.VIEWS."VIEW DEFINITION" and copy the SQL and run it, all works ok.
When I run select * from the view, it fails, complaining that one of the tables doesn't exist.
My guess is that the problem is that in the script file, the view is created before the table. My guess is that the view is stored optimised and at the time the view was created, the table didn't exist, so the optimised version couldn't find it. But I'm no expert.
I'm using 2.1.214.
An excerpt from the script is attached, including the view definition and the definition of the missing table, which happens to come right after.
scipt file segment.txt

@katzyn
Copy link
Contributor

katzyn commented Apr 15, 2023

Unfortunately, you need to edit the exported script and re-order definitions of views and tables by yourself. If this file is too large for regular text editors you can try to use some stream editor or some special editor for large files.

Usually this issue appears after various modifications of database schema. The SCRIPT command doesn't check dependencies between tables and views (view may depend on other tables and views, and in some cases tables may depend on views) and exports them in their creation order. Usually this order is good enough, but after some ALTER commands a different order can be needed.

This issue is a duplicate of #2390.

@katzyn katzyn closed this as not planned Won't fix, can't repro, duplicate, stale Apr 15, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants