Simple view creation, deletion, preview, and other operations

Source: Internet
Author: User

Simple view creation, deletion, preview, and other operations
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 form of a stored data value set in the database tutorial. 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 query through views, and there are few restrictions on data modification through them.

A view is an SQL statement stored in a database. It is mainly for two reasons: security reasons. A view can hide some data, such as the Social Insurance Fund table, you can use the view to display only the name and address, but not the social insurance number and wage number. Another reason is that complex queries are easy to understand and use.

 

<? Php tutorial
$ Mysql tutorial I = new mysqli ("localhost", "root", "123456", "xiaoqiangdb ");
 
$ SQL = "select * from myview order by chengji ";
 
$ Result = $ mysqli-> query ($ SQL );
 
Echo '<table align = "center" border = "1"> ';
 
While ($ row = $ result-> fetch_assoc ()){
Echo '<tr> ';
Foreach ($ row as $ col ){
Echo '<td>'. $ col. '</td> ';
}
Echo '</tr> ';
}
Echo '</table> ';
 
$ Mysqli-> close ();

?>


You can use

· Use create view or alter view to create or change a view.
Alter [algorithm = {undefined | merge | temptable}] view view_name [(column_list)] as select_statement [with [cascaded | local] check option]


Create [or replace] [algorithm = {undefined | merge | temptable}] view view_name [(column_list)] as select_statement [with [cascaded | local] check option]

· Use drop view to destroy a view.

Drop view [if exists] view_name [, view_name]... [restrict | cascade] drop view can delete one or more views. You must have the drop permission on each view.


· Use show create view to display view metadata.

Show create view view_name this statement provides a create view statement for creating a given view.

Mysql> show create view v;

View instances one by one

View the view Syntax "show tables;" or "show tables status". You can not only view the view name in the table, but also view other related information, such as an instance.

-> Show tables;

St

Stff

Staroo

26 row in set (0.00 sec );

-> Show tables status like 'st' g

Name: st

Engine: null

Version: null

.....
.

To query the definition of a view, run the show create view command.

-> Show create view st list gview: st

Create view: create algorithm = udefined definer = 'root @ localhost' SQL ....

And so on. If you do not write anything else, you can test it in mysql.

Now let's take a look at how mysql deletes a view instance.

Syntax:

Drop view [if exists] view_name [, viewname]... [restrict | casede] For example, to delete the st view

-> Drop view st;

Query OK, 0 rows affected (0.00 sec );

For more details, see http://www.bKjia. c0m/database/110/mysql-drop-show.htm

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.