Skip to main content

Views in SQL a sample Query for your project

A view is basically a logical view of one or more base tables. A view can be a read only or updatable. A view generally be created to avoid any unwanted changes into actual base tables. Mainly view is created for security reasons.
  • A view can be constructed with another view so it is called as nested view.
  • You can create or replace an existing view
  • A view can be created without having base tables. This is possible with FORCE option.
Learn SQL and handle databases confidently
Learn SQL and handle databases confidently
Read only views: The standard syntax for view is as follows:

CREATE OR REPLACE VIEW INVOICE_SUMMARY AS
SELECT VENDOR_NAME
COUNT(*) AS INVOICE_COUNT,
SUM(INVOICE_TOTAL) AS INVOICE_TOTAL_SUM
FROM VENDORS
JOIN INVOICES ON VENDORS.VENDOR_ID*INVOICES.VENDOR_ID
GROUP BY VENDOR_NAME;

How to use FORCE command:

CREATE FORCE VIEW PRODUCTS_LIST AS
SELECT PRODUCT_DESCRIPTION, PRODUCT_PRICE
FROM PRODUCTS;

Updatable Views: A view can also be updatable if a view follows certain rules. Read more to understand all about what is updatable view.  
  • A view when it is created for update purpose, you can give INSERT,UPDATE and DELETE
  • A read only view should contain WITH READ ONLY CLAUSE.
While updating a view, it is possible to update only one base table at a time. When you created a view from more than one table, then it is not possible to update two tables at a time.

What is ALTER view
This is possible with CREATE OR REPLACE statement. Just you can replace with existing statement.

Drop view
DROP VIEW VENDORS_SW


Last pointsA view with CHECK OPTION is surely help you to satisfy certain condition. Usually this option will be used in updatable views.

Comments

Popular posts from this blog

The best 5 differences of AWS EMR and Hadoop

With Amazon Elastic MapReduce (Amazon EMR) you can analyze and process vast amounts of data. It does this by distributing the computational work across a cluster of virtual servers running in the Amazon cloud. The cluster is managed using an open-source framework called Hadoop.

Amazon EMR has made enhancements to Hadoop and other open-source applications to work seamlessly with AWS. For example, Hadoop clusters running on Amazon EMR use EC2 instances as virtual Linux servers for the master and slave nodes, Amazon S3 for bulk storage of input and output data, and CloudWatch to monitor cluster performance and raise alarms.

You can also move data into and out of DynamoDB using Amazon EMR and Hive. All of this is orchestrated by Amazon EMR control software that launches and manages the Hadoop cluster. This process is called an Amazon EMR cluster.


What does Hadoop do...

Hadoop uses a distributed processing architecture called MapReduce in which a task is mapped to a set of servers for proce…

Top 20 ultimate ETL Questions really good for interviews

How to print/display the first line of a file?  there are many ways to do this. However the easiest way to display the first line of a file is using the [head] command.  $> head -1 file. Txt no prize in guessing that if you specify [head -2] then it would print first 2 records of the file.  another way can be by using [sed] command. [sed] is a very powerful text editor which can be used for various text manipulation purposes like this.  $> sed '2,$ d' file. Txt how does the above command work?  The 'd' parameter basically tells [sed] to delete all the records from display from line 2 to last line of the file (last line is represented by $ symbol). Of course it does not actually delete those lines from the file, it just does not display those lines in standard output screen. So you only see the remaining line which is the 1st line.  how to print/display the last line of a file?  the easiest way is to use the [tail] command.  $> tail -1 file. Txt if you want to do it using…

5 Things About AWS EC2 You Need to Focus!

Amazon Elastic Compute Cloud (Amazon EC2) - is a web service that provides resizable compute capacity in the cloud. It is designed to make web-scale cloud computing easier for developers.
Amazon EC2’s simple web service interface allows you to obtain and configure capacity with minimal friction.

The basic functions of EC2... 
It provides you with complete control of your computing resources and lets you run on Amazon’s proven computing environment.Amazon EC2 reduces the time required to obtain and boot new server instances to minutes, allowing you to quickly scale capacity, both up and down, as your computing requirements change.Amazon EC2 changes the economics of computing by allowing you to pay only for capacity that you actually use. Amazon EC2 provides developers the tools to build failure resilient applications and isolate themselves from common failure scenarios. 
Key Points for Interviews:
EC2 is the basic fundamental block around which the AWS are structured.EC2 provides remote ope…