How does regular view works? - snowflake-cloud-data-platform

I understands in Snowflake, "table" is just a metadata representation of physical micro-partitions.
How does regular view works? Is it just another metadata representation which points physical micro-partition directly, or is their any routing-like mechanism happening inside the cloud service layer?

A regular view(non-materialized view) is a named query.
Non-materialized Views:
A view is basically a named definition of a query. A non-materialized view’s results are created by executing the query at the time that the view is referenced in a query. The results are not stored for future use.

Related

Dependency Checks in Snowflake

I have below requirement.
I want to drop table : DIM_SALES_DETAILS
Before dropping, I want to run a query which will provide me all those object names (Views, Materialized Views, Stored Procedures, Tasks etc.) where this table has been used.
Is there a way we can get this ?
Thank You.
Have you tried to query the OBJECT_DEPENDENCIES view in the Account Usage schema of the shared SNOWFLAKE database?
https://docs.snowflake.com/en/user-guide/object-dependencies.html#impact-analysis-find-the-objects-referenced-by-a-table
There are some sample queries to find out the dependent objects.

Snowflake - Views Usage by external access

I have set of views in the two schema under one database , i wanted to know which views are getting most used by external access like (Power BI , BO..) . Is there any way in snowflake to identify that?
Everytime an external tool accesses a Snowflake object (Views in your case), this is captured in Query History in Snowflake.
To compare which Views are most used, you can compare the number of times each of those Views is accessed.
Following SQL query accesses the query history, and filters by View name, and gives the number of times a View was accessed, in a given timeframe:
select count(1) as "ACCESS_COUNT" from snowflake.account_usage.query_history where start_time between '<yyyy-mm-dd hh:mm:ss>' and '<yyyy-mm-dd hh:mm:ss>' and database_name = '<db_name>' and query_text ilike '%<view_name>%' ;
Please note that the result will also include the count a View was accessed by any other users as well (and not just by external tools)
To refine your search, you can add more filters. Here's the list of columns in query_history View.

How does SQLITE DB saves data of multiple tables in a single file?

I am working on a project to create a simplified version of SQLite Database. I got stuck when trying to figure out how does it manages to store data of multiple tables with different schema, in a single file. I suppose it should be using some indexes to map the data of different tables. Can someone shed more light on how its actually done? Thanks.
Edit: I suppose there is already an explanation in the docs, but looking for some easier way to understand it better and faster.
The schema is the list of all entities (tables, views etc) (the database as a whole) rather than a database existing of many schemas on a per entity basis.
Data itself is stored in pages each page being owned by an entity. It is these blocks that are saved.
The default page size is 4k. You will notice that the file size will always be a mutliple of 4K. You could also, with experimentation create a database with some tables, note it's size, then add some data, and if the added data does not require another page, see that the size of the file is the same. This demonstrating how it's all about pages rather than a linear/contiguos stream of data.
It, the schema, is saved in a table called sqlite_master. This table has columns :-
type (the type e.g. table etc),
name (the name given to the entity),
tbl_name (the tale to which the entity applies )
root page (the map to the first page)
sql (the SQL used to generate the entity, if any)
note that another schema, sqlite_temp_master, may also exist if there are temporary tables.
For example :-
Using SELECT * FROM sqlite_master; could result in something like :-
2.6. Storage Of The SQL Database Schema

How to list all jobs which operate with specified database object?

Is there a way to list in Sql Server all the jobs which operate on a mentioned Sql Server object, for example a certain table (directly or indirectly through a stored procedure for example)?
An example: I am interested in a certain table or view, so if there is a job which invokes (in any step) a procedure, which in its turn does any operation on that table/view (like insert or select or update etc), I'd like to see it listed.
Side note: sp_depends seems to list only the procedures and functions, but not the jobs.
There is no built-in way to find indirect dependencies. You can check which jobs directly call a certain stored procedure, but no way to see which tables or other objects get used by that stored procedure unless you check the direct dependencies of that stored procedure.
So if you are looking for a specific table, you can find objects that reference it directly, but not objects that reference THOSE objects (indirect dependency).
You would either have to write your own script or search around and see if someone else has written one.

Sql server Code Reuse

I have a table with about 30 fields. I current have several stored procedures which access either a (aggregated) view of this table or the table itself. For many of these SPs I would like to assure that the returned records have all the same fields with the same column names. Is there a way to do this where I don't have to change 20 stored procs if I do need to change the output.
My way around it thus far is to provide clients with lists of ID which they then call SP's that return the data however this seems to be slow compared with getting the data in one shot. I have also considered using the formatting stored procs with a cursor from inside the search stored procs but was unsure if that would really buy me a whole lot.
The typical way to define a standardised and consistent data access method across multiple stored procedures in SQL Server to use Views.
Now your problem description seems to suggest that you are already using Views in order to manage your data access. If you are indeed unable to use Views for a specific reason, perhaps you can clarify the nature of your problem further for us.

Resources