MySQL CREATE view

Source: Internet
Author: User
Tags mysql create

(1). First Class:

Create View  as Select *  from table;

(2). Type II:

Create View  as Select  from table;

(3). Category III:

Create View v[vid,vname,vage]asselectfromtable ;

If the amount of data involved is too large, the business logic needs a cross-table query, and so on, you can also create a cross-table view, there are three scenarios:

One, based on the same database

This is a simpler situation, just a simple line of SQL commands, as follows:

Create View  as (Select*fromUnion All (select* from Table2);

Second, based on different databases

This is only a database name that is more than the SQL statement above, as follows:

Create View  as (Select*fromUnion All (select* from Database 2.table2);

Or

Create View  as (Select*fromUnion All (select* from Database 2.table2);

If execution of the first SQL will establish a view under Database 1, and vice versa;

Third, based on different server

This is a bit of a hassle, you need to first set up a remote table to access the remote server's data table, and then the newly created remote table and local table view, the steps are as follows:

1. See if MySQL supports the federated engine

(1). log in to MySQL;

(2). Mysql>show engines;

(3). If displayed as no, add: federated (in My.ini) to the configuration file and restart the MySQL service.

2. Create a remote table

Mysql>CREATE TABLEfederated_table (IDINT( -) not NULLauto_increment, nameVARCHAR( +) not NULL DEFAULT "', OtherINT( -) not NULL DEFAULT '0',                     PRIMARY KEY(ID)) ENGINE=Federateddefault CHARSET=UTF8 CONNECTION='Mysql://[email protected]_host:3306/federated/test_table';

The connection can be configured as follows:

  (1). CONNECTION='mysql://username:[email protected]:p ort/database/tablename'   (2). CONNECTION='mysql://[email protected]/database/tablename'  (  3). CONNECTION='mysql://username:[email protected]/database/tablename'

3. Build a View

Create View  as (Select*fromUnion All (select* from remote database. test_table);

MySQL CREATE view

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.