How to export all Views from a database

Francesco Mantovani
3 min readJan 23, 2022
How to export all Views from a database

Friends don’t let friends use INFORMATION_SCHEMA, but…

I know the whole diatribe about INFORMATION_SCHEMA and I would not join the debate.

I just want to say that I in case you need to export all Views from a database you can use this pretty simple query:

SELECT v.TABLE_SCHEMA AS View_Schema

,v.table_name AS View_Name

,v.VIEW_DEFINITION AS Create_View_Script

FROM information_schema.VIEWS v

JOIN information_schema.columns c ON v.table_schema = c.table_schema

AND v.table_name = c.table_name

GROUP BY v.TABLE_SCHEMA

,v.table_name

,v.VIEW_DEFINITION

Querying INFORMATION_SCHEMA this way is pretty safe as this is is what is behind your “right click > Script View as > CREATE to > New Query Editor Window”.

This is the result on AdventureWorks2019:

Export all views form database

I haven’t found any particular problem and the query is pretty straight forward.

Post you opinion in the comment if you have a better idea; this is the best I could find.

A few words about COVID-19

I discovered today that Meat Loaf passed away because of COVID-19. He had one of those peculiar wide-ranging voice that was able to worm your hearth.

He was probably a No Vax and is unknown if he was vaccinated or not.

Anyway what I want to say is that Switzerland is teaching me something about tolerance, listen to this story.

I have a friend here in Switzerland, and his father died of COVID-19 with the first wave in 2020. We were talking about the fact that we both have No Vax friends and the No Vax movement is much more wide than we expected.

Here in Switzerland they proposed a referendum aimed to strength the restrictions and impose to all citizens to hold a valid vaccination certificate in order to go to work.

The phrase that my friend pronounced and that stuck me is this:

“ it would be a pity if the law gets approved. I have a few No Vax friends and it would be sad not being able to go to the restaurant with them…. and the fact that they will probably lose their job…”

This is a phrase of high value.

Translated this phrase means “even if I have lost my Dad, even if I’m vaccinated and I respect the rules I also respect people that have a different view of a subject that changed so intimately my life”.

Is a great example of tolerance and tolerance is something that is scarce during these modern times.

This is a phrase that goes beyond the “I’m right” or “you are right” or “this should be done” or “this is right and that is wrong”.

Is so unusual to admit that we, homo sapiens, we are not perfect machines, we can contradict ourselves, we base our decisions on emotions.

And my friends is right, friendship goes beyond the right or wrong and is about acceptance.

--

--

Francesco Mantovani

Lorem Ipsum “Neque porro quisquam est qui dolorem ipsum quia dolor sit amet, consectetur, adipisci velit…” “There is no one who loves pain itself, who seeks