Add column description in views in bigquery Terraform - google-bigquery

I have tables in bigquery which have column description using terraform via their schema.
I'm trying to add description to columns which are created via a view from the previous mentionned tables.
My question, is there a way to inherit the description from the origin table to the view ? or if no, how to add directly column description inside the query that creates the view ?
Cheers,

Related

Oracle do not display/move to end field in view

Would it be possible to create a view from a table showing all its fields in the original order but one without specifically naming all of them? Also, would it be possible to do the same but moving that field to the last column of the view?

Google Big Query view does not preserve data mode

When creating a view from a table in Google Big Query using the UI, all the fields come with NULLABLE mode and it cannot be changed.
Is there a way of fixing it?
Thanks.
A BigQuery view is defined by a query from a table, the required fields are handled in the that table.
The required fields are the fields (not NULLABLE) that need to be present when loading data in a table. As a view is not meant to load data the mode of the fields doesn't need to be required or nullable.

Storing SQL metadata

I have a generated SQL table which fits nicely in rows/columns, but I'd also like to store some information about that table such as:
When was it generated?
Who generated it?
What script was run to generate it?
Where did the data come from?
A list of key-pair values which didn't fit in the table and really only describe more information about the source
I'm a little new to SQL, but how would one normally store this information?
I would image that after I CREATE TABLE foo, I would need to then CREATE TABLE foo_meta, then each question will be a column and I'll need to INSERT just one row: the answers to those questions. Is that a normal way to handle this?
Some clarifications,
I'm using SQLite3
Each table represents recorded time-history data where each column is a parameter and each row is a time-step.
Each table will have associated metadata
The meta-data contains things like initial conditions and other conditions which weren't recorded in the time-history.
I will add a bunch of test-results to the same database. Each test will have a data table (time-history) and a meta-data table.

Creating Indexed View which references a Non Indexed View and objects from multiple DB's

I have the following objects used in the following format in a create view statement.
dbo.objects1 A
INNER JOIN db2.dbo.object2
INNER JOIN db2.dbo.object3
INNER JOIN db2.dbo.object4
INNER JOIN db2.dbo.object5
The objects1 is a table from Database1 which has Indexes. The objects2 through objects5 are in another database and all these 4 objects are view with No indexes.
Now I am trying to create an indexed view with all the above five objects but SQL server is not allowing me.
First error is:
Names must be in two-part format and an object cannot reference itself.
Second error is:
Cannot schema bind view 'dbo.vw_Order' because name 'db2.dbo.object2' is invalid for schema binding.
Now I googled these errors and I came to following assumptions:
Views cannot contain objects from multiple databases in a join query.
In order to create indexes on a view, all the objects in the view should have either indexes or should be schema binded (like Functions).
When I run the view like a query, Execution Plan is recommending me to create an index on columns from objects in db2. Please let me know if my assumptions are correct. If not, please let me know a way as to how I can create a view in this situation.
As you have already done the research that all the objects(tables/View) in a definition of an indexed view must have TWO PART name i.e [Schema].[Object] it means all the objects will be in one database and you cannot create indexed view across multiple databases. Indexed views come with a lot of limitations, consider creating a stored procedure if possible
Other error that you are getting is you are missing WITH SCHEMABINDING option in your view's definition. It is a must requirement for creating an indexed view that you must use the WITH SCHEMABINDING option when creating indexed view i.e none of the underlying tables/objects schema can be changed until you drop this view.
Again I would suggest to look into stored procedures as it seems impossible in your case to create an Indexed View because of all the limitation that come with it.
Add the owner to the view name and tables.
Like:
Create VIEW dbo.MyView
WITH SCHEMABINDING
AS
SELECT * From dbo.Users
You cannot create indexed view using two objects of different databases.

If I update a view, will my original tables get updated

Hypothetically I have two tables Employee and Locations. Additionaly I have a view viewEmpLocation which is made by joining Employee and Locations.
If I update the view, will the data in the original table get updated?
Yes.
The data "in" a view has no existence independent from the tables that make up the view. The view is, in essence, a stored SELECT statement that masquerades as a table. The data is stored in the original tables and only "assembled" into the view when you want to look at it. If the view is updateable (not all views are) the updates are applied to the table data.
see Using Views in Microsoft SQL Server
When modifying data through a view
(that is, using INSERT or UPDATE
statements) certain limitations exist
depending upon the type of view. Views
that access multiple tables can only
modify one of the tables in the view.
Views that use functions, specify
DISTINCT, or utilize the GROUP BY
clause may not be updated.
Additionally, inserting data is
prohibited for the following types of
views:
* views having columns with derived (i.e., computed) data in the SELECT-list
* views that do not contain all columns defined as NOT NULL from the tables from which they were defined
It is also possible to insert or
update data through a view such that
the data is no longer accessible via
that view, unless the WITH CHECK
OPTION has been specified.
You could use a trigger on the view to do an insert/update/delete to the actual tables.
http://www.devarticles.com/c/a/SQL-Server/Using-Triggers-In-MS-SQL-Server/1/