SQL alter view modification usage

Source: Internet
Author: User
Tags mysql tutorial

Alter table allows you to modify the structure of an existing TABLE. For example, you can add or delete columns, create or delete indexes, change existing column types, or rename columns or tables. You can also change the comment and type of the table. You can also modify the view. See the following example. Alter view syntax ALTER [ALGORITHM = {UNDEFINED | MERGE | TEMPTABLE}] VIEW view_name [(column_list)] AS select_statement [WITH [CASCADED | LOCAL] check option] This statement is used to change the definition of an existing view. Its syntax is similar to the create view mysql tutorial> mysql> create table Employee (-> id int,-> first_name VARCHAR (15),-> last_name VARCHAR (15 ), -> start_date DATE,-> end_date DATE,-> salary FLOAT (8, 2),-> city VARCHAR (10),-> description VARCHAR (15)->); Query OK, 0 rows affected (0.02 sec) mysql> insert into Employee (id, first_name, last_name, start_date, end_Date, salary, City, Description)-> values (1, 'jason ', 'martin', '000000', '000000', 19960725, 'toronto ', 'programmer'); Query OK, 1 row affected (20060725 sec) mysql> insert into Employee (id, first_name, last_name, start_date, end_Date, salary, City, Description)-> values (2, 'alison ', 'mathews ', '123', '123', 19760321, 'vancouver ', 'tester'); Query OK, 1 row affected (19860221 sec) mysql> insert into Employee (id, first_name, last_name, start_date, end_Date, salary, City, Description)-> values (3, 'James ', 'Smith', '123', '123', 19781212, 'vancouver ', 'tester'); Query OK, 1 row affected (0.00 sec) mysql> insert into Employee (id, first_name, last_name, start_date, end_Date, salary, city, Description)-> values (4, 'celia ', 'Rice', '000000', '000000', 19821024, 'vancouver ', 'manager'); Query OK, 1 row affected (0.00 sec) mysql> insert into Employee (id, first_name, last_name, start_date, end_Date, salary, City, Description)-> values (5, 'Robert ', 'black', '000000', '000000', 19840115, 'vancouver', 'tester'); Query OK, 1 row affected (19980808 sec) mysql> insert into Employee (id, first_name, last_name, start_date, end_Date, salary, City, Description)-> values (6, 'linda ', 'green ', '20140901', '20160901', 19870730, 'New York ', 'tester'); Query OK, 1 row affected (19960104 sec) mysql> insert into Employee (id, first_name, last_name, start_date, end_Date, salary, City, Description)-> values (7, 'David ', 'Larry', '123', '123', 19901231, 'New York ', 'manager'); Query OK, 1 row affected (0.00 sec) mysql> insert into Employee (id, first_name, last_name, start_date, end_Date, salary, city, Description)-> values (8, 'James ', 'cat', '000000', '000000', 19960917, 'vancouver', 'tester'); Query OK, 1 row affected (0.00 sec) mysql> select * from Employee; + ------ + ------------ + ----------- + ------------ + --------- + ----------- + hour + | id | first_name | last_name | start_date | end_date | salary | city | description | + ------ + ------------ + hour ----------- + ------------ + --------- + ----------- + ------------- + | 1 | Jason | Martin | 1234.56 | 6661.78 | Toronto | Programmer | 2 | Alison | Mathews | | Vancouver | Tester | 3 | James | Smith | 1978-12-12 | 1990-03-15 | 6544.78 | Vancouver | Tester | 4 | Celia | Rice | 1982-10-24 | 2344.78 | Vancouver | Manager | 5 | Robert | Black | 2334.78 | Vancouver | Tester | 6 | Linda | Green | 4322.78 | New York | Tester | 7 | David | Larry | 1990-12-31 | 1998-02-12 | 7897.78 | New York | Manager | 8 | James | Cat | 1996-09-17 | 1232.78 | Vancouver | Tester | + ------ + ------------ + ----------- + ------------ + --------- + ----------- + ------------- + 8 rows in set (0.00 sec) mysql> Create VIEW myView (id, first_name, city)-> as select id, first_name, city FROM employee; Query OK, 0 rows affected (0.00 sec) mysql> select * from myView; + ------ + ------------ + ----------- + | id | first_name | city | + ------ + ------------ + ----------- + | 1 | Jason | Toronto | 2 | Alison | Vancouver | 3 | James | vancouver | 4 | Celia | Vancouver | 5 | Robert | Vancouver | 6 | Linda | New York | 7 | David | New York | 8 | James | Vancouver | + ------ + ------------ + ----------- + 8 rows in set (0.00 sec) mysql> alter view myView (id, first_name, city)-> as select id, upper (first_name), city FROM employee; Query OK, 0 rows affected (0.00 sec) mysql> select * from myView; + ------ + ------------ + ----------- + | id | first_name | city | + ------ + ------------ + ----------- + | 1 | JASON | Toronto | 2 | ALISON | Vancouver | 3 | JAMES | vancouver | 4 | CELIA | Vancouver | 5 | ROBERT | Vancouver | 6 | LINDA | New York | 7 | DAVID | New York | 8 | JAMES | Vancouver | + ------ + ------------ + ----------- + 8 rows in set (0.02 sec) mysql> drop view myView; Query OK, 0 rows affected (0.00 sec) mysql> drop table Employee; Query OK, 0 rows affected (0.00 sec) mysql>

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.