11-10c# Foundation--View of database

Source: Internet
Author: User

View

A view is actually a virtual table of results built on the table's connection. in simple terms, a view is actually a virtual table that is connected to the table by the table and is easy to use when querying.

First, the statements that need to be connected are stored in the database, and a new view name is defined instead of the connection statement;

Then, each time the new view name is queried, it is actually a code query that performs a table connection.

1, the two tables (Student,score table) are combined into a table to use, to form a new table.

(Select Student. Sno,sname,ssex,sbirthday,class,score. Cno,degree from Student
Join score on student. Sno=score. Sno) as--as a new table for easy query use

2. Create a View

Method One: Use the view---new view to manipulate.

Step 1: Under Object Explorer select the database (Xinxibiao) for which you want to build the view, click the "+" sign,

In the subdirectory, select View, and right-click New View.

Step 2: In the "Add Table" dialog box that pops up, select the table you want to build the relationship with, then click "Add" to close it.

Step 3: When two or more tables are established, it is found that the relationship between the primary key and the foreign key exists between them, which is the relational table between them.

Step 4: After you have established the relationship, complete the creation of the view and the desired results will be displayed.

Method Two: Create a view from code

Writing format:

Create + (view English name) + created view name---table-like creation format

As

A query statement that establishes a relationship between two or more tables

Go

Example: CREATE VIEW studentscore----creating views

As

Select Student. Sno,sname,ssex,sbirthday,class,score. Cno,degree from Student

Join score on student. Sno=score. Sno---Establishing a relational statement for a student,score table

Go

Select*from studentscore----Query result statements

The "Considerations" view does not exist in the order by, aggregate functions, in,not in relational operations and other statements, it is not a real table, is a virtual table, the data source in the Student,score table, can only use the table to join the Join...on combination of data, convenient query use.

Exercises 1:

3. Delete View

Method 1:

Method 2: Remove by code

Drop view+ View Name

Example: Drop View Studentscore

4. Modify the View

ALTER VIEW Studentscore---equivalent to deleting the views overrides

As

Select Student. Sno,sname,ssex,sbirthday,class,score. Cno,degree from Student

Join score on student. Sno=score. Sno

Go

"Considerations" the same relationship view can only be built once, after modification to reestablish the relationship, the view itself is virtual nonexistent, just for the convenience of query.

11-10c# Foundation--View of database

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.