Where used list in BigQuery - google-bigquery

I have a view, Wanted to check what sort of SQL can help to identify list of all views and Stored procedure using it.
For Example,
View A is being used in View B, View C and Stored Procedure D.
Is there any metadata schema which can help writing such query where we can track all dependent objects of a certain object in BigQuery. Please assist.
For Example,
View A is being used in View B, View C and Stored Procedure D.
Is there any metadata schema which can help writing such query where we can track all dependent objects of a certain object in BigQuery. Please assist.

You can run the following query that will list all views, this can be done on an individual dataset basis. Of course if you have a set of datasets you could create one UNION ALL query for each dataset to combine the results.
SELECT * FROM dataset_name.INFORMATION_SCHEMA.VIEWS WHERE
REGEXP_CONTAINS(view_definition, 'dataset_name.table_name')
Replacing dataset_name and table_name in the above query.
view_definition in the schema table contains the actual SQL code to create the view. So we are essentially just searching that field for the table name, same would work if you are looking for a view being used in a view.

Related

How to set up a view that replaces a table once processed?

Every time I attempt to save a view that has "create or replace table" I get the error:Only SELECT statements are allowed in view queries.
I am using standard SQL in Google Cloud Big Query. I do not want the view as a scheduled query and the view is too large to run, meaning it errors out asking for me to create a table that allows large results. I want the query to update its associated table every time it is run. I came across the Write_Truncate syntax, however I do not know to use it.
create or replace table.test1 as( all my other queries)
I just expect for big query to allow me to run the table.

How can I append data onto a view using sql?

I have created a view using the following sql command:
CREATE OR REPLACE VIEW Table AS
SELECT * FROM TABLEA FULL OUTER JOIN TABLEB
ON TABLEA.Column1=TABLEB.Column1
I usually get new datasets every week and I was wondering if there was a way using sql commands to append the data from the new table onto the view, "Table"?
Thanks in advance.
A view in SQL, so long as it is not a materialized view, basically just sits on top of the underlying table. So, for a non materialized view, if you want it to see new data, that data would have to come from the underlying tables. If you have a materialized view, then you may just insert however many rows you want.

Extract the name of a Database which is used in a view (refering other Database)

i dynamicaly create Views which refering other Databases (mainly to import data from there)
use [RezepteDB]
in this DB i create a view like this
CREATE VIEW [dbo].bla as select * from ZutatenDB.dbo.Bla
Later i need the name of the Database, on which is the view based.
For this example 'ZutatenDB'.
How can i done this? a small function to pass the name of the view and return the name of the database.
One technique is to use sys.dm_sql_referenced_entities:
SELECT *
FROM sys.dm_sql_referenced_entities ('dbo.bla', 'OBJECT');
You can see the referenced server, database, schema and objects.

vb.net query for creating table

I have Access as my back end. Student is the database name and its path is c:\Project\student.mdb
And am having few tables in it. When i click a command button in vb.net a new table must be created in the path mentioned. And it should have the fields I declare.
What s the query I need to use ? Is it possible to do like that ?
Yes, it's possible, you can check out the syntax for the create table command.
However, I have to say that creating tables dynamically suggests a bad database design. The database layout should normally remain the same whatever data you put in the database.
If you create tables dynamically, that means that you have data in the table names, but data should go inside the tables, not in table names (or even field names).
Yes it's possible . Just pass the create table command as query and the table name as variable , which you want to add dynamically. for reference of create table command
Create table command

Query driving a view and actual view not returning same results

I have a view that is returning four columns of data to be pushed to an external program. When I simply query the view ("Select * from schema.view_name") I get 10353 rows. When I run the actual SQL that created the view (I literally copied and pasted what Oracle had stored, minus the "Create or Replace" statement), I get 238745 rows.
Any ideas why this might occur?
Best guess: when you run the query standalone you're not running it in the same schema the view was created in (I am inferring this from the fact that you included the schema name in your example SELECT). The schema where you're running the query either has its own table with the same name as one of the base tables in the view, or one of the names is a synonym pointing to yet another view that contains only a subset of the rows in the underlying table.