Create and use a view

Source: Internet
Author: User

Create and use a view

When I typed a student's balance form to query the card_Info table and student at the same time, I returned the query content to the form. So I used the view. Now I want to share the view creation method:

First, we need to know what the view is and what its role is.

A view is a virtual table whose content is defined by the query. Like a real table, a view contains a series of columns and row data with names. However, a view does not exist in the database as a stored data value set. Rows and columns are used to define tables referenced by View queries and dynamically generate tables when views are referenced.

For the referenced basic table, the view function is similar to filtering. The filtering of the definition view can be from one or more tables of the current or other databases, or other views. There are no restrictions on querying through views, and there are few restrictions on Modifying data through views.

Now let's take a look at creating a view:

We can use SQL statements:

<span style="font-size:18px;">CREATE [OR REPLACE] [ALGORITHM = {UNDEFINED | MERGE | TEMPTABLE}]    VIEW [db_name.]view_name [(column_list)]    AS select_statement    [WITH [CASCADED | LOCAL] CHECK OPTION]</span>

You can also create a view by following these steps:

1. First, right-click the database-view and choose create view.


2. Add the basic table of the view and select the fields to be joined. The same fields in the two tables are the contact fields, otherwise, a field corresponds to all fields in the other table.



3. Save the result (the view name is generally V + "_" + name)


After the view is created, the statement is the same as that of the normal table, but the table name is changed to the view name.

<Span style = "font-size: 18px;"> ''' <summary> ''' check the balance of the student (create a view to combine the two tables for query) ''' </summary> ''' <param name = "rechargecash"> </param> ''' <returns> </returns> ''' <remarks> </ remarks> Public Function CashInquire (ByVal rechargecash As JFEntity. registerCardEntity) As List (Of JFEntity. registerCardEntity) Implements IRegisterCardDAL. cashInquire Dim SQL As String Dim table As New DataTable Dim list As New List (Of JFEntity. registerCardEntity) Dim sqlparams As SqlParameter () = {New SqlParameter ("@ cardID", rechargecash. cardID)} SQL = "select * from V_CashInquire where cardID = @ cardID" table = SqlHelper. execSelect (SQL, CommandType. text, sqlparams) list = JFDAL. modelHelper. convertTolist (Of JFEntity. registerCardEntity) (table) Return list End Function </span>

Summary:Our learning is repeated over and over again. At the beginning, we only saw views in videos and books, but they were not applied. Now we have used the data center for the second time and used the previous knowledge. Everything has the meaning of existence, just like a view. Its existence makes the query simpler and saves a lot of code. So we need to go down step by step, because many difficulties can be solved with the knowledge we have learned before, so everything is not a problem !! Fighting ~




Copyright Disclaimer: This article is an original article by the blogger and cannot be reproduced without the permission of the blogger.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.